Skip to content

Commit

Permalink
use stores of the correct size to set discriminants
Browse files Browse the repository at this point in the history
  • Loading branch information
the8472 committed Oct 14, 2024
1 parent 2aa26d8 commit e7b2ca9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions compiler/rustc_codegen_ssa/src/mir/place.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustc_abi::Primitive::{Int, Pointer};
use rustc_abi::{Align, FieldsShape, Size, TagEncoding, Variants};
use rustc_middle::mir::interpret::Scalar;
use rustc_middle::mir::tcx::PlaceTy;
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
use rustc_middle::ty::{self, Ty};
Expand Down Expand Up @@ -388,13 +389,17 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
let niche_llty = bx.cx().immediate_backend_type(niche.layout);
let niche_value = variant_index.as_u32() - niche_variants.start().as_u32();
let niche_value = (niche_value as u128).wrapping_add(niche_start);
// FIXME(eddyb): check the actual primitive type here.
let niche_llval = if niche_value == 0 {
// HACK(eddyb): using `c_null` as it works on all types.
bx.cx().const_null(niche_llty)
} else {
bx.cx().const_uint_big(niche_llty, niche_value)

let rustc_abi::Abi::Scalar(scalar) = niche.layout.abi else {
bug!("expected a scalar placeref for the niche");
};
let max = niche.layout.size.unsigned_int_max();
let wrapped = niche_value & max;
let niche_llval = bx.cx().scalar_to_backend(
Scalar::from_uint(wrapped, niche.layout.size),
scalar,
niche_llty,
);
OperandValue::Immediate(niche_llval).store(bx, niche);
}
}
Expand Down

0 comments on commit e7b2ca9

Please sign in to comment.