Skip to content

Fix RISC-V Test Failures in ./x test for Multiple Codegen and Assembly Cases #143915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

CaiWeiran
Copy link

Resumption of #143792.
This PR addresses and resolves several test failures that occurred when running ./x test on the RISC-V architecture. The issues were due to platform-specific behavior, ABI differences, or code generation inconsistencies specific to RISC-V.

The following tests have been fixed:

  • assembly/dwarf-mixed-versions-lto.rs
  • codegen/const-vector.rs
  • codegen/enum/enum-aggregate.rs
  • codegen/simd/extract-insert-dyn.rs
  • codegen/transmute-scalar.rs
  • codegen/uninhabited-transparent-return-abi.rs

All changes have been tested locally with ./x test on a RISC-V target and now pass as expected.

Notes:

  • These fixes are scoped specifically to enable full test suite compliance for RISC-V targets.
  • No changes were made that affect other architectures.

Fix tests/assembly/dwarf-mixed-versions-lto.rs test failure on riscv64.
Fix tests/codegen/const-vector.rs test failure on riscv64.
Fix tests/codegen/enum/enum-aggregate.rs test failure on riscv64.
Fix tests/codegen/simd/extract-insert-dyn.rs test failure on riscv64.
Fix tests/codegen/transmute-scalar.rs test failure on riscv64.
Fix tests/codegen/uninhabited-transparent-return-abi.rs test failure on riscv64.
@rustbot
Copy link
Collaborator

rustbot commented Jul 14, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 14, 2025
@CaiWeiran
Copy link
Author

@Mark-Simulacrum I have merged different revisions into a single file.

@rust-log-analyzer

This comment has been minimized.

Fix tidy check error.
@CaiWeiran CaiWeiran changed the title Ci test Fix RISC-V Test Failures in ./x test for Multiple Codegen and Assembly Cases Jul 14, 2025
@rust-log-analyzer

This comment has been minimized.

Fix regex matching error.
@rustbot
Copy link
Collaborator

rustbot commented Jul 15, 2025

Error: This team (llvm) cannot be pinged via this command; it may need to be added to triagebot.toml on the default branch.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@Mark-Simulacrum
Copy link
Member

cc @nikic for whether there's a better pattern for us to follow in codegen tests to normalize/ignore the per-target ABI questions (E.g., signext above), or if we should instead retain test coverage very explicitly of them.

@nikic
Copy link
Contributor

nikic commented Jul 15, 2025

@Mark-Simulacrum Ignoring ABI attributes via {{.*}} seems fine. But I think that for tests like transmute-scalar.rs that aren't testing anything target specific, we should be specifying an explicit --target to avoid these issues. I feel like that might have been the intention for that test all along, seeing as how it uses minicore already.

@CaiWeiran
Copy link
Author

@Mark-Simulacrum Ignoring ABI attributes via {{.*}} seems fine. But I think that for tests like transmute-scalar.rs that aren't testing anything target specific, we should be specifying an explicit --target to avoid these issues. I feel like that might have been the intention for that test all along, seeing as how it uses minicore already.

@nikic I'm not sure I understand. If I don't make any changes, running ./x test --target riscv64gc-unknown-linux-gnu tests/codegen/enum/enum-aggregate.rs still fails. So even when specifying --target, the test fails due to target-specific ABI differences.

@nikic
Copy link
Contributor

nikic commented Jul 16, 2025

@Mark-Simulacrum Ignoring ABI attributes via {{.*}} seems fine. But I think that for tests like transmute-scalar.rs that aren't testing anything target specific, we should be specifying an explicit --target to avoid these issues. I feel like that might have been the intention for that test all along, seeing as how it uses minicore already.

@nikic I'm not sure I understand. If I don't make any changes, running ./x test --target riscv64gc-unknown-linux-gnu tests/codegen/enum/enum-aggregate.rs still fails. So even when specifying --target, the test fails due to target-specific ABI differences.

The test should specify

//@ compile-flags: --target=x86_64-unknown-linux-gnu
//@ needs-llvm-components: x86

To always run against the x86 triple even if you are running on a riscv host.

@CaiWeiran
Copy link
Author

CaiWeiran commented Jul 16, 2025

