@@ -7,25 +7,10 @@ use rustc_target::abi::HasDataLayout;
7
7
8
8
use crate :: * ;
9
9
10
- // pub trait HasUnderlyingPointer {
11
- // fn get_underlying_raw_ptr(&self) -> *const u8;
12
- // }
13
-
14
- // impl HasUnderlyingPointer for Allocation {
15
- // fn get_underlying_raw_ptr(&self) -> *const u8 {
16
-
17
- // }
18
- // }
19
-
20
10
impl < ' mir , ' tcx : ' mir > EvalContextExt < ' mir , ' tcx > for crate :: MiriEvalContext < ' mir , ' tcx > { }
21
11
22
12
pub trait EvalContextExt < ' mir , ' tcx : ' mir > : crate :: MiriEvalContextExt < ' mir , ' tcx > {
23
13
24
- // fn get_allocation_for_id(&self, id: AllocId) -> InterpResult<'tcx, &Allocation<Provenance, AllocExtra>> {
25
- // let this = self.eval_context_ref();
26
- // this.get_alloc_raw(id)
27
- // }
28
-
29
14
/// Extract the scalar value from the result of reading a scalar from the machine,
30
15
/// and convert it to a `CArg`.
31
16
fn scalar_to_carg (
@@ -69,16 +54,71 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
69
54
return Ok ( CArg :: USize ( k. to_machine_usize ( cx) ?. try_into ( ) . unwrap ( ) ) ) ;
70
55
}
71
56
// pointers
72
- TyKind :: RawPtr ( TypeAndMut { .. } ) => {
57
+ TyKind :: RawPtr ( TypeAndMut { ty : some_ty , mutbl : some_mut } ) => {
73
58
match k {
74
- ScalarMaybeUninit :: Scalar ( Scalar :: Ptr ( ptr, sz ) ) => {
59
+ ScalarMaybeUninit :: Scalar ( Scalar :: Ptr ( ptr, _ ) ) => {
75
60
let qq = ptr. into_parts ( ) . 1 . bytes_usize ( ) ;
76
- // TODO select correct types rather than yoloing
77
- return Ok ( CArg :: RecConstPtrCarg ( Box :: new ( CArg :: ConstPtrInt32 ( qq as * const i32 ) ) ) )
61
+ match ( some_ty. kind ( ) , some_mut) {
62
+ // int
63
+ ( TyKind :: Int ( IntTy :: I8 ) , rustc_hir:: Mutability :: Mut ) => {
64
+ return Ok ( CArg :: MutPtrInt8 ( qq as * mut i8 ) ) ;
65
+ } ,
66
+ ( TyKind :: Int ( IntTy :: I8 ) , rustc_hir:: Mutability :: Not ) => {
67
+ return Ok ( CArg :: ConstPtrInt8 ( qq as * const i8 ) ) ;
68
+ } ,
69
+ ( TyKind :: Int ( IntTy :: I16 ) , rustc_hir:: Mutability :: Mut ) => {
70
+ return Ok ( CArg :: MutPtrInt16 ( qq as * mut i16 ) ) ;
71
+ } ,
72
+ ( TyKind :: Int ( IntTy :: I16 ) , rustc_hir:: Mutability :: Not ) => {
73
+ return Ok ( CArg :: ConstPtrInt16 ( qq as * const i16 ) ) ;
74
+ } ,
75
+ ( TyKind :: Int ( IntTy :: I32 ) , rustc_hir:: Mutability :: Mut ) => {
76
+ return Ok ( CArg :: MutPtrInt32 ( qq as * mut i32 ) ) ;
77
+ } ,
78
+ ( TyKind :: Int ( IntTy :: I32 ) , rustc_hir:: Mutability :: Not ) => {
79
+ return Ok ( CArg :: ConstPtrInt32 ( qq as * const i32 ) ) ;
80
+ } ,
81
+ ( TyKind :: Int ( IntTy :: I64 ) , rustc_hir:: Mutability :: Mut ) => {
82
+ return Ok ( CArg :: MutPtrInt64 ( qq as * mut i64 ) ) ;
83
+ } ,
84
+ ( TyKind :: Int ( IntTy :: I64 ) , rustc_hir:: Mutability :: Not ) => {
85
+ return Ok ( CArg :: ConstPtrInt64 ( qq as * const i64 ) ) ;
86
+ } ,
87
+ // uints
88
+ ( TyKind :: Uint ( UintTy :: U8 ) , rustc_hir:: Mutability :: Mut ) => {
89
+ return Ok ( CArg :: MutPtrUInt8 ( qq as * mut u8 ) ) ;
90
+ } ,
91
+ ( TyKind :: Uint ( UintTy :: U8 ) , rustc_hir:: Mutability :: Not ) => {
92
+ return Ok ( CArg :: ConstPtrUInt8 ( qq as * const u8 ) ) ;
93
+ } ,
94
+ ( TyKind :: Uint ( UintTy :: U16 ) , rustc_hir:: Mutability :: Mut ) => {
95
+ return Ok ( CArg :: MutPtrUInt16 ( qq as * mut u16 ) ) ;
96
+ } ,
97
+ ( TyKind :: Uint ( UintTy :: U16 ) , rustc_hir:: Mutability :: Not ) => {
98
+ return Ok ( CArg :: ConstPtrUInt16 ( qq as * const u16 ) ) ;
99
+ } ,
100
+ ( TyKind :: Uint ( UintTy :: U32 ) , rustc_hir:: Mutability :: Mut ) => {
101
+ return Ok ( CArg :: MutPtrUInt32 ( qq as * mut u32 ) ) ;
102
+ } ,
103
+ ( TyKind :: Uint ( UintTy :: U32 ) , rustc_hir:: Mutability :: Not ) => {
104
+ return Ok ( CArg :: ConstPtrUInt32 ( qq as * const u32 ) ) ;
105
+ } ,
106
+ ( TyKind :: Uint ( UintTy :: U64 ) , rustc_hir:: Mutability :: Mut ) => {
107
+ return Ok ( CArg :: MutPtrUInt64 ( qq as * mut u64 ) ) ;
108
+ } ,
109
+ ( TyKind :: Uint ( UintTy :: U64 ) , rustc_hir:: Mutability :: Not ) => {
110
+ return Ok ( CArg :: ConstPtrUInt64 ( qq as * const u64 ) ) ;
111
+ } ,
112
+ // recursive case
113
+ ( TyKind :: RawPtr ( ..) , _) => {
114
+ return Ok ( CArg :: RecCarg ( Box :: new ( Self :: scalar_to_carg ( k, some_ty, cx) ?) ) ) ;
115
+ }
116
+ _ => { }
117
+ }
78
118
}
79
119
_ => { }
80
120
}
81
- }
121
+ } ,
82
122
_ => { }
83
123
}
84
124
// If no primitives were returned then we have an unsupported type.
@@ -321,9 +361,8 @@ pub enum CArg {
321
361
ConstPtrUInt16 ( * const u16 ) ,
322
362
ConstPtrUInt32 ( * const u32 ) ,
323
363
ConstPtrUInt64 ( * const u64 ) ,
324
- // recursive
325
- RecConstPtrCarg ( Box < CArg > ) ,
326
- RecMutPtrCarg ( Box < CArg > ) ,
364
+ /// Recursive `CArg` (for nested pointers).
365
+ RecCarg ( Box < CArg > ) ,
327
366
}
328
367
329
368
impl < ' a > CArg {
@@ -356,8 +395,7 @@ impl<'a> CArg {
356
395
CArg :: ConstPtrUInt16 ( i) => arg ( i) ,
357
396
CArg :: ConstPtrUInt32 ( i) => arg ( i) ,
358
397
CArg :: ConstPtrUInt64 ( i) => arg ( i) ,
359
- CArg :: RecConstPtrCarg ( box_carg) => ( * box_carg) . arg_downcast ( ) ,
360
- CArg :: RecMutPtrCarg ( box_carg) => ( * box_carg) . arg_downcast ( ) ,
398
+ CArg :: RecCarg ( box_carg) => ( * box_carg) . arg_downcast ( ) ,
361
399
}
362
400
}
363
401
}
0 commit comments