@@ -203,10 +203,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
203
203
PrimVal :: from_uint_with_size ( n, self . memory . pointer_size ( ) )
204
204
}
205
205
206
- fn isize_primval ( & self , n : i64 ) -> PrimVal {
207
- PrimVal :: from_int_with_size ( n, self . memory . pointer_size ( ) )
208
- }
209
-
210
206
fn str_to_value ( & mut self , s : & str ) -> EvalResult < ' tcx , Value > {
211
207
// FIXME: cache these allocs
212
208
let ptr = self . memory . allocate ( s. len ( ) , 1 ) ?;
@@ -523,7 +519,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
523
519
self . write_value ( value, dest, value_ty) ?;
524
520
} else {
525
521
assert_eq ! ( operands. len( ) , 0 ) ;
526
- let zero = self . isize_primval ( 0 ) ;
522
+ let value_size = self . type_size ( dest_ty) . expect ( "pointer types are sized" ) ;
523
+ let zero = PrimVal :: from_int_with_size ( 0 , value_size) ;
527
524
self . write_primval ( dest, zero) ?;
528
525
}
529
526
} else {
@@ -541,13 +538,14 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
541
538
let operand_ty = self . operand_ty ( operand) ;
542
539
assert_eq ! ( self . type_size( operand_ty) , Some ( 0 ) ) ;
543
540
}
544
- let offset = self . nonnull_offset ( dest_ty, nndiscr, discrfield) ?;
541
+ let ( offset, ty ) = self . nonnull_offset_and_ty ( dest_ty, nndiscr, discrfield) ?;
545
542
546
543
// FIXME(solson)
547
544
let dest = self . force_allocation ( dest) ?. to_ptr ( ) ;
548
545
549
546
let dest = dest. offset ( offset. bytes ( ) as isize ) ;
550
- try!( self . memory . write_isize ( dest, 0 ) ) ;
547
+ let dest_size = self . type_size ( ty) . unwrap_or ( self . memory . pointer_size ( ) ) ;
548
+ try!( self . memory . write_int ( dest, 0 , dest_size) ) ;
551
549
}
552
550
} else {
553
551
bug ! ( "tried to assign {:?} to Layout::RawNullablePointer" , kind) ;
@@ -694,7 +692,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
694
692
}
695
693
}
696
694
697
- fn nonnull_offset ( & self , ty : Ty < ' tcx > , nndiscr : u64 , discrfield : & [ u32 ] ) -> EvalResult < ' tcx , Size > {
695
+ fn nonnull_offset_and_ty ( & self , ty : Ty < ' tcx > , nndiscr : u64 , discrfield : & [ u32 ] ) -> EvalResult < ' tcx , ( Size , Ty < ' tcx > ) > {
698
696
// Skip the constant 0 at the start meant for LLVM GEP.
699
697
let mut path = discrfield. iter ( ) . skip ( 1 ) . map ( |& i| i as usize ) ;
700
698
@@ -709,10 +707,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
709
707
_ => bug ! ( "non-enum for StructWrappedNullablePointer: {}" , ty) ,
710
708
} ;
711
709
712
- self . field_path_offset ( inner_ty, path)
710
+ self . field_path_offset_and_ty ( inner_ty, path)
713
711
}
714
712
715
- fn field_path_offset < I : Iterator < Item = usize > > ( & self , mut ty : Ty < ' tcx > , path : I ) -> EvalResult < ' tcx , Size > {
713
+ fn field_path_offset_and_ty < I : Iterator < Item = usize > > ( & self , mut ty : Ty < ' tcx > , path : I ) -> EvalResult < ' tcx , ( Size , Ty < ' tcx > ) > {
716
714
let mut offset = Size :: from_bytes ( 0 ) ;
717
715
718
716
// Skip the initial 0 intended for LLVM GEP.
@@ -722,7 +720,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
722
720
offset = offset. checked_add ( field_offset, & self . tcx . data_layout ) . unwrap ( ) ;
723
721
}
724
722
725
- Ok ( offset)
723
+ Ok ( ( offset, ty ) )
726
724
}
727
725
728
726
fn get_field_ty ( & self , ty : Ty < ' tcx > , field_index : usize ) -> EvalResult < ' tcx , Ty < ' tcx > > {
0 commit comments