@@ -319,6 +319,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
319
319
// some fieldless enum variants can have non-zero size but still `Aggregate` ABI... try
320
320
// to detect those here and also give them no data
321
321
_ if matches ! ( layout. abi, Abi :: Aggregate { .. } )
322
+ && matches ! ( layout. variants, abi:: Variants :: Single { .. } )
322
323
&& matches ! ( & layout. fields, abi:: FieldsShape :: Arbitrary { offsets, .. } if offsets. len( ) == 0 ) =>
323
324
{
324
325
Immediate :: Uninit
@@ -328,8 +329,9 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
328
329
assert_eq ! ( offset. bytes( ) , 0 ) ;
329
330
assert ! (
330
331
match ( self . layout. abi, layout. abi) {
331
- ( Abi :: Scalar ( ..) , Abi :: Scalar ( ..) ) => true ,
332
- ( Abi :: ScalarPair ( ..) , Abi :: ScalarPair ( ..) ) => true ,
332
+ ( Abi :: Scalar ( l) , Abi :: Scalar ( r) ) => l. size( cx) == r. size( cx) ,
333
+ ( Abi :: ScalarPair ( l1, l2) , Abi :: ScalarPair ( r1, r2) ) =>
334
+ l1. size( cx) == r1. size( cx) && l2. size( cx) == r2. size( cx) ,
333
335
_ => false ,
334
336
} ,
335
337
"cannot project into {} immediate with equally-sized field {}\n outer ABI: {:#?}\n field ABI: {:#?}" ,
@@ -344,16 +346,23 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
344
346
( Immediate :: ScalarPair ( a_val, b_val) , Abi :: ScalarPair ( a, b) ) => {
345
347
assert_matches ! ( layout. abi, Abi :: Scalar ( ..) ) ;
346
348
Immediate :: from ( if offset. bytes ( ) == 0 {
347
- debug_assert_eq ! ( layout. size, a. size( cx) ) ;
349
+ // It is "okay" to transmute from `usize` to a pointer (GVN relies on that).
350
+ // So only compare the size.
351
+ assert_eq ! ( layout. size, a. size( cx) ) ;
348
352
a_val
349
353
} else {
350
- debug_assert_eq ! ( offset, a. size( cx) . align_to( b. align( cx) . abi) ) ;
351
- debug_assert_eq ! ( layout. size, b. size( cx) ) ;
354
+ assert_eq ! ( offset, a. size( cx) . align_to( b. align( cx) . abi) ) ;
355
+ assert_eq ! ( layout. size, b. size( cx) ) ;
352
356
b_val
353
357
} )
354
358
}
355
359
// everything else is a bug
356
- _ => bug ! ( "invalid field access on immediate {}, layout {:#?}" , self , self . layout) ,
360
+ _ => bug ! (
361
+ "invalid field access on immediate {} at offset {}, original layout {:#?}" ,
362
+ self ,
363
+ offset. bytes( ) ,
364
+ self . layout
365
+ ) ,
357
366
} ;
358
367
359
368
ImmTy :: from_immediate ( inner_val, layout)
0 commit comments