@@ -2214,6 +2214,11 @@ pub enum Rvalue<'tcx> {
22142214 /// &x or &mut x
22152215 Ref ( Region < ' tcx > , BorrowKind , Place < ' tcx > ) ,
22162216
2217+ /// Accessing a thread local static. This is inherently a runtime operation, even if llvm
2218+ /// treats it as an access to a static. This `Rvalue` yields a reference to the thread local
2219+ /// static.
2220+ ThreadLocalRef ( DefId ) ,
2221+
22172222 /// Create a raw pointer to the given place
22182223 /// Can be generated by raw address of expressions (`&raw const x`),
22192224 /// or when casting a reference to a raw pointer.
@@ -2353,6 +2358,10 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23532358 UnaryOp ( ref op, ref a) => write ! ( fmt, "{:?}({:?})" , op, a) ,
23542359 Discriminant ( ref place) => write ! ( fmt, "discriminant({:?})" , place) ,
23552360 NullaryOp ( ref op, ref t) => write ! ( fmt, "{:?}({:?})" , op, t) ,
2361+ ThreadLocalRef ( did) => ty:: tls:: with ( |tcx| {
2362+ let muta = tcx. static_mutability ( did) . unwrap ( ) . prefix_str ( ) ;
2363+ write ! ( fmt, "&/*tls*/ {}{}" , muta, tcx. def_path_str( did) )
2364+ } ) ,
23562365 Ref ( region, borrow_kind, ref place) => {
23572366 let kind_str = match borrow_kind {
23582367 BorrowKind :: Shared => "" ,
@@ -2506,7 +2515,10 @@ impl Constant<'tcx> {
25062515 pub fn check_static_ptr ( & self , tcx : TyCtxt < ' _ > ) -> Option < DefId > {
25072516 match self . literal . val . try_to_scalar ( ) {
25082517 Some ( Scalar :: Ptr ( ptr) ) => match tcx. global_alloc ( ptr. alloc_id ) {
2509- GlobalAlloc :: Static ( def_id) => Some ( def_id) ,
2518+ GlobalAlloc :: Static ( def_id) => {
2519+ assert ! ( !tcx. is_thread_local_static( def_id) ) ;
2520+ Some ( def_id)
2521+ }
25102522 _ => None ,
25112523 } ,
25122524 _ => None ,
0 commit comments