|
1 | 1 | use rustc_abi::Primitive::{Int, Pointer};
|
2 |
| -use rustc_abi::{Align, FieldsShape, Size, TagEncoding, VariantIdx, Variants}; |
| 2 | +use rustc_abi::{Align, BackendRepr, FieldsShape, Size, TagEncoding, VariantIdx, 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};
|
@@ -387,13 +388,17 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
|
387 | 388 | let niche_llty = bx.cx().immediate_backend_type(niche.layout);
|
388 | 389 | let niche_value = variant_index.as_u32() - niche_variants.start().as_u32();
|
389 | 390 | let niche_value = (niche_value as u128).wrapping_add(niche_start);
|
390 |
| - // FIXME(eddyb): check the actual primitive type here. |
391 |
| - let niche_llval = if niche_value == 0 { |
392 |
| - // HACK(eddyb): using `c_null` as it works on all types. |
393 |
| - bx.cx().const_null(niche_llty) |
394 |
| - } else { |
395 |
| - bx.cx().const_uint_big(niche_llty, niche_value) |
| 391 | + |
| 392 | + let BackendRepr::Scalar(scalar) = niche.layout.backend_repr else { |
| 393 | + bug!("expected a scalar placeref for the niche"); |
396 | 394 | };
|
| 395 | + let max = niche.layout.size.unsigned_int_max(); |
| 396 | + let wrapped = niche_value & max; |
| 397 | + let niche_llval = bx.cx().scalar_to_backend( |
| 398 | + Scalar::from_uint(wrapped, niche.layout.size), |
| 399 | + scalar, |
| 400 | + niche_llty, |
| 401 | + ); |
397 | 402 | OperandValue::Immediate(niche_llval).store(bx, niche);
|
398 | 403 | }
|
399 | 404 | }
|
|
0 commit comments