Skip to content

Commit 4b95376

Browse files
committed
Respect endianness correctly in CheckEnums test suite
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 parent c9fb6dc commit 4b95376

8 files changed

+102
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ run-pass
2+
//@ compile-flags: -C debug-assertions
3+
// This test depends on the endianess and has a different behavior on
4+
// little endian.
5+
//@ ignore-endian-little
6+
7+
#[allow(dead_code)]
8+
#[repr(u32)]
9+
enum Foo {
10+
A,
11+
B,
12+
}
13+
14+
#[allow(dead_code)]
15+
struct Bar {
16+
a: u16,
17+
b: u16,
18+
}
19+
20+
fn main() {
21+
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 0, b: 1 }) };
22+
}

tests/ui/mir/enum/convert_non_enum_break.rs renamed to tests/ui/mir/enum/convert_non_enum_break_little_endian.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//@ run-fail
22
//@ compile-flags: -C debug-assertions
3+
// This test depends on the endianess and has a different behavior on
4+
// big endian.
5+
//@ ignore-endian-big
36
//@ error-pattern: trying to construct an enum from an invalid value 0x10000
47

58
#[allow(dead_code)]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ run-fail
2+
//@ compile-flags: -C debug-assertions
3+
// This test depends on the endianess and has a different behavior on
4+
// little endian.
5+
//@ ignore-endian-little
6+
//@ error-pattern: trying to construct an enum from an invalid value
7+
8+
#[allow(dead_code)]
9+
#[repr(u32)]
10+
enum Foo {
11+
A,
12+
B,
13+
}
14+
15+
#[allow(dead_code)]
16+
struct Bar {
17+
a: u16,
18+
b: u16,
19+
}
20+
21+
fn main() {
22+
let _val: Foo = unsafe { std::mem::transmute::<_, Foo>(Bar { a: 1, b: 0 }) };
23+
}

tests/ui/mir/enum/convert_non_enum_ok.rs renamed to tests/ui/mir/enum/convert_non_enum_ok_little_endian.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//@ run-pass
22
//@ compile-flags: -C debug-assertions
3+
// This test depends on the endianess and has a different behavior on
4+
// big endian.
5+
//@ ignore-endian-big
36

47
#[allow(dead_code)]
58
#[repr(u32)]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ run-pass
2+
//@ compile-flags: -C debug-assertions
3+
// This test depends on the endianess and has a different behavior on
4+
// big endian.
5+
//@ ignore-endian-little
6+
7+
#[allow(dead_code)]
8+
enum Foo {
9+
A,
10+
B,
11+
}
12+
13+
#[allow(dead_code)]
14+
struct Bar {
15+
a: usize,
16+
b: usize,
17+
}
18+
19+
fn main() {
20+
let _val: Option<(usize, Foo)> =
21+
unsafe { std::mem::transmute::<_, Option<(usize, Foo)>>(Bar { a: 3, b: 3 }) };
22+
}

tests/ui/mir/enum/niche_option_tuple_break.rs renamed to tests/ui/mir/enum/niche_option_tuple_break_little_endian.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//@ run-fail
22
//@ compile-flags: -C debug-assertions
3+
// This test depends on the endianess and has a different behavior on
4+
// big endian.
5+
//@ ignore-endian-big
36
//@ error-pattern: trying to construct an enum from an invalid value 0x3
47

58
#[allow(dead_code)]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ run-pass
2+
//@ compile-flags: -C debug-assertions
3+
// This test depends on the endianess and has a different behavior on
4+
// little endian.
5+
//@ ignore-endian-little
6+
7+
#[allow(dead_code)]
8+
#[repr(u16)]
9+
enum Mix {
10+
A,
11+
B(u16),
12+
}
13+
14+
#[allow(dead_code)]
15+
enum Nested {
16+
C(Mix),
17+
D,
18+
E,
19+
}
20+
21+
fn main() {
22+
let _val: Nested = unsafe { std::mem::transmute::<u32, Nested>(4) };
23+
}

tests/ui/mir/enum/with_niche_int_break.rs renamed to tests/ui/mir/enum/with_niche_int_break_little_endian.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//@ run-fail
22
//@ compile-flags: -C debug-assertions
33
//@ error-pattern: trying to construct an enum from an invalid value 0x4
4+
// This test depends on the endianess and has a different behavior on
5+
// big endian.
6+
//@ ignore-endian-big
47

58
#[allow(dead_code)]
69
#[repr(u16)]

0 commit comments

Comments
 (0)