@@ -167,7 +167,7 @@ pub enum StackPopCleanup {
167
167
}
168
168
169
169
impl < ' a , ' tcx > EvalContext < ' a , ' tcx > {
170
- pub fn new ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , memory_size : usize , stack_limit : usize , step_limit : u64 ) -> Self {
170
+ pub fn new ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , memory_size : u64 , stack_limit : usize , step_limit : u64 ) -> Self {
171
171
EvalContext {
172
172
tcx : tcx,
173
173
memory : Memory :: new ( & tcx. data_layout , memory_size) ,
@@ -211,7 +211,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
211
211
212
212
fn str_to_value ( & mut self , s : & str ) -> EvalResult < ' tcx , Value > {
213
213
// FIXME: cache these allocs
214
- let ptr = self . memory . allocate ( s. len ( ) , 1 ) ?;
214
+ let ptr = self . memory . allocate ( s. len ( ) as u64 , 1 ) ?;
215
215
self . memory . write_bytes ( ptr, s. as_bytes ( ) ) ?;
216
216
self . memory . freeze ( ptr. alloc_id ) ?;
217
217
Ok ( Value :: ByValPair ( PrimVal :: from_ptr ( ptr) , self . usize_primval ( s. len ( ) as u64 ) ) )
@@ -255,7 +255,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
255
255
Str ( ref s) => return self . str_to_value ( s) ,
256
256
257
257
ByteStr ( ref bs) => {
258
- let ptr = self . memory . allocate ( bs. len ( ) , 1 ) ?;
258
+ let ptr = self . memory . allocate ( bs. len ( ) as u64 , 1 ) ?;
259
259
self . memory . write_bytes ( ptr, bs) ?;
260
260
self . memory . freeze ( ptr. alloc_id ) ?;
261
261
PrimVal :: from_ptr ( ptr)
@@ -292,25 +292,25 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
292
292
self . tcx . normalize_associated_type ( & substituted)
293
293
}
294
294
295
- fn type_size ( & self , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , Option < usize > > {
295
+ fn type_size ( & self , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , Option < u64 > > {
296
296
self . type_size_with_substs ( ty, self . substs ( ) )
297
297
}
298
298
299
- fn type_align ( & self , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , usize > {
299
+ fn type_align ( & self , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , u64 > {
300
300
self . type_align_with_substs ( ty, self . substs ( ) )
301
301
}
302
302
303
- fn type_size_with_substs ( & self , ty : Ty < ' tcx > , substs : & ' tcx Substs < ' tcx > ) -> EvalResult < ' tcx , Option < usize > > {
303
+ fn type_size_with_substs ( & self , ty : Ty < ' tcx > , substs : & ' tcx Substs < ' tcx > ) -> EvalResult < ' tcx , Option < u64 > > {
304
304
let layout = self . type_layout_with_substs ( ty, substs) ?;
305
305
if layout. is_unsized ( ) {
306
306
Ok ( None )
307
307
} else {
308
- Ok ( Some ( layout. size ( & self . tcx . data_layout ) . bytes ( ) as usize ) )
308
+ Ok ( Some ( layout. size ( & self . tcx . data_layout ) . bytes ( ) ) )
309
309
}
310
310
}
311
311
312
- fn type_align_with_substs ( & self , ty : Ty < ' tcx > , substs : & ' tcx Substs < ' tcx > ) -> EvalResult < ' tcx , usize > {
313
- self . type_layout_with_substs ( ty, substs) . map ( |layout| layout. align ( & self . tcx . data_layout ) . abi ( ) as usize )
312
+ fn type_align_with_substs ( & self , ty : Ty < ' tcx > , substs : & ' tcx Substs < ' tcx > ) -> EvalResult < ' tcx , u64 > {
313
+ self . type_layout_with_substs ( ty, substs) . map ( |layout| layout. align ( & self . tcx . data_layout ) . abi ( ) )
314
314
}
315
315
316
316
fn type_layout ( & self , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , & ' tcx Layout > {
@@ -464,7 +464,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
464
464
for ( offset, operand) in offsets. into_iter ( ) . zip ( operands) {
465
465
let value = self . eval_operand ( operand) ?;
466
466
let value_ty = self . operand_ty ( operand) ;
467
- let field_dest = dest. offset ( offset as isize ) ;
467
+ let field_dest = dest. offset ( offset) ;
468
468
self . write_value_to_ptr ( value, field_dest, value_ty) ?;
469
469
}
470
470
Ok ( ( ) )
@@ -525,8 +525,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
525
525
General { discr, ref variants, .. } => {
526
526
if let mir:: AggregateKind :: Adt ( adt_def, variant, _, _) = * kind {
527
527
let discr_val = adt_def. variants [ variant] . disr_val . to_u64_unchecked ( ) ;
528
- let discr_size = discr. size ( ) . bytes ( ) as usize ;
529
- let discr_offset = variants[ variant] . offsets [ 0 ] . bytes ( ) as isize ;
528
+ let discr_size = discr. size ( ) . bytes ( ) ;
529
+ let discr_offset = variants[ variant] . offsets [ 0 ] . bytes ( ) ;
530
530
531
531
// FIXME(solson)
532
532
let dest = self . force_allocation ( dest) ?;
@@ -581,7 +581,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
581
581
// FIXME(solson)
582
582
let dest = self . force_allocation ( dest) ?. to_ptr ( ) ;
583
583
584
- let dest = dest. offset ( offset. bytes ( ) as isize ) ;
584
+ let dest = dest. offset ( offset. bytes ( ) ) ;
585
585
let dest_size = self . type_size ( ty) ?. expect ( "bad StructWrappedNullablePointer discrfield" ) ;
586
586
try!( self . memory . write_int ( dest, 0 , dest_size) ) ;
587
587
}
@@ -594,7 +594,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
594
594
assert_eq ! ( operands. len( ) , 0 ) ;
595
595
if let mir:: AggregateKind :: Adt ( adt_def, variant, _, _) = * kind {
596
596
let n = adt_def. variants [ variant] . disr_val . to_u64_unchecked ( ) ;
597
- let size = discr. size ( ) . bytes ( ) as usize ;
597
+ let size = discr. size ( ) . bytes ( ) ;
598
598
599
599
let val = if signed {
600
600
PrimVal :: from_int_with_size ( n as i64 , size)
@@ -621,18 +621,18 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
621
621
622
622
Repeat ( ref operand, _) => {
623
623
let ( elem_ty, length) = match dest_ty. sty {
624
- ty:: TyArray ( elem_ty, n) => ( elem_ty, n) ,
624
+ ty:: TyArray ( elem_ty, n) => ( elem_ty, n as u64 ) ,
625
625
_ => bug ! ( "tried to assign array-repeat to non-array type {:?}" , dest_ty) ,
626
626
} ;
627
- self . inc_step_counter_and_check_limit ( length as u64 ) ?;
627
+ self . inc_step_counter_and_check_limit ( length) ?;
628
628
let elem_size = self . type_size ( elem_ty) ?. expect ( "repeat element type must be sized" ) ;
629
629
let value = self . eval_operand ( operand) ?;
630
630
631
631
// FIXME(solson)
632
632
let dest = self . force_allocation ( dest) ?. to_ptr ( ) ;
633
633
634
634
for i in 0 ..length {
635
- let elem_dest = dest. offset ( ( i * elem_size) as isize ) ;
635
+ let elem_dest = dest. offset ( i * elem_size) ;
636
636
self . write_value_to_ptr ( value, elem_dest, elem_ty) ?;
637
637
}
638
638
}
@@ -741,15 +741,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
741
741
}
742
742
743
743
fn nonnull_offset_and_ty ( & self , ty : Ty < ' tcx > , nndiscr : u64 , discrfield : & [ u32 ] ) -> EvalResult < ' tcx , ( Size , Ty < ' tcx > ) > {
744
- // Skip the constant 0 at the start meant for LLVM GEP.
745
- let mut path = discrfield. iter ( ) . skip ( 1 ) . map ( |& i| i as usize ) ;
744
+ // Skip the constant 0 at the start meant for LLVM GEP and the outer non-null variant
745
+ let path = discrfield. iter ( ) . skip ( 2 ) . map ( |& i| i as usize ) ;
746
746
747
747
// Handle the field index for the outer non-null variant.
748
748
let inner_ty = match ty. sty {
749
749
ty:: TyAdt ( adt_def, substs) => {
750
750
let variant = & adt_def. variants [ nndiscr as usize ] ;
751
- let index = path . next ( ) . unwrap ( ) ;
752
- let field = & variant. fields [ index] ;
751
+ let index = discrfield [ 1 ] ;
752
+ let field = & variant. fields [ index as usize ] ;
753
753
field. ty ( self . tcx , substs)
754
754
}
755
755
_ => bug ! ( "non-enum for StructWrappedNullablePointer: {}" , ty) ,
@@ -804,8 +804,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
804
804
Ok ( variant. offsets [ field_index] )
805
805
}
806
806
FatPointer { .. } => {
807
- let bytes = field_index * self . memory . pointer_size ( ) ;
808
- Ok ( Size :: from_bytes ( bytes as u64 ) )
807
+ let bytes = field_index as u64 * self . memory . pointer_size ( ) ;
808
+ Ok ( Size :: from_bytes ( bytes) )
809
809
}
810
810
_ => {
811
811
let msg = format ! ( "can't handle type: {:?}, with layout: {:?}" , ty, layout) ;
@@ -980,7 +980,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
980
980
_ => bug ! ( "field access on non-product type: {:?}" , base_layout) ,
981
981
} ;
982
982
983
- let ptr = base_ptr. offset ( offset. bytes ( ) as isize ) ;
983
+ let ptr = base_ptr. offset ( offset. bytes ( ) ) ;
984
984
let extra = if self . type_is_sized ( field_ty) {
985
985
LvalueExtra :: None
986
986
} else {
@@ -1048,7 +1048,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1048
1048
let n = self . value_to_primval ( n_ptr, usize) ?
1049
1049
. expect_uint ( "Projection::Index expected usize" ) ;
1050
1050
assert ! ( n < len) ;
1051
- let ptr = base_ptr. offset ( n as isize * elem_size as isize ) ;
1051
+ let ptr = base_ptr. offset ( n * elem_size) ;
1052
1052
( ptr, LvalueExtra :: None )
1053
1053
}
1054
1054
@@ -1062,12 +1062,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1062
1062
assert ! ( n >= min_length as u64 ) ;
1063
1063
1064
1064
let index = if from_end {
1065
- n as isize - offset as isize
1065
+ n - u64 :: from ( offset)
1066
1066
} else {
1067
- offset as isize
1067
+ u64 :: from ( offset)
1068
1068
} ;
1069
1069
1070
- let ptr = base_ptr. offset ( index * elem_size as isize ) ;
1070
+ let ptr = base_ptr. offset ( index * elem_size) ;
1071
1071
( ptr, LvalueExtra :: None )
1072
1072
}
1073
1073
@@ -1078,9 +1078,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1078
1078
1079
1079
let ( elem_ty, n) = base. elem_ty_and_len ( base_ty) ;
1080
1080
let elem_size = self . type_size ( elem_ty) ?. expect ( "slice element must be sized" ) ;
1081
- assert ! ( ( from as u64 ) <= n - ( to as u64 ) ) ;
1082
- let ptr = base_ptr. offset ( from as isize * elem_size as isize ) ;
1083
- let extra = LvalueExtra :: Length ( n - to as u64 - from as u64 ) ;
1081
+ assert ! ( u64 :: from ( from) <= n - u64 :: from ( to) ) ;
1082
+ let ptr = base_ptr. offset ( u64 :: from ( from ) * elem_size) ;
1083
+ let extra = LvalueExtra :: Length ( n - u64 :: from ( to ) - u64:: from ( from ) ) ;
1084
1084
( ptr, extra)
1085
1085
}
1086
1086
} ;
@@ -1318,8 +1318,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1318
1318
ty : Ty < ' tcx >
1319
1319
) -> EvalResult < ' tcx , ( ) > {
1320
1320
assert_eq ! ( self . get_field_count( ty) ?, 2 ) ;
1321
- let field_0 = self . get_field_offset ( ty, 0 ) ?. bytes ( ) as isize ;
1322
- let field_1 = self . get_field_offset ( ty, 1 ) ?. bytes ( ) as isize ;
1321
+ let field_0 = self . get_field_offset ( ty, 0 ) ?. bytes ( ) ;
1322
+ let field_1 = self . get_field_offset ( ty, 1 ) ?. bytes ( ) ;
1323
1323
self . memory . write_primval ( ptr. offset ( field_0) , a) ?;
1324
1324
self . memory . write_primval ( ptr. offset ( field_1) , b) ?;
1325
1325
Ok ( ( ) )
@@ -1368,7 +1368,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1368
1368
ty:: TyAdt ( ..) => {
1369
1369
use rustc:: ty:: layout:: Layout :: * ;
1370
1370
if let CEnum { discr, signed, .. } = * self . type_layout ( ty) ? {
1371
- let size = discr. size ( ) . bytes ( ) as usize ;
1371
+ let size = discr. size ( ) . bytes ( ) ;
1372
1372
if signed {
1373
1373
PrimValKind :: from_int_size ( size)
1374
1374
} else {
@@ -1450,7 +1450,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1450
1450
PrimVal :: from_ptr ( p)
1451
1451
} else {
1452
1452
trace ! ( "reading fat pointer extra of type {}" , ty) ;
1453
- let extra = ptr. offset ( self . memory . pointer_size ( ) as isize ) ;
1453
+ let extra = ptr. offset ( self . memory . pointer_size ( ) ) ;
1454
1454
let extra = match self . tcx . struct_tail ( ty) . sty {
1455
1455
ty:: TyTrait ( ..) => PrimVal :: from_ptr ( self . memory . read_ptr ( extra) ?) ,
1456
1456
ty:: TySlice ( ..) |
@@ -1464,7 +1464,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1464
1464
ty:: TyAdt ( ..) => {
1465
1465
use rustc:: ty:: layout:: Layout :: * ;
1466
1466
if let CEnum { discr, signed, .. } = * self . type_layout ( ty) ? {
1467
- let size = discr. size ( ) . bytes ( ) as usize ;
1467
+ let size = discr. size ( ) . bytes ( ) ;
1468
1468
if signed {
1469
1469
let n = self . memory . read_int ( ptr, size) ?;
1470
1470
PrimVal :: from_int_with_size ( n, size)
@@ -1566,8 +1566,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1566
1566
if self . type_size ( dst_fty) ? == Some ( 0 ) {
1567
1567
continue ;
1568
1568
}
1569
- let src_field_offset = self . get_field_offset ( src_ty, i) ?. bytes ( ) as isize ;
1570
- let dst_field_offset = self . get_field_offset ( dest_ty, i) ?. bytes ( ) as isize ;
1569
+ let src_field_offset = self . get_field_offset ( src_ty, i) ?. bytes ( ) ;
1570
+ let dst_field_offset = self . get_field_offset ( dest_ty, i) ?. bytes ( ) ;
1571
1571
let src_f_ptr = src_ptr. offset ( src_field_offset) ;
1572
1572
let dst_f_ptr = dest. offset ( dst_field_offset) ;
1573
1573
if src_fty == dst_fty {
@@ -1699,7 +1699,7 @@ impl<'tcx> Lvalue<'tcx> {
1699
1699
pub fn eval_main < ' a , ' tcx : ' a > (
1700
1700
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1701
1701
def_id : DefId ,
1702
- memory_size : usize ,
1702
+ memory_size : u64 ,
1703
1703
step_limit : u64 ,
1704
1704
stack_limit : usize ,
1705
1705
) {
0 commit comments