@@ -670,9 +670,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
670
670
671
671
Ref ( _, _, ref lvalue) => {
672
672
let src = self . eval_lvalue ( lvalue) ?;
673
- // We ignore the alignment of the lvalue here -- this rvalue produces sth. of type &, which must always be aligned.
673
+ // We ignore the alignment of the lvalue here -- special handling for packed structs ends
674
+ // at the `&` operator.
674
675
let ( ptr, extra, _aligned) = self . force_allocation ( src) ?. to_ptr_extra_aligned ( ) ;
675
- let ty = self . lvalue_ty ( lvalue) ;
676
676
677
677
let val = match extra {
678
678
LvalueExtra :: None => ptr. to_value ( ) ,
@@ -682,10 +682,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
682
682
bug ! ( "attempted to take a reference to an enum downcast lvalue" ) ,
683
683
} ;
684
684
685
- // Check alignment and non-NULLness.
686
- let ( _, align) = self . size_and_align_of_dst ( ty, val) ?;
687
- self . memory . check_align ( ptr, align) ?;
688
-
689
685
self . write_value ( val, dest, dest_ty) ?;
690
686
}
691
687
@@ -1105,6 +1101,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1105
1101
dest : Lvalue < ' tcx > ,
1106
1102
dest_ty : Ty < ' tcx > ,
1107
1103
) -> EvalResult < ' tcx > {
1104
+ //trace!("Writing {:?} to {:?} at type {:?}", src_val, dest, dest_ty);
1108
1105
// Note that it is really important that the type here is the right one, and matches the type things are read at.
1109
1106
// In case `src_val` is a `ByValPair`, we don't do any magic here to handle padding properly, which is only
1110
1107
// correct if we never look at this data with the wrong type.
@@ -1382,7 +1379,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1382
1379
// if we transmute a ptr to an isize, reading it back into a primval shouldn't panic
1383
1380
// Due to read_ptr ignoring the sign, we need to jump around some hoops
1384
1381
match self . memory . read_int ( ptr. to_ptr ( ) ?, size) {
1385
- Err ( EvalError :: ReadPointerAsBytes ) if size == self . memory . pointer_size ( ) => self . memory . read_ptr ( ptr. to_ptr ( ) ?) ?. into_inner_primval ( ) ,
1382
+ Err ( EvalError :: ReadPointerAsBytes ) if size == self . memory . pointer_size ( ) =>
1383
+ // Reading as an int failed because we are seeing ptr bytes *and* we are actually reading at ptr size.
1384
+ // Let's try again, reading a ptr this time.
1385
+ self . memory . read_ptr ( ptr. to_ptr ( ) ?) ?. into_inner_primval ( ) ,
1386
1386
other => PrimVal :: from_i128 ( other?) ,
1387
1387
}
1388
1388
}
@@ -1397,11 +1397,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1397
1397
U128 => 16 ,
1398
1398
Us => self . memory . pointer_size ( ) ,
1399
1399
} ;
1400
- if size == self . memory . pointer_size ( ) {
1401
- // if we transmute a ptr to an usize, reading it back into a primval shouldn't panic
1402
- self . memory . read_ptr ( ptr. to_ptr ( ) ?) ? . into_inner_primval ( )
1403
- } else {
1404
- PrimVal :: from_u128 ( self . memory . read_uint ( ptr . to_ptr ( ) ? , size ) ? )
1400
+ // if we transmute a ptr to an usize, reading it back into a primval shouldn't panic
1401
+ // for consistency's sake, we use the same code as above
1402
+ match self . memory . read_uint ( ptr. to_ptr ( ) ?, size ) {
1403
+ Err ( EvalError :: ReadPointerAsBytes ) if size == self . memory . pointer_size ( ) => self . memory . read_ptr ( ptr . to_ptr ( ) ? ) ? . into_inner_primval ( ) ,
1404
+ other => PrimVal :: from_u128 ( other? ) ,
1405
1405
}
1406
1406
}
1407
1407
0 commit comments