1
1
use std:: time:: SystemTime ;
2
2
3
+ use rustc_hir:: LangItem ;
4
+ use rustc_middle:: ty:: { layout:: TyAndLayout , query:: TyCtxtAt , subst:: Subst , Ty } ;
5
+
3
6
use crate :: * ;
4
7
use thread:: Time ;
5
8
@@ -44,7 +47,7 @@ fn mutexattr_set_kind<'mir, 'tcx: 'mir>(
44
47
attr_op : & OpTy < ' tcx , Tag > ,
45
48
kind : impl Into < ScalarMaybeUninit < Tag > > ,
46
49
) -> InterpResult < ' tcx , ( ) > {
47
- ecx. write_scalar_at_offset ( attr_op, 0 , kind, ecx. machine . layouts . i32 )
50
+ ecx. write_scalar_at_offset ( attr_op, 0 , kind, layout_of_maybe_uninit ( ecx. tcx , ecx . tcx . types . i32 ) )
48
51
}
49
52
50
53
// pthread_mutex_t is between 24 and 48 bytes, depending on the platform.
@@ -79,7 +82,7 @@ fn mutex_set_kind<'mir, 'tcx: 'mir>(
79
82
mutex_op,
80
83
offset,
81
84
kind,
82
- ecx. machine . layouts . i32 ,
85
+ layout_of_maybe_uninit ( ecx. tcx , ecx . tcx . types . i32 ) ,
83
86
AtomicWriteOp :: Relaxed ,
84
87
)
85
88
}
@@ -100,7 +103,7 @@ fn mutex_set_id<'mir, 'tcx: 'mir>(
100
103
mutex_op,
101
104
4 ,
102
105
id,
103
- ecx. machine . layouts . u32 ,
106
+ layout_of_maybe_uninit ( ecx. tcx , ecx . tcx . types . u32 ) ,
104
107
AtomicWriteOp :: Relaxed ,
105
108
)
106
109
}
@@ -144,7 +147,7 @@ fn rwlock_set_id<'mir, 'tcx: 'mir>(
144
147
rwlock_op,
145
148
4 ,
146
149
id,
147
- ecx. machine . layouts . u32 ,
150
+ layout_of_maybe_uninit ( ecx. tcx , ecx . tcx . types . u32 ) ,
148
151
AtomicWriteOp :: Relaxed ,
149
152
)
150
153
}
@@ -211,7 +214,7 @@ fn cond_set_id<'mir, 'tcx: 'mir>(
211
214
cond_op,
212
215
4 ,
213
216
id,
214
- ecx. machine . layouts . u32 ,
217
+ layout_of_maybe_uninit ( ecx. tcx , ecx . tcx . types . u32 ) ,
215
218
AtomicWriteOp :: Relaxed ,
216
219
)
217
220
}
@@ -244,7 +247,12 @@ fn cond_set_clock_id<'mir, 'tcx: 'mir>(
244
247
cond_op : & OpTy < ' tcx , Tag > ,
245
248
clock_id : impl Into < ScalarMaybeUninit < Tag > > ,
246
249
) -> InterpResult < ' tcx , ( ) > {
247
- ecx. write_scalar_at_offset ( cond_op, 8 , clock_id, ecx. machine . layouts . i32 )
250
+ ecx. write_scalar_at_offset (
251
+ cond_op,
252
+ 8 ,
253
+ clock_id,
254
+ layout_of_maybe_uninit ( ecx. tcx , ecx. tcx . types . i32 ) ,
255
+ )
248
256
}
249
257
250
258
/// Try to reacquire the mutex associated with the condition variable after we
@@ -788,3 +796,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
788
796
Ok ( 0 )
789
797
}
790
798
}
799
+
800
+ fn layout_of_maybe_uninit < ' tcx > ( tcx : TyCtxtAt < ' tcx > , param : Ty < ' tcx > ) -> TyAndLayout < ' tcx > {
801
+ let def_id = tcx. require_lang_item ( LangItem :: MaybeUninit , None ) ;
802
+ let def_ty = tcx. type_of ( def_id) ;
803
+ let ty = def_ty. subst ( * tcx, & [ param. into ( ) ] ) ;
804
+
805
+ let param_env = tcx. param_env ( def_id) ;
806
+ tcx. layout_of ( param_env. and ( ty) ) . unwrap ( )
807
+ }
0 commit comments