@@ -165,6 +165,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
165165 // We need to handle `extern static`.
166166 match self . tcx . try_get_global_alloc ( alloc_id) {
167167 Some ( GlobalAlloc :: Static ( def_id) ) if self . tcx . is_thread_local_static ( def_id) => {
168+ // Thread-local statics do not have a constant address. They *must* be accessed via
169+ // `ThreadLocalRef`; we can never have a pointer to them as a regular constant value.
168170 bug ! ( "global memory cannot point to thread-local static" )
169171 }
170172 Some ( GlobalAlloc :: Static ( def_id) ) if self . tcx . is_foreign_item ( def_id) => {
@@ -539,6 +541,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
539541 None => throw_ub ! ( PointerUseAfterFree ( id, CheckInAllocMsg :: MemoryAccessTest ) ) ,
540542 Some ( GlobalAlloc :: Static ( def_id) ) => {
541543 assert ! ( self . tcx. is_static( def_id) ) ;
544+ // Thread-local statics do not have a constant address. They *must* be accessed via
545+ // `ThreadLocalRef`; we can never have a pointer to them as a regular constant value.
542546 assert ! ( !self . tcx. is_thread_local_static( def_id) ) ;
543547 // Notice that every static has two `AllocId` that will resolve to the same
544548 // thing here: one maps to `GlobalAlloc::Static`, this is the "lazy" ID,
@@ -740,6 +744,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
740744 match self . tcx . try_get_global_alloc ( id) {
741745 Some ( GlobalAlloc :: Static ( def_id) ) => {
742746 assert ! ( self . tcx. is_static( def_id) ) ;
747+ // Thread-local statics do not have a constant address. They *must* be accessed via
748+ // `ThreadLocalRef`; we can never have a pointer to them as a regular constant value.
743749 assert ! ( !self . tcx. is_thread_local_static( def_id) ) ;
744750 // Use size and align of the type.
745751 let ty = self
0 commit comments