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 2 commits 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 correcting these expectations and adds separate tests for big endian targets with the correct expectations.

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.

1c3t3a added 2 commits July 3, 2025 11:50
We already have //@ ignore-endian-big, this does the same for
little endian.
The endianness can change the test expectation for the enum check.
This change is correcting these expectations and adds separate tests
for big endian targets with the correct expectations.
@@ -1,5 +1,8 @@
//@ run-fail
//@ compile-flags: -C debug-assertions
// This test depends on the endianess and has a different behavior on
// big endian.
//@ ignore-endian-big
//@ error-pattern: trying to construct an enum from an invalid value 0x10000
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of splitting this test, consider using revisions and keeping the old name?

Copy link
Contributor

@lcnr lcnr Jul 3, 2025

Choose a reason for hiding this comment

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

search for existing //@ revisions to see how it works

Copy link
Member

Choose a reason for hiding this comment

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

Or better, use cfg to make the code work under little-endian and big-endian.

@@ -1,5 +1,8 @@
//@ run-pass
//@ compile-flags: -C debug-assertions
// This test depends on the endianess and has a different behavior on
// big endian.
//@ ignore-endian-big
Copy link
Contributor

Choose a reason for hiding this comment

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

same in this test

@@ -1,5 +1,8 @@
//@ run-fail
//@ compile-flags: -C debug-assertions
// This test depends on the endianess and has a different behavior on
// big endian.
//@ ignore-endian-big
//@ error-pattern: trying to construct an enum from an invalid value 0x3
Copy link
Contributor

Choose a reason for hiding this comment

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

and this one

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

Choose a reason for hiding this comment

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

What is endian-dependent about this test?

Copy link
Member

Choose a reason for hiding this comment

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

Why should this pass on big-endian? That makes no sense, it's still an invalid enum!

Copy link
Member

Choose a reason for hiding this comment

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

Oh I think I see what happens... Foo becomes a 1-byte enum and 3 in big-endian leaves that byte 0, and only changes the padding.

The test should be made endian-independent by adding repr(u32) to Foo and by having Bar with two u32 fields:

#[allow(dead_code)]
#[repr(u32)]
enum Foo {
    A,
    B,
}

#[allow(dead_code)]
struct Bar {
    a: u32,
    b: u32,
}

fn main() {
    let _val: Option<(u32, Foo)> =
        unsafe { std::mem::transmute::<_, Option<(u32, Foo)>>(Bar { a: 3, b: 3 }) };
}

Copy link
Member

Choose a reason for hiding this comment

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

Replace 4 by u32::MAX here, then the test fails both under little-endian and big-endian.

@@ -0,0 +1,23 @@
//@ run-fail
Copy link
Member

Choose a reason for hiding this comment

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

A test called ok that is "run-fail" doesn't make a lot of sense, does 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