@@ -2214,6 +2214,11 @@ pub enum Rvalue<'tcx> {
2214
2214
/// &x or &mut x
2215
2215
Ref ( Region < ' tcx > , BorrowKind , Place < ' tcx > ) ,
2216
2216
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
+
2217
2222
/// Create a raw pointer to the given place
2218
2223
/// Can be generated by raw address of expressions (`&raw const x`),
2219
2224
/// or when casting a reference to a raw pointer.
@@ -2353,6 +2358,10 @@ impl<'tcx> Debug for Rvalue<'tcx> {
2353
2358
UnaryOp ( ref op, ref a) => write ! ( fmt, "{:?}({:?})" , op, a) ,
2354
2359
Discriminant ( ref place) => write ! ( fmt, "discriminant({:?})" , place) ,
2355
2360
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
+ } ) ,
2356
2365
Ref ( region, borrow_kind, ref place) => {
2357
2366
let kind_str = match borrow_kind {
2358
2367
BorrowKind :: Shared => "" ,
@@ -2506,7 +2515,10 @@ impl Constant<'tcx> {
2506
2515
pub fn check_static_ptr ( & self , tcx : TyCtxt < ' _ > ) -> Option < DefId > {
2507
2516
match self . literal . val . try_to_scalar ( ) {
2508
2517
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
+ }
2510
2522
_ => None ,
2511
2523
} ,
2512
2524
_ => None ,
0 commit comments