@@ -66,7 +66,8 @@ pub struct Frame<'tcx> {
66
66
pub return_to_block : StackPopCleanup ,
67
67
68
68
/// The location where the result of the current stack frame should be written to.
69
- pub return_lvalue : Lvalue < ' tcx > ,
69
+ /// None if the function is a diverging function
70
+ pub return_lvalue : Option < Lvalue < ' tcx > > ,
70
71
71
72
/// The list of locals for this stack frame, stored in order as
72
73
/// `[arguments..., variables..., temporaries...]`. The locals are stored as `Option<Value>`s.
@@ -266,7 +267,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
266
267
instance : ty:: Instance < ' tcx > ,
267
268
span : codemap:: Span ,
268
269
mir : & ' tcx mir:: Mir < ' tcx > ,
269
- return_lvalue : Lvalue < ' tcx > ,
270
+ return_lvalue : Option < Lvalue < ' tcx > > ,
270
271
return_to_block : StackPopCleanup ,
271
272
) -> EvalResult < ' tcx > {
272
273
:: log_settings:: settings ( ) . indentation += 1 ;
@@ -323,7 +324,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
323
324
:: log_settings:: settings ( ) . indentation -= 1 ;
324
325
let frame = self . stack . pop ( ) . expect ( "tried to pop a stack frame, but there were none" ) ;
325
326
match frame. return_to_block {
326
- StackPopCleanup :: MarkStatic ( mutable) => if let Lvalue :: Global ( id) = frame. return_lvalue {
327
+ StackPopCleanup :: MarkStatic ( mutable) => if let Lvalue :: Global ( id) = frame. return_lvalue . expect ( "diverging static" ) {
327
328
let global_value = self . globals . get_mut ( & id)
328
329
. expect ( "global should have been cached (static)" ) ;
329
330
match global_value. value {
@@ -389,13 +390,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
389
390
where J :: IntoIter : ExactSizeIterator ,
390
391
{
391
392
// FIXME(solson)
392
- let dest_ptr = self . force_allocation ( dest) ?. to_ptr ( ) ;
393
+ let dest_ptr = self . force_allocation ( dest) ?. to_ptr ( ) ? ;
393
394
394
395
let discr_dest = dest_ptr. offset ( discr_offset, self . memory . layout ) ?;
395
396
self . memory . write_uint ( discr_dest, discr_val, discr_size) ?;
396
397
397
398
let dest = Lvalue :: Ptr {
398
- ptr : dest_ptr,
399
+ ptr : PrimVal :: Ptr ( dest_ptr) ,
399
400
extra : LvalueExtra :: DowncastVariant ( variant_idx) ,
400
401
} ;
401
402
@@ -481,7 +482,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
481
482
match * dest_layout {
482
483
Univariant { ref variant, .. } => {
483
484
if variant. packed {
484
- let ptr = self . force_allocation ( dest) ?. to_ptr_and_extra ( ) . 0 ;
485
+ let ptr = self . force_allocation ( dest) ?. to_ptr_and_extra ( ) . 0 . to_ptr ( ) ? ;
485
486
self . memory . mark_packed ( ptr, variant. stride ( ) . bytes ( ) ) ;
486
487
}
487
488
self . assign_fields ( dest, dest_ty, operands) ?;
@@ -499,7 +500,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
499
500
. to_u128_unchecked ( ) ;
500
501
let discr_size = discr. size ( ) . bytes ( ) ;
501
502
if variants[ variant] . packed {
502
- let ptr = self . force_allocation ( dest) ?. to_ptr_and_extra ( ) . 0 ;
503
+ let ptr = self . force_allocation ( dest) ?. to_ptr_and_extra ( ) . 0 . to_ptr ( ) ? ;
503
504
self . memory . mark_packed ( ptr, variants[ variant] . stride ( ) . bytes ( ) ) ;
504
505
}
505
506
@@ -541,7 +542,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
541
542
StructWrappedNullablePointer { nndiscr, ref nonnull, ref discrfield, .. } => {
542
543
if let mir:: AggregateKind :: Adt ( _, variant, _, _) = * * kind {
543
544
if nonnull. packed {
544
- let ptr = self . force_allocation ( dest) ?. to_ptr_and_extra ( ) . 0 ;
545
+ let ptr = self . force_allocation ( dest) ?. to_ptr_and_extra ( ) . 0 . to_ptr ( ) ? ;
545
546
self . memory . mark_packed ( ptr, nonnull. stride ( ) . bytes ( ) ) ;
546
547
}
547
548
if nndiscr == variant as u64 {
@@ -554,7 +555,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
554
555
let ( offset, ty) = self . nonnull_offset_and_ty ( dest_ty, nndiscr, discrfield) ?;
555
556
556
557
// FIXME(solson)
557
- let dest = self . force_allocation ( dest) ?. to_ptr ( ) ;
558
+ let dest = self . force_allocation ( dest) ?. to_ptr ( ) ? ;
558
559
559
560
let dest = dest. offset ( offset. bytes ( ) , self . memory . layout ) ?;
560
561
let dest_size = self . type_size ( ty) ?
@@ -613,7 +614,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
613
614
let value = self . eval_operand ( operand) ?;
614
615
615
616
// FIXME(solson)
616
- let dest = self . force_allocation ( dest) ?. to_ptr ( ) ;
617
+ let dest = self . force_allocation ( dest) ?. to_ptr ( ) ? ;
617
618
618
619
for i in 0 ..length {
619
620
let elem_dest = dest. offset ( i * elem_size, self . memory . layout ) ?;
@@ -630,8 +631,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
630
631
631
632
Ref ( _, _, ref lvalue) => {
632
633
let src = self . eval_lvalue ( lvalue) ?;
633
- let ( raw_ptr, extra) = self . force_allocation ( src) ?. to_ptr_and_extra ( ) ;
634
- let ptr = PrimVal :: Ptr ( raw_ptr) ;
634
+ let ( ptr, extra) = self . force_allocation ( src) ?. to_ptr_and_extra ( ) ;
635
635
636
636
let val = match extra {
637
637
LvalueExtra :: None => Value :: ByVal ( ptr) ,
@@ -726,7 +726,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
726
726
Discriminant ( ref lvalue) => {
727
727
let lval = self . eval_lvalue ( lvalue) ?;
728
728
let ty = self . lvalue_ty ( lvalue) ;
729
- let ptr = self . force_allocation ( lval) ?. to_ptr ( ) ;
729
+ let ptr = self . force_allocation ( lval) ?. to_ptr ( ) ? ;
730
730
let discr_val = self . read_discriminant_value ( ptr, ty) ?;
731
731
if let ty:: TyAdt ( adt_def, _) = ty. sty {
732
732
if adt_def. discriminants ( self . tcx ) . all ( |v| discr_val != v. to_u128_unchecked ( ) ) {
@@ -856,14 +856,14 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
856
856
}
857
857
}
858
858
859
- pub ( super ) fn wrapping_pointer_offset ( & self , ptr : Pointer , pointee_ty : Ty < ' tcx > , offset : i64 ) -> EvalResult < ' tcx , Pointer > {
859
+ pub ( super ) fn wrapping_pointer_offset ( & self , ptr : PrimVal , pointee_ty : Ty < ' tcx > , offset : i64 ) -> EvalResult < ' tcx , PrimVal > {
860
860
// FIXME: assuming here that type size is < i64::max_value()
861
861
let pointee_size = self . type_size ( pointee_ty) ?. expect ( "cannot offset a pointer to an unsized type" ) as i64 ;
862
862
let offset = offset. overflowing_mul ( pointee_size) . 0 ;
863
- Ok ( ptr. wrapping_signed_offset ( offset, self . memory . layout ) )
863
+ ptr. wrapping_signed_offset ( offset, self . memory . layout )
864
864
}
865
865
866
- pub ( super ) fn pointer_offset ( & self , ptr : Pointer , pointee_ty : Ty < ' tcx > , offset : i64 ) -> EvalResult < ' tcx , Pointer > {
866
+ pub ( super ) fn pointer_offset ( & self , ptr : PrimVal , pointee_ty : Ty < ' tcx > , offset : i64 ) -> EvalResult < ' tcx , PrimVal > {
867
867
if offset == 0 {
868
868
// rustc relies on Offset-by-0 to be well-defined even for "bad" pointers like Unique::empty().
869
869
return Ok ( ptr) ;
@@ -872,7 +872,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
872
872
let pointee_size = self . type_size ( pointee_ty) ?. expect ( "cannot offset a pointer to an unsized type" ) as i64 ;
873
873
return if let Some ( offset) = offset. checked_mul ( pointee_size) {
874
874
let ptr = ptr. signed_offset ( offset, self . memory . layout ) ?;
875
- self . memory . check_bounds ( ptr, false ) ?;
875
+ self . memory . check_bounds ( ptr. to_ptr ( ) ? , false ) ?;
876
876
Ok ( ptr)
877
877
} else {
878
878
Err ( EvalError :: OverflowingMath )
@@ -1036,7 +1036,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1036
1036
1037
1037
Lvalue :: Ptr { ptr, extra } => {
1038
1038
assert_eq ! ( extra, LvalueExtra :: None ) ;
1039
- self . write_value_to_ptr ( src_val, ptr, dest_ty)
1039
+ self . write_value_to_ptr ( src_val, ptr. to_ptr ( ) ? , dest_ty)
1040
1040
}
1041
1041
1042
1042
Lvalue :: Local { frame, local, field } => {
@@ -1242,20 +1242,20 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1242
1242
}
1243
1243
}
1244
1244
1245
- fn read_ptr ( & mut self , ptr : Pointer , pointee_ty : Ty < ' tcx > ) -> EvalResult < ' tcx , Value > {
1245
+ pub ( crate ) fn read_ptr ( & self , ptr : Pointer , pointee_ty : Ty < ' tcx > ) -> EvalResult < ' tcx , Value > {
1246
1246
let p = self . memory . read_ptr ( ptr) ?;
1247
1247
if self . type_is_sized ( pointee_ty) {
1248
- Ok ( Value :: ByVal ( PrimVal :: Ptr ( p ) ) )
1248
+ Ok ( Value :: ByVal ( p ) )
1249
1249
} else {
1250
1250
trace ! ( "reading fat pointer extra of type {}" , pointee_ty) ;
1251
1251
let extra = ptr. offset ( self . memory . pointer_size ( ) , self . memory . layout ) ?;
1252
1252
let extra = match self . tcx . struct_tail ( pointee_ty) . sty {
1253
- ty:: TyDynamic ( ..) => PrimVal :: Ptr ( self . memory . read_ptr ( extra) ?) ,
1253
+ ty:: TyDynamic ( ..) => self . memory . read_ptr ( extra) ?,
1254
1254
ty:: TySlice ( ..) |
1255
1255
ty:: TyStr => PrimVal :: from_u128 ( self . memory . read_usize ( extra) ? as u128 ) ,
1256
1256
_ => bug ! ( "unsized primval ptr read from {:?}" , pointee_ty) ,
1257
1257
} ;
1258
- Ok ( Value :: ByValPair ( PrimVal :: Ptr ( p ) , extra) )
1258
+ Ok ( Value :: ByValPair ( p , extra) )
1259
1259
}
1260
1260
}
1261
1261
@@ -1301,7 +1301,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1301
1301
ty:: TyFloat ( FloatTy :: F32 ) => PrimVal :: from_f32 ( self . memory . read_f32 ( ptr) ?) ,
1302
1302
ty:: TyFloat ( FloatTy :: F64 ) => PrimVal :: from_f64 ( self . memory . read_f64 ( ptr) ?) ,
1303
1303
1304
- ty:: TyFnPtr ( _) => self . memory . read_ptr ( ptr) . map ( PrimVal :: Ptr ) ?,
1304
+ ty:: TyFnPtr ( _) => self . memory . read_ptr ( ptr) ?,
1305
1305
ty:: TyRef ( _, ref tam) |
1306
1306
ty:: TyRawPtr ( ref tam) => return self . read_ptr ( ptr, tam. ty ) . map ( Some ) ,
1307
1307
@@ -1360,7 +1360,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1360
1360
( & ty:: TyArray ( _, length) , & ty:: TySlice ( _) ) => {
1361
1361
let ptr = src. read_ptr ( & self . memory ) ?;
1362
1362
let len = PrimVal :: from_u128 ( length as u128 ) ;
1363
- let ptr = PrimVal :: Ptr ( ptr) ;
1364
1363
self . write_value ( Value :: ByValPair ( ptr, len) , dest, dest_ty)
1365
1364
}
1366
1365
( & ty:: TyDynamic ( ..) , & ty:: TyDynamic ( ..) ) => {
@@ -1374,7 +1373,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1374
1373
let trait_ref = self . tcx . erase_regions ( & trait_ref) ;
1375
1374
let vtable = self . get_vtable ( src_pointee_ty, trait_ref) ?;
1376
1375
let ptr = src. read_ptr ( & self . memory ) ?;
1377
- let ptr = PrimVal :: Ptr ( ptr) ;
1378
1376
let extra = PrimVal :: Ptr ( vtable) ;
1379
1377
self . write_value ( Value :: ByValPair ( ptr, extra) , dest, dest_ty)
1380
1378
} ,
@@ -1423,7 +1421,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1423
1421
} ;
1424
1422
1425
1423
// FIXME(solson)
1426
- let dest = self . force_allocation ( dest) ?. to_ptr ( ) ;
1424
+ let dest = self . force_allocation ( dest) ?. to_ptr ( ) ? ;
1427
1425
let iter = src_fields. zip ( dst_fields) . enumerate ( ) ;
1428
1426
for ( i, ( src_f, dst_f) ) in iter {
1429
1427
let src_fty = monomorphize_field_ty ( self . tcx , src_f, substs_a) ;
@@ -1632,7 +1630,7 @@ pub fn eval_main<'a, 'tcx: 'a>(
1632
1630
start_instance,
1633
1631
start_mir. span ,
1634
1632
start_mir,
1635
- Lvalue :: from_ptr ( ret_ptr) ,
1633
+ Some ( Lvalue :: from_ptr ( ret_ptr) ) ,
1636
1634
StackPopCleanup :: None ,
1637
1635
) ?;
1638
1636
@@ -1659,7 +1657,7 @@ pub fn eval_main<'a, 'tcx: 'a>(
1659
1657
main_instance,
1660
1658
main_mir. span ,
1661
1659
main_mir,
1662
- Lvalue :: from_ptr ( Pointer :: zst_ptr ( ) ) ,
1660
+ Some ( Lvalue :: zst ( ) ) ,
1663
1661
StackPopCleanup :: None ,
1664
1662
) ?;
1665
1663
}
0 commit comments