@@ -2209,6 +2209,11 @@ pub enum Rvalue<'tcx> {
2209
2209
/// &x or &mut x
2210
2210
Ref ( Region < ' tcx > , BorrowKind , Place < ' tcx > ) ,
2211
2211
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
+
2212
2217
/// Create a raw pointer to the given place
2213
2218
/// Can be generated by raw address of expressions (`&raw const x`),
2214
2219
/// or when casting a reference to a raw pointer.
@@ -2348,6 +2353,10 @@ impl<'tcx> Debug for Rvalue<'tcx> {
2348
2353
UnaryOp ( ref op, ref a) => write ! ( fmt, "{:?}({:?})" , op, a) ,
2349
2354
Discriminant ( ref place) => write ! ( fmt, "discriminant({:?})" , place) ,
2350
2355
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
+ } ) ,
2351
2360
Ref ( region, borrow_kind, ref place) => {
2352
2361
let kind_str = match borrow_kind {
2353
2362
BorrowKind :: Shared => "" ,
@@ -2501,7 +2510,10 @@ impl Constant<'tcx> {
2501
2510
pub fn check_static_ptr ( & self , tcx : TyCtxt < ' _ > ) -> Option < DefId > {
2502
2511
match self . literal . val . try_to_scalar ( ) {
2503
2512
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
+ }
2505
2517
_ => None ,
2506
2518
} ,
2507
2519
_ => None ,
0 commit comments