@@ -2209,6 +2209,11 @@ pub enum Rvalue<'tcx> {
22092209 /// &x or &mut x
22102210 Ref ( Region < ' tcx > , BorrowKind , Place < ' tcx > ) ,
22112211
2212+ /// Accessing a thread local static. This is inherently a runtime operation, even if llvm
2213+ /// treats it as an access to a static. This `Rvalue` yields a reference to the thread local
2214+ /// static.
2215+ ThreadLocalRef ( DefId ) ,
2216+
22122217 /// Create a raw pointer to the given place
22132218 /// Can be generated by raw address of expressions (`&raw const x`),
22142219 /// or when casting a reference to a raw pointer.
@@ -2348,6 +2353,10 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23482353 UnaryOp ( ref op, ref a) => write ! ( fmt, "{:?}({:?})" , op, a) ,
23492354 Discriminant ( ref place) => write ! ( fmt, "discriminant({:?})" , place) ,
23502355 NullaryOp ( ref op, ref t) => write ! ( fmt, "{:?}({:?})" , op, t) ,
2356+ ThreadLocalRef ( did) => ty:: tls:: with ( |tcx| {
2357+ let muta = tcx. static_mutability ( did) . unwrap ( ) . prefix_str ( ) ;
2358+ write ! ( fmt, "&/*tls*/ {}{}" , muta, tcx. def_path_str( did) )
2359+ } ) ,
23512360 Ref ( region, borrow_kind, ref place) => {
23522361 let kind_str = match borrow_kind {
23532362 BorrowKind :: Shared => "" ,
@@ -2501,7 +2510,10 @@ impl Constant<'tcx> {
25012510 pub fn check_static_ptr ( & self , tcx : TyCtxt < ' _ > ) -> Option < DefId > {
25022511 match self . literal . val . try_to_scalar ( ) {
25032512 Some ( Scalar :: Ptr ( ptr) ) => match tcx. global_alloc ( ptr. alloc_id ) {
2504- GlobalAlloc :: Static ( def_id) => Some ( def_id) ,
2513+ GlobalAlloc :: Static ( def_id) => {
2514+ assert ! ( !tcx. is_thread_local_static( def_id) ) ;
2515+ Some ( def_id)
2516+ }
25052517 _ => None ,
25062518 } ,
25072519 _ => None ,
0 commit comments