Skip to content

Respect endianness correctly in CheckEnums test suite #143339

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 1 commit into
base: master
Choose a base branch
from

Conversation

1c3t3a
Copy link
Member

@1c3t3a 1c3t3a commented Jul 2, 2025

The endianness can change the test expectation for the enum check. This change is fixing the failing tests on big endian by changing the tests so that they behave the same as on little endian.

Fixes #143332.

@rustbot
Copy link
Collaborator

rustbot commented Jul 2, 2025

r? @lcnr

rustbot has assigned @lcnr.
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 A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 2, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 2, 2025

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@bors
Copy link
Collaborator

bors commented Jul 3, 2025

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

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

pls switch to revisions, afterwards r=me

@lcnr
Copy link
Contributor

lcnr commented Jul 3, 2025

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 3, 2025
Copy link
Member

@RalfJung RalfJung Jul 3, 2025

Choose a reason for hiding this comment

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

Why does this test use a struct with two u16 fields to begin with? if you transmuted a u32 directly to Foo, things would be endian-independent. (same for convert_non_enum_break)

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea of this test was to transmute a non-integer value to an enum. I am happy to change it to a u32 here, but in that case I might as well delete it because that behavior is covered by other tests. My goal here was to check that I can safely extract the discriminant from a transmute of non-int value.

Copy link
Member

@RalfJung RalfJung Jul 7, 2025

Choose a reason for hiding this comment

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

I have no idea what you think that's an interesting case to test, and there is no comment in the test explaining that this is what the test is about. Please always add such comments.

But anyway, whatever the point of the test is, surely it can be done on both little-endian and big-endian systems. So find a form of the test that does that, or add #[cfg(target_endian = ...)] in the test if you need slightly different code to make it work in both ways (and then ensure you actually test both codepaths, e.g. with Miri).

The goal should be to have the exact same test coverage on little-endian and big-endian. It makes no sense at all to take the existing little-endian tests and just update the expected output for big-endian, as they obviously don't test the right thing on big-endian if they produce such different results there!

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea what you think that's an interesting case to test

So you think it doesn't make sense to test that? My point was that I am transmuting internally between either an Int-To-Int or a direct transmute. I want to make sure that the direct transmute is working correctly and that my codepath that inserts it behaves correctly. If you disagree with that, it's better to drop the test in favor of a slimmer testsuite.

The goal should be to have the exact same test coverage on little-endian and big-endian.

Yes I understand that point, thanks for the feedback. For that reason I went ahead and changed this struct to one with just a single member that is a u32. The test is the same for big and little endian.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know your code (and unfortunately don't have the time to dig into it right now), maybe the test makes sense, but it's very unclear from the outside.^^

I went ahead and changed this struct to one with just a single member that is a u32. The test is the same for big and little endian.

Such a struct is identical to an int for most parts of the compiler. I am surprised that it would make any difference for your code. But sure, that sounds good. :)

@1c3t3a
Copy link
Member Author

1c3t3a commented Jul 7, 2025

I updated the test suite to always work for both cases and stopped enabling or disabling tests as per Ralf's suggestion.

The endianness can change the test expectation for the enum check.
This change is fixing the failing tests on big endian by changing
the tests so that they behave the same as on little endian.
@RalfJung
Copy link
Member

RalfJung commented Jul 7, 2025

This looks good... @fneddy any chance you could test this, or should we just land it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

CheckEnums tests fail on s390x (big-endian)
5 participants