@@ -6,6 +6,7 @@ use rustc::{ty, ty::layout::HasDataLayout, mir};
66use crate :: {
77 InterpResult , InterpError , StackPopCleanup ,
88 MPlaceTy , Scalar , Tag ,
9+ HelpersEvalContextExt ,
910} ;
1011
1112pub type TlsKey = u128 ;
@@ -111,7 +112,6 @@ impl<'tcx> TlsData<'tcx> {
111112 fn fetch_tls_dtor (
112113 & mut self ,
113114 key : Option < TlsKey > ,
114- cx : & impl HasDataLayout ,
115115 ) -> Option < ( ty:: Instance < ' tcx > , Scalar < Tag > , TlsKey ) > {
116116 use std:: collections:: Bound :: * ;
117117
@@ -123,10 +123,10 @@ impl<'tcx> TlsData<'tcx> {
123123 for ( & key, & mut TlsEntry { ref mut data, dtor } ) in
124124 thread_local. range_mut ( ( start, Unbounded ) )
125125 {
126- if let Some ( ref mut data ) = * data {
126+ if let Some ( data_scalar ) = * data {
127127 if let Some ( dtor) = dtor {
128- let ret = Some ( ( dtor, * data , key) ) ;
129- * data = Scalar :: ptr_null ( cx ) ;
128+ let ret = Some ( ( dtor, data_scalar , key) ) ;
129+ * data = None ;
130130 return ret;
131131 }
132132 }
@@ -139,10 +139,11 @@ impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tc
139139pub trait EvalContextExt < ' mir , ' tcx : ' mir > : crate :: MiriEvalContextExt < ' mir , ' tcx > {
140140 fn run_tls_dtors ( & mut self ) -> InterpResult < ' tcx > {
141141 let this = self . eval_context_mut ( ) ;
142- let mut dtor = this. machine . tls . fetch_tls_dtor ( None , & * this . tcx ) ;
142+ let mut dtor = this. machine . tls . fetch_tls_dtor ( None ) ;
143143 // FIXME: replace loop by some structure that works with stepping
144144 while let Some ( ( instance, ptr, key) ) = dtor {
145145 trace ! ( "Running TLS dtor {:?} on {:?}" , instance, ptr) ;
146+ assert ! ( !this. is_null( ptr) . unwrap( ) , "Data can't be NULL when dtor is called!" ) ;
146147 // TODO: Potentially, this has to support all the other possible instances?
147148 // See eval_fn_call in interpret/terminator/mod.rs
148149 let mir = this. load_mir ( instance. def ) ?;
@@ -163,9 +164,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
163164 // step until out of stackframes
164165 this. run ( ) ?;
165166
166- dtor = match this. machine . tls . fetch_tls_dtor ( Some ( key) , & * this . tcx ) {
167+ dtor = match this. machine . tls . fetch_tls_dtor ( Some ( key) ) {
167168 dtor @ Some ( _) => dtor,
168- None => this. machine . tls . fetch_tls_dtor ( None , & * this . tcx ) ,
169+ None => this. machine . tls . fetch_tls_dtor ( None ) ,
169170 } ;
170171 }
171172 // FIXME: On a windows target, call `unsafe extern "system" fn on_tls_callback`.
0 commit comments