11use std:: time:: SystemTime ;
22
3+ use rustc_hir:: LangItem ;
4+ use rustc_middle:: ty:: { layout:: TyAndLayout , query:: TyCtxtAt , subst:: Subst , Ty } ;
5+
36use crate :: * ;
47use thread:: Time ;
58
@@ -44,7 +47,7 @@ fn mutexattr_set_kind<'mir, 'tcx: 'mir>(
4447 attr_op : & OpTy < ' tcx , Tag > ,
4548 kind : impl Into < ScalarMaybeUninit < Tag > > ,
4649) -> 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 ) )
4851}
4952
5053// pthread_mutex_t is between 24 and 48 bytes, depending on the platform.
@@ -79,7 +82,7 @@ fn mutex_set_kind<'mir, 'tcx: 'mir>(
7982 mutex_op,
8083 offset,
8184 kind,
82- ecx. machine . layouts . i32 ,
85+ layout_of_maybe_uninit ( ecx. tcx , ecx . tcx . types . i32 ) ,
8386 AtomicWriteOp :: Relaxed ,
8487 )
8588}
@@ -100,7 +103,7 @@ fn mutex_set_id<'mir, 'tcx: 'mir>(
100103 mutex_op,
101104 4 ,
102105 id,
103- ecx. machine . layouts . u32 ,
106+ layout_of_maybe_uninit ( ecx. tcx , ecx . tcx . types . u32 ) ,
104107 AtomicWriteOp :: Relaxed ,
105108 )
106109}
@@ -144,7 +147,7 @@ fn rwlock_set_id<'mir, 'tcx: 'mir>(
144147 rwlock_op,
145148 4 ,
146149 id,
147- ecx. machine . layouts . u32 ,
150+ layout_of_maybe_uninit ( ecx. tcx , ecx . tcx . types . u32 ) ,
148151 AtomicWriteOp :: Relaxed ,
149152 )
150153}
@@ -211,7 +214,7 @@ fn cond_set_id<'mir, 'tcx: 'mir>(
211214 cond_op,
212215 4 ,
213216 id,
214- ecx. machine . layouts . u32 ,
217+ layout_of_maybe_uninit ( ecx. tcx , ecx . tcx . types . u32 ) ,
215218 AtomicWriteOp :: Relaxed ,
216219 )
217220}
@@ -244,7 +247,12 @@ fn cond_set_clock_id<'mir, 'tcx: 'mir>(
244247 cond_op : & OpTy < ' tcx , Tag > ,
245248 clock_id : impl Into < ScalarMaybeUninit < Tag > > ,
246249) -> 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+ )
248256}
249257
250258/// 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
788796 Ok ( 0 )
789797 }
790798}
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