@Mark-Simulacrum Ignoring ABI attributes via {{.*}} seems fine. But I think that for tests like transmute-scalar.rs that aren't testing anything target specific, we should be specifying an explicit --target to avoid these issues. I feel like that might have been the intention for that test all along, seeing as how it uses minicore already.

@nikic I'm not sure I understand. If I don't make any changes, running ./x test --target riscv64gc-unknown-linux-gnu tests/codegen/enum/enum-aggregate.rs still fails. So even when specifying --target, the test fails due to target-specific ABI differences.

The test should specify

//@ compile-flags: --target=x86_64-unknown-linux-gnu
//@ needs-llvm-components: x86

To always run against the x86 triple even if you are running on a riscv host.

@nikic It will fail the test if I don't install the x86_64-unknown-linux-gnu target on the RISC-V host.
When running tests on a RISC-V host, my goal is to test the RISC-V triple.
If a certain test is specifically for x86, would it be better to mark it with //@ only-x86?
Or alternatively, modify the matching rules like I did to adapt to different ISAs?

@nikic
Copy link
Contributor

nikic commented Jul 16, 2025

@CaiWeiran Using --target + needs-llvm-components + no_core ensures that the test can run on arbitrary hosts. It should not fail on RISCV if everything is implemented correctly.

Ignore cross-compile.
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Jul 18, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 18, 2025

This PR modifies run-make tests.

cc @jieyouxu

This reverts commit d464e57.
@bors
Copy link
Collaborator

bors commented Jul 22, 2025

☔ The latest upstream changes (presumably #144249) made this pull request unmergeable. Please resolve the merge conflicts.

@Mark-Simulacrum
Copy link
Member

r=me with commits squashed, I don't think this needs more than one commit.

@@ -79,7 +80,7 @@ pub fn bool_to_fake_bool_signed(b: bool) -> FakeBoolSigned {
unsafe { mem::transmute(b) }
}

// CHECK-LABEL: define{{.*}}i1 @fake_bool_signed_to_bool(i8 %b)
// CHECK-LABEL: define{{.*}}i1 @fake_bool_signed_to_bool(i8 {{.*}}%b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least for things like this one that aren't about SIMD, the point of having the signature is basically just to make it easier to read the verifications and check that the argument has the expected name (as opposed to being called %0 because of the ABI or LocalKind or something).

So for things like that, I think ignoring extra flags in here is acceptable -- though admittedly slightly unusual because it's a -C no-prepopulate-passes test. (In optimized tests it's very common to have a wildcard for resiliency against LLVM adding new parameter attributes.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, though if it's just an optional extension flag, consider using

Suggested change
// CHECK-LABEL: define{{.*}}i1 @fake_bool_signed_to_bool(i8 {{.*}}%b)
// CHECK-LABEL: define{{.*}}i1 @fake_bool_signed_to_bool(i8{{( zeroext)?}} %b)

because you know exactly what you're ignoring in this case, rather than allowing for arbitrary future attributes that might be added by the optimizer.

pub extern "C" fn single_element_simd_to_scalar(b: S) -> i64 {
unsafe { mem::transmute(b) }
}

// CHECK-LABEL: define{{.*}}<1 x i64> @scalar_to_single_element_simd(i64 %b)
// CHECK-LABEL: define{{.*}}i64{{.*}} @scalar_to_single_element_simd(i64 %b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm less sure what should be done for this case. Is it even BackendRepr::SimdVector in these cases if it's not a vector type in the ABI? Should these SIMD ones be split into another file from the scalar ones? Should it be more like {{ i64| <1 x i64>}} if those are the only two realistic possibilities for what will be here?

unsafe extern "C" fn dyn_simd_insert(x: i8x16, e: i8, idx: u32) -> i8x16 {
simd_insert_dyn(x, idx, e)
}

// CHECK-LABEL: literal_dyn_simd_insert
// CHECK: insertelement <16 x i8> %x, i8 %e, i32 7
// CHECK: insertelement <16 x i8> %[[TEMP:.+]], i8 %e, i32 7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if you're not going to consume the variable again later (by mentioning %[[TEMP]] somewhere) then I think you should just use a {{regex}} not a [[NAME:regex]].

Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed the ping here. I've dropped some thoughts, but nothing super-critical, so feel free to do with them what you will, since you already have an approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants