-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Interpreter calls discriminant_for_variant on zero variant enum #89765
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
cc @RalfJung |
Ah, nasty unsafe code is nasty. ;) This reminds me of discussions I had with @eddyb a while ago about the Basically the bad code is like match op.layout.variants {
Variants::Single { index } => {
let discr = match op.layout.ty.discriminant_for_variant(*self.tcx, index) { but is this really the only part of the compiler that assumes that for |
FTR this is the layout of the empty enum: Layout {
fields: Primitive,
variants: Single {
index: 0,
},
abi: Uninhabited,
largest_niche: None,
align: AbiAndPrefAlign {
abi: Align {
pow2: 0,
},
pref: Align {
pow2: 0,
},
},
size: Size {
raw: 0,
},
} The fix could be
I haven't made up my mind yet about which one seems better... but I am leaning towards the first option. |
As pointed out at #89764 (comment), our codegen backend actually says that CTFE does not check validity invariants, so this does not clearly say what we should do there; we could still treat all types without discriminants the same (by returning 0). |
In release mode https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=b4e16b630ff26b1c56b45647a8330f9a returns an undef (look at llvm IR) even though from all docs it should be sound. At least as long as |
I have not been able to weaponize it, but we should probably just make the codegen backend return 0 |
In my book |
In #89764, things look like we should properly check full validity of a value when reading its discriminant. However, that on its own cannot fix this ICE since the first thing validity checking will do is of course read the discriminant... |
…num, r=petrochenkov fix getting the discriminant of a zero-variant enum Fixes rust-lang#89765
…num, r=petrochenkov fix getting the discriminant of a zero-variant enum Fixes rust-lang#89765
…num, r=petrochenkov fix getting the discriminant of a zero-variant enum Fixes rust-lang#89765
Interpreter calls
discriminant_for_variant
on zero variant enum, when asked unsafely to do so :-).Code
Error
@rustbot label: +requires-nightly +A-const-eval
The text was updated successfully, but these errors were encountered: