Closed
Description
When loading discriminants of an enum that uses niche optimizations, Miri/CTFE has to do some arithmetic:
rust/src/librustc_mir/interpret/operand.rs
Lines 645 to 646 in bdd4bda
Currently, this happens on type u128
. That's probably wrong, it should happen on the type of the discriminant. That will result in different overflow behavior.
It's just addition and subtraction, so signed vs unsigned does not matter and we could just mask off the "too high" bits after each operation, as in:
rust/src/librustc_target/abi/mod.rs
Lines 664 to 669 in bdd4bda
However, it might be more elegant to use our binary_*op
methods in operator.rs
.