@@ -16,14 +16,14 @@ use super::{
16
16
17
17
use tls:: MemoryExt ;
18
18
19
- use super :: memory:: Kind ;
19
+ use super :: memory:: MemoryKind ;
20
20
21
21
pub trait EvalContextExt < ' tcx > {
22
22
fn call_c_abi (
23
23
& mut self ,
24
24
def_id : DefId ,
25
25
arg_operands : & [ mir:: Operand < ' tcx > ] ,
26
- dest : Lvalue < ' tcx > ,
26
+ dest : Lvalue ,
27
27
dest_ty : Ty < ' tcx > ,
28
28
dest_block : mir:: BasicBlock ,
29
29
) -> EvalResult < ' tcx > ;
@@ -33,7 +33,7 @@ pub trait EvalContextExt<'tcx> {
33
33
fn call_missing_fn (
34
34
& mut self ,
35
35
instance : ty:: Instance < ' tcx > ,
36
- destination : Option < ( Lvalue < ' tcx > , mir:: BasicBlock ) > ,
36
+ destination : Option < ( Lvalue , mir:: BasicBlock ) > ,
37
37
arg_operands : & [ mir:: Operand < ' tcx > ] ,
38
38
sig : ty:: FnSig < ' tcx > ,
39
39
path : String ,
@@ -42,7 +42,7 @@ pub trait EvalContextExt<'tcx> {
42
42
fn eval_fn_call (
43
43
& mut self ,
44
44
instance : ty:: Instance < ' tcx > ,
45
- destination : Option < ( Lvalue < ' tcx > , mir:: BasicBlock ) > ,
45
+ destination : Option < ( Lvalue , mir:: BasicBlock ) > ,
46
46
arg_operands : & [ mir:: Operand < ' tcx > ] ,
47
47
span : Span ,
48
48
sig : ty:: FnSig < ' tcx > ,
@@ -53,7 +53,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
53
53
fn eval_fn_call (
54
54
& mut self ,
55
55
instance : ty:: Instance < ' tcx > ,
56
- destination : Option < ( Lvalue < ' tcx > , mir:: BasicBlock ) > ,
56
+ destination : Option < ( Lvalue , mir:: BasicBlock ) > ,
57
57
arg_operands : & [ mir:: Operand < ' tcx > ] ,
58
58
span : Span ,
59
59
sig : ty:: FnSig < ' tcx > ,
@@ -89,7 +89,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
89
89
& mut self ,
90
90
def_id : DefId ,
91
91
arg_operands : & [ mir:: Operand < ' tcx > ] ,
92
- dest : Lvalue < ' tcx > ,
92
+ dest : Lvalue ,
93
93
dest_ty : Ty < ' tcx > ,
94
94
dest_block : mir:: BasicBlock ,
95
95
) -> EvalResult < ' tcx > {
@@ -113,15 +113,15 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
113
113
self . write_null ( dest, dest_ty) ?;
114
114
} else {
115
115
let align = self . memory . pointer_size ( ) ;
116
- let ptr = self . memory . allocate ( size, align, Kind :: C . into ( ) ) ?;
116
+ let ptr = self . memory . allocate ( size, align, MemoryKind :: C . into ( ) ) ?;
117
117
self . write_primval ( dest, PrimVal :: Ptr ( ptr) , dest_ty) ?;
118
118
}
119
119
}
120
120
121
121
"free" => {
122
122
let ptr = args[ 0 ] . into_ptr ( & mut self . memory ) ?;
123
123
if !ptr. is_null ( ) ? {
124
- self . memory . deallocate ( ptr. to_ptr ( ) ?, None , Kind :: C . into ( ) ) ?;
124
+ self . memory . deallocate ( ptr. to_ptr ( ) ?, None , MemoryKind :: C . into ( ) ) ?;
125
125
}
126
126
}
127
127
@@ -251,7 +251,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
251
251
}
252
252
if let Some ( old) = success {
253
253
if let Some ( var) = old {
254
- self . memory . deallocate ( var, None , Kind :: Env . into ( ) ) ?;
254
+ self . memory . deallocate ( var, None , MemoryKind :: Env . into ( ) ) ?;
255
255
}
256
256
self . write_null ( dest, dest_ty) ?;
257
257
} else {
@@ -274,12 +274,12 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
274
274
}
275
275
if let Some ( ( name, value) ) = new {
276
276
// +1 for the null terminator
277
- let value_copy = self . memory . allocate ( ( value. len ( ) + 1 ) as u64 , 1 , Kind :: Env . into ( ) ) ?;
277
+ let value_copy = self . memory . allocate ( ( value. len ( ) + 1 ) as u64 , 1 , MemoryKind :: Env . into ( ) ) ?;
278
278
self . memory . write_bytes ( value_copy. into ( ) , & value) ?;
279
279
let trailing_zero_ptr = value_copy. offset ( value. len ( ) as u64 , & self ) ?. into ( ) ;
280
280
self . memory . write_bytes ( trailing_zero_ptr, & [ 0 ] ) ?;
281
281
if let Some ( var) = self . machine_data . env_vars . insert ( name. to_owned ( ) , value_copy) {
282
- self . memory . deallocate ( var, None , Kind :: Env . into ( ) ) ?;
282
+ self . memory . deallocate ( var, None , MemoryKind :: Env . into ( ) ) ?;
283
283
}
284
284
self . write_null ( dest, dest_ty) ?;
285
285
} else {
@@ -317,7 +317,8 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
317
317
}
318
318
319
319
"sysconf" => {
320
- let name = self . value_to_primval ( args[ 0 ] , usize) ?. to_u64 ( ) ?;
320
+ let c_int = self . operand_ty ( & arg_operands[ 0 ] ) ;
321
+ let name = self . value_to_primval ( args[ 0 ] , c_int) ?. to_u64 ( ) ?;
321
322
trace ! ( "sysconf() called with name {}" , name) ;
322
323
// cache the sysconf integers via miri's global cache
323
324
let paths = & [
@@ -329,8 +330,8 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
329
330
if let Ok ( instance) = self . resolve_path ( path) {
330
331
let cid = GlobalId { instance, promoted : None } ;
331
332
// compute global if not cached
332
- let val = match self . globals . get ( & cid) . map ( |glob| glob . value ) {
333
- Some ( value ) => self . value_to_primval ( value , usize ) ?. to_u64 ( ) ?,
333
+ let val = match self . globals . get ( & cid) . cloned ( ) {
334
+ Some ( ptr ) => self . value_to_primval ( Value :: ByRef ( ptr ) , c_int ) ?. to_u64 ( ) ?,
334
335
None => eval_body_as_primval ( self . tcx , instance) ?. 0 . to_u64 ( ) ?,
335
336
} ;
336
337
if val == name {
@@ -459,7 +460,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
459
460
fn call_missing_fn (
460
461
& mut self ,
461
462
instance : ty:: Instance < ' tcx > ,
462
- destination : Option < ( Lvalue < ' tcx > , mir:: BasicBlock ) > ,
463
+ destination : Option < ( Lvalue , mir:: BasicBlock ) > ,
463
464
arg_operands : & [ mir:: Operand < ' tcx > ] ,
464
465
sig : ty:: FnSig < ' tcx > ,
465
466
path : String ,
@@ -500,7 +501,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
500
501
if !align. is_power_of_two ( ) {
501
502
return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
502
503
}
503
- let ptr = self . memory . allocate ( size, align, Kind :: Rust . into ( ) ) ?;
504
+ let ptr = self . memory . allocate ( size, align, MemoryKind :: Rust . into ( ) ) ?;
504
505
self . write_primval ( dest, PrimVal :: Ptr ( ptr) , dest_ty) ?;
505
506
}
506
507
"alloc::heap::::__rust_alloc_zeroed" => {
@@ -512,7 +513,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
512
513
if !align. is_power_of_two ( ) {
513
514
return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
514
515
}
515
- let ptr = self . memory . allocate ( size, align, Kind :: Rust . into ( ) ) ?;
516
+ let ptr = self . memory . allocate ( size, align, MemoryKind :: Rust . into ( ) ) ?;
516
517
self . memory . write_repeat ( ptr. into ( ) , 0 , size) ?;
517
518
self . write_primval ( dest, PrimVal :: Ptr ( ptr) , dest_ty) ?;
518
519
}
@@ -526,7 +527,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
526
527
if !align. is_power_of_two ( ) {
527
528
return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
528
529
}
529
- self . memory . deallocate ( ptr, Some ( ( old_size, align) ) , Kind :: Rust . into ( ) ) ?;
530
+ self . memory . deallocate ( ptr, Some ( ( old_size, align) ) , MemoryKind :: Rust . into ( ) ) ?;
530
531
}
531
532
"alloc::heap::::__rust_realloc" => {
532
533
let ptr = args[ 0 ] . into_ptr ( & mut self . memory ) ?. to_ptr ( ) ?;
@@ -543,7 +544,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
543
544
if !new_align. is_power_of_two ( ) {
544
545
return err ! ( HeapAllocNonPowerOfTwoAlignment ( new_align) ) ;
545
546
}
546
- let new_ptr = self . memory . reallocate ( ptr, old_size, old_align, new_size, new_align, Kind :: Rust . into ( ) ) ?;
547
+ let new_ptr = self . memory . reallocate ( ptr, old_size, old_align, new_size, new_align, MemoryKind :: Rust . into ( ) ) ?;
547
548
self . write_primval ( dest, PrimVal :: Ptr ( new_ptr) , dest_ty) ?;
548
549
}
549
550
0 commit comments