@@ -616,7 +616,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
616
616
if let Place :: Ptr { ptr, .. } = frame. return_place {
617
617
// FIXME: to_ptr()? might be too extreme here, static zsts might reach this under certain conditions
618
618
self . memory . mark_static_initialized (
619
- ptr. read ( ) ?. to_ptr ( ) ?. alloc_id ,
619
+ ptr. unwrap_or_err ( ) ?. to_ptr ( ) ?. alloc_id ,
620
620
mutable,
621
621
) ?
622
622
} else {
@@ -744,7 +744,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
744
744
let ( dest, dest_align) = self . force_allocation ( dest) ?. to_ptr_align ( ) ;
745
745
746
746
if length > 0 {
747
- let dest = dest. read ( ) ?;
747
+ let dest = dest. unwrap_or_err ( ) ?;
748
748
//write the first value
749
749
self . write_value_to_ptr ( value, dest, dest_align, elem_ty) ?;
750
750
@@ -1082,7 +1082,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1082
1082
} ,
1083
1083
} ;
1084
1084
Ok ( Place :: Ptr {
1085
- ptr,
1085
+ ptr : ptr . into ( ) ,
1086
1086
align,
1087
1087
extra : variant. map_or ( PlaceExtra :: None , PlaceExtra :: DowncastVariant ) ,
1088
1088
} )
@@ -1120,7 +1120,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1120
1120
1121
1121
/// ensures this Value is not a ByRef
1122
1122
pub fn follow_by_ref_value (
1123
- & mut self ,
1123
+ & self ,
1124
1124
value : Value ,
1125
1125
ty : Ty < ' tcx > ,
1126
1126
) -> EvalResult < ' tcx , Value > {
@@ -1133,13 +1133,13 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1133
1133
}
1134
1134
1135
1135
pub fn value_to_scalar (
1136
- & mut self ,
1136
+ & self ,
1137
1137
ValTy { value, ty } : ValTy < ' tcx > ,
1138
1138
) -> EvalResult < ' tcx , Scalar > {
1139
1139
match self . follow_by_ref_value ( value, ty) ? {
1140
1140
Value :: ByRef { .. } => bug ! ( "follow_by_ref_value can't result in `ByRef`" ) ,
1141
1141
1142
- Value :: Scalar ( scalar) => Ok ( scalar) ,
1142
+ Value :: Scalar ( scalar) => scalar. unwrap_or_err ( ) ,
1143
1143
1144
1144
Value :: ScalarPair ( ..) => bug ! ( "value_to_scalar can't work with fat pointers" ) ,
1145
1145
}
@@ -1179,7 +1179,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1179
1179
match dest {
1180
1180
Place :: Ptr { ptr, align, extra } => {
1181
1181
assert_eq ! ( extra, PlaceExtra :: None ) ;
1182
- self . write_value_to_ptr ( src_val, ptr. read ( ) ?, align, dest_ty)
1182
+ self . write_value_to_ptr ( src_val, ptr. unwrap_or_err ( ) ?, align, dest_ty)
1183
1183
}
1184
1184
1185
1185
Place :: Local { frame, local } => {
@@ -1288,37 +1288,6 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1288
1288
}
1289
1289
}
1290
1290
1291
- pub ( crate ) fn read_ptr (
1292
- & self ,
1293
- ptr : Pointer ,
1294
- ptr_align : Align ,
1295
- pointee_ty : Ty < ' tcx > ,
1296
- ) -> EvalResult < ' tcx , Value > {
1297
- let ptr_size = self . memory . pointer_size ( ) ;
1298
- let p: ScalarMaybeUndef = self . memory . read_ptr_sized ( ptr, ptr_align) ?;
1299
- if self . type_is_sized ( pointee_ty) {
1300
- Ok ( Value :: Scalar ( p) )
1301
- } else {
1302
- trace ! ( "reading fat pointer extra of type {}" , pointee_ty) ;
1303
- let extra = ptr. offset ( ptr_size, self ) ?;
1304
- match self . tcx . struct_tail ( pointee_ty) . sty {
1305
- ty:: TyDynamic ( ..) => Ok ( Value :: ScalarPair (
1306
- p,
1307
- self . memory . read_ptr_sized ( extra, ptr_align) ?,
1308
- ) ) ,
1309
- ty:: TySlice ( ..) | ty:: TyStr => {
1310
- let len = self
1311
- . memory
1312
- . read_ptr_sized ( extra, ptr_align) ?
1313
- . read ( ) ?
1314
- . to_bits ( ptr_size) ?;
1315
- Ok ( p. to_value_with_len ( len as u64 , self . tcx . tcx ) )
1316
- } ,
1317
- _ => bug ! ( "unsized scalar ptr read from {:?}" , pointee_ty) ,
1318
- }
1319
- }
1320
- }
1321
-
1322
1291
fn validate_scalar (
1323
1292
& self ,
1324
1293
value : Scalar ,
@@ -1330,8 +1299,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1330
1299
trace ! ( "validate scalar: {:#?}, {:#?}, {:#?}, {}" , value, size, scalar, ty) ;
1331
1300
let ( lo, hi) = scalar. valid_range . clone ( ) . into_inner ( ) ;
1332
1301
1333
- let ( bits, defined) = match value {
1334
- Scalar :: Bits { bits, defined } => ( bits, defined) ,
1302
+ let bits = match value {
1303
+ Scalar :: Bits { bits, size : value_size } => {
1304
+ assert_eq ! ( value_size as u64 , size. bytes( ) ) ;
1305
+ bits
1306
+ } ,
1335
1307
Scalar :: Ptr ( _) => {
1336
1308
let ptr_size = self . memory . pointer_size ( ) ;
1337
1309
let ptr_max = u128:: max_value ( ) >> ( 128 - ptr_size. bits ( ) ) ;
@@ -1374,30 +1346,16 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1374
1346
}
1375
1347
1376
1348
use std:: ops:: RangeInclusive ;
1377
- let in_range = |bound : RangeInclusive < u128 > | {
1378
- defined as u64 >= size. bits ( ) && bound. contains ( & bits)
1379
- } ;
1349
+ let in_range = |bound : RangeInclusive < u128 > | bound. contains ( & bits) ;
1380
1350
if lo > hi {
1381
1351
if in_range ( 0 ..=hi) || in_range ( lo..=u128:: max_value ( ) ) {
1382
1352
Ok ( ( ) )
1383
- } else if defined as u64 >= size. bits ( ) {
1384
- validation_failure ! (
1385
- bits,
1386
- path,
1387
- format!( "something in the range {:?} or {:?}" , ..=hi, lo..)
1388
- )
1389
1353
} else {
1390
1354
validation_failure ! ( "undefined bytes" , path)
1391
1355
}
1392
1356
} else {
1393
1357
if in_range ( scalar. valid_range . clone ( ) ) {
1394
1358
Ok ( ( ) )
1395
- } else if defined as u64 >= size. bits ( ) {
1396
- validation_failure ! (
1397
- bits,
1398
- path,
1399
- format!( "something in the range {:?}" , scalar. valid_range)
1400
- )
1401
1359
} else {
1402
1360
validation_failure ! ( "undefined bytes" , path)
1403
1361
}
@@ -1455,7 +1413,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1455
1413
// expectation.
1456
1414
layout:: Abi :: Scalar ( ref scalar) => {
1457
1415
let size = scalar. value . size ( self ) ;
1458
- let value = self . memory . read_scalar ( ptr, ptr_align, size) ?;
1416
+ let value = self . memory . read_scalar ( ptr, ptr_align, size) ?. unwrap_or_err ( ) ? ;
1459
1417
self . validate_scalar ( value, size, scalar, & path, layout. ty ) ?;
1460
1418
if scalar. value == Primitive :: Pointer {
1461
1419
// ignore integer pointers, we can't reason about the final hardware
@@ -1538,7 +1496,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1538
1496
}
1539
1497
}
1540
1498
1541
- pub fn try_read_by_ref ( & mut self , mut val : Value , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , Value > {
1499
+ pub fn try_read_by_ref ( & self , mut val : Value , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , Value > {
1542
1500
// Convert to ByVal or ScalarPair if possible
1543
1501
if let Value :: ByRef ( ptr, align) = val {
1544
1502
if let Some ( read_val) = self . try_read_value ( ptr, align, ty) ? {
@@ -1548,7 +1506,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1548
1506
Ok ( val)
1549
1507
}
1550
1508
1551
- pub fn try_read_value ( & mut self , ptr : Scalar , ptr_align : Align , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , Option < Value > > {
1509
+ pub fn try_read_value ( & self , ptr : Scalar , ptr_align : Align , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , Option < Value > > {
1552
1510
let mut layout = self . layout_of ( ty) ?;
1553
1511
self . memory . check_align ( ptr, ptr_align) ?;
1554
1512
@@ -1563,9 +1521,9 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1563
1521
layout:: Variants :: Tagged { .. } => {
1564
1522
let variant_index = self . read_discriminant_as_variant_index (
1565
1523
Place :: from_ptr ( ptr, ptr_align) ,
1566
- layout. ty ,
1524
+ layout,
1567
1525
) ?;
1568
- layout = layout. for_variant ( & self , variant_index) ;
1526
+ layout = layout. for_variant ( self , variant_index) ;
1569
1527
trace ! ( "variant layout: {:#?}" , layout) ;
1570
1528
} ,
1571
1529
layout:: Variants :: Single { .. } => { } ,
@@ -1578,10 +1536,10 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1578
1536
}
1579
1537
layout:: Abi :: ScalarPair ( ref a, ref b) => {
1580
1538
let ( a, b) = ( & a. value , & b. value ) ;
1581
- let ( a_size, b_size) = ( a. size ( & self ) , b. size ( & self ) ) ;
1539
+ let ( a_size, b_size) = ( a. size ( self ) , b. size ( self ) ) ;
1582
1540
let a_ptr = ptr;
1583
- let b_offset = a_size. abi_align ( b. align ( & self ) ) ;
1584
- let b_ptr = ptr. offset ( b_offset, & self ) ?. into ( ) ;
1541
+ let b_offset = a_size. abi_align ( b. align ( self ) ) ;
1542
+ let b_ptr = ptr. offset ( b_offset, self ) ?. into ( ) ;
1585
1543
let a_val = self . memory . read_scalar ( a_ptr, ptr_align, a_size) ?;
1586
1544
let b_val = self . memory . read_scalar ( b_ptr, ptr_align, b_size) ?;
1587
1545
Ok ( Some ( Value :: ScalarPair ( a_val, b_val) ) )
@@ -1929,7 +1887,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
1929
1887
ScalarMaybeUndef :: Undef ,
1930
1888
ScalarMaybeUndef :: Undef ,
1931
1889
) ,
1932
- _ => Value :: ByRef ( self . alloc_ptr ( ty ) ?. into ( ) , layout. align ) ,
1890
+ _ => Value :: ByRef ( self . alloc_ptr ( layout ) ?. into ( ) , layout. align ) ,
1933
1891
} )
1934
1892
}
1935
1893
}
0 commit comments