2025-06-08 16:49:45 -04:00
|
|
|
//@ compile-flags: -Zmir-opt-level=0
|
2023-10-16 17:36:39 +00:00
|
|
|
// skip-filecheck
|
2022-09-04 20:00:31 -07:00
|
|
|
// EMIT_MIR enum_cast.foo.built.after.mir
|
|
|
|
|
// EMIT_MIR enum_cast.bar.built.after.mir
|
|
|
|
|
// EMIT_MIR enum_cast.boo.built.after.mir
|
2023-05-14 22:29:26 -07:00
|
|
|
// EMIT_MIR enum_cast.far.built.after.mir
|
2022-06-29 14:18:55 +00:00
|
|
|
|
2025-07-23 22:13:05 -07:00
|
|
|
// Previously MIR building included range `Assume`s in the MIR statements,
|
|
|
|
|
// which these tests demonstrated, but now that we have range metadata on
|
|
|
|
|
// parameters in LLVM (in addition to !range metadata on loads) the impact
|
|
|
|
|
// of the extra volume of MIR is worse than its value.
|
|
|
|
|
// Thus these are now about the discriminant type and the cast type,
|
|
|
|
|
// both of which might be different from the backend type of the tag.
|
|
|
|
|
|
2022-06-29 14:18:55 +00:00
|
|
|
enum Foo {
|
2024-06-03 10:18:33 +10:00
|
|
|
A,
|
2022-06-29 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum Bar {
|
2024-06-03 10:18:33 +10:00
|
|
|
A,
|
|
|
|
|
B,
|
2022-06-29 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[repr(u8)]
|
|
|
|
|
enum Boo {
|
2024-06-03 10:18:33 +10:00
|
|
|
A,
|
|
|
|
|
B,
|
2022-06-29 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-14 22:29:26 -07:00
|
|
|
#[repr(i16)]
|
|
|
|
|
enum Far {
|
2024-06-03 10:18:33 +10:00
|
|
|
A,
|
|
|
|
|
B,
|
2023-05-14 22:29:26 -07:00
|
|
|
}
|
|
|
|
|
|
2022-06-29 14:18:55 +00:00
|
|
|
fn foo(foo: Foo) -> usize {
|
|
|
|
|
foo as usize
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn bar(bar: Bar) -> usize {
|
|
|
|
|
bar as usize
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn boo(boo: Boo) -> usize {
|
|
|
|
|
boo as usize
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-14 22:29:26 -07:00
|
|
|
fn far(far: Far) -> isize {
|
|
|
|
|
far as isize
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[repr(i16)]
|
|
|
|
|
enum SignedAroundZero {
|
|
|
|
|
A = -2,
|
|
|
|
|
B = 0,
|
|
|
|
|
C = 2,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[repr(u16)]
|
|
|
|
|
enum UnsignedAroundZero {
|
|
|
|
|
A = 65535,
|
|
|
|
|
B = 0,
|
|
|
|
|
C = 1,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EMIT_MIR enum_cast.signy.built.after.mir
|
|
|
|
|
fn signy(x: SignedAroundZero) -> i16 {
|
|
|
|
|
x as i16
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EMIT_MIR enum_cast.unsigny.built.after.mir
|
|
|
|
|
fn unsigny(x: UnsignedAroundZero) -> u16 {
|
|
|
|
|
// FIXME: This doesn't get an around-the-end range today, sadly.
|
|
|
|
|
x as u16
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-03 10:18:33 +10:00
|
|
|
enum NotStartingAtZero {
|
|
|
|
|
A = 4,
|
|
|
|
|
B = 6,
|
|
|
|
|
C = 8,
|
|
|
|
|
}
|
2023-05-14 22:29:26 -07:00
|
|
|
|
|
|
|
|
// EMIT_MIR enum_cast.offsetty.built.after.mir
|
|
|
|
|
fn offsetty(x: NotStartingAtZero) -> u32 {
|
|
|
|
|
x as u32
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-03 10:18:33 +10:00
|
|
|
fn main() {}
|