-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//@ run-pass | ||
//@ compile-flags: -C debug-assertions | ||
// This test depends on the endianess and has a different behavior on | ||
// little endian. | ||
//@ ignore-endian-little | ||
|
||
#[allow(dead_code)] | ||
#[repr(u32)] | ||
enum Foo { | ||
A, | ||
B, | ||
} | ||
|
||
#[allow(dead_code)] | ||
struct Bar { | ||
a: u16, | ||
b: u16, | ||
} | ||
|
||
fn main() { | ||
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 0, b: 1 }) }; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//@ run-fail | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A test called |
||
//@ compile-flags: -C debug-assertions | ||
// This test depends on the endianess and has a different behavior on | ||
// little endian. | ||
//@ ignore-endian-little | ||
//@ error-pattern: trying to construct an enum from an invalid value | ||
|
||
#[allow(dead_code)] | ||
#[repr(u32)] | ||
enum Foo { | ||
A, | ||
B, | ||
} | ||
|
||
#[allow(dead_code)] | ||
struct Bar { | ||
a: u16, | ||
b: u16, | ||
} | ||
|
||
fn main() { | ||
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 1, b: 0 }) }; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this test use a struct with two |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same in this test |
||
|
||
#[allow(dead_code)] | ||
#[repr(u32)] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I think I see what happens... The test should be made endian-independent by adding #[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 }) };
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//@ run-pass | ||
//@ compile-flags: -C debug-assertions | ||
// This test depends on the endianess and has a different behavior on | ||
// big endian. | ||
//@ ignore-endian-little | ||
|
||
#[allow(dead_code)] | ||
enum Foo { | ||
A, | ||
B, | ||
} | ||
|
||
#[allow(dead_code)] | ||
struct Bar { | ||
a: usize, | ||
b: usize, | ||
} | ||
|
||
fn main() { | ||
let _val: Option<(usize, Foo)> = | ||
unsafe { std::mem::transmute::<_, Option<(usize, Foo)>>(Bar { a: 3, b: 3 }) }; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is endian-dependent about this test? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this one |
||
|
||
#[allow(dead_code)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//@ run-pass | ||
//@ compile-flags: -C debug-assertions | ||
// This test depends on the endianess and has a different behavior on | ||
// little endian. | ||
//@ ignore-endian-little | ||
|
||
#[allow(dead_code)] | ||
#[repr(u16)] | ||
enum Mix { | ||
A, | ||
B(u16), | ||
} | ||
|
||
#[allow(dead_code)] | ||
enum Nested { | ||
C(Mix), | ||
D, | ||
E, | ||
} | ||
|
||
fn main() { | ||
let _val: Nested = unsafe { std::mem::transmute::<u32, Nested>(4) }; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace |
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 worksThere was a problem hiding this comment.
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.