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.
There was a problem hiding this comment.
While a good idea in theory, this is significantly more typing than I am up for at the moment, to get all of the CHECK directives written for all the MIR statements we emit across all the variations of thing we check for. I'm fine with you writing the diff and pushing to this branch.
It's |
|
See also #143273, which fixes a similar-looking issue. |
097cb2f to
449eafd
Compare
This comment has been minimized.
This comment has been minimized.
449eafd to
cdb47bf
Compare
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? @scottmcm |
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.