|
1 | 1 | use rustc_abi::Primitive::{Int, Pointer};
|
2 | 2 | use rustc_abi::{Align, FieldsShape, Size, TagEncoding, Variants};
|
| 3 | +use rustc_middle::mir::interpret::Scalar; |
3 | 4 | use rustc_middle::mir::tcx::PlaceTy;
|
4 | 5 | use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
|
5 | 6 | use rustc_middle::ty::{self, Ty};
|
@@ -389,12 +390,18 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
|
389 | 390 | let niche_value = variant_index.as_u32() - niche_variants.start().as_u32();
|
390 | 391 | let niche_value = (niche_value as u128).wrapping_add(niche_start);
|
391 | 392 | // FIXME(eddyb): check the actual primitive type here.
|
392 |
| - let niche_llval = if niche_value == 0 { |
393 |
| - // HACK(eddyb): using `c_null` as it works on all types. |
394 |
| - bx.cx().const_null(niche_llty) |
395 |
| - } else { |
396 |
| - bx.cx().const_uint_big(niche_llty, niche_value) |
| 393 | + |
| 394 | + let rustc_abi::Abi::Scalar(scalar) = niche.layout.abi else { |
| 395 | + bug!("expected a scalar placeref for the niche"); |
397 | 396 | };
|
| 397 | + |
| 398 | + let max = niche.layout.size.unsigned_int_max(); |
| 399 | + let wrapped = niche_value & max; |
| 400 | + let niche_llval = bx.cx().scalar_to_backend( |
| 401 | + Scalar::from_uint(wrapped, niche.layout.size), |
| 402 | + scalar, |
| 403 | + niche_llty, |
| 404 | + ); |
398 | 405 | OperandValue::Immediate(niche_llval).store(bx, niche);
|
399 | 406 | }
|
400 | 407 | }
|
|
0 commit comments