Remove a buggy cast from CheckEnums - #159447
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
The following reproducer is a variant that still breaks for me with the same error after applying this PR. Notice that use std::{mem, num::NonZeroI32};
#[repr(C)]
struct Payload {
pad: u8,
value: NonZeroI32,
}
enum Thing {
Value(Payload),
Empty,
}
fn main() {
let value = Thing::Value(Payload {
pad: 0,
value: NonZeroI32::new(-1).unwrap(),
});
let _ = unsafe { mem::transmute::<Thing, Thing>(value) };
} |
|
It's not obvious to me that this should be going to Seems like it should be emitting rust/compiler/rustc_codegen_ssa/src/traits/builder.rs Lines 270 to 289 in 421875f |
| //@ run-pass | ||
| //@ compile-flags: -C debug-assertions | ||
|
|
||
| // This is a regression test for https://github.com/rust-lang/rust/issues/159433 |
There was a problem hiding this comment.
suggestion: while these UI tests are good to have, I think we should have a mir-opt test showing and testing the MIR generated for various cases too.
There's a bunch of codegen-llvm tests around transmutes if you want inspiration of things to try.
It's |
|
See also #143273, which fixes a similar-looking issue. |
This is a fix for #159433.
Based on the MIR that @theemathas reported:
I think the problem here is that on the full-size discriminant path we just have an unnecessary cast. We transmuted to
u32to read the discriminant value, then we should just cast directly tou128to do the comparison. There's no need to get sidetracked by the fact that there is ani32field.We do still need the extra cast along our field-reading path that uses
[MaybeUninit<u8>; N], so the fix here is to move the code into that arm of theif.