Don't upgrade TLS model when cplus_decl_attributes is called on a thread
local variable whose TLS model isn't set yet.
gcc/cp/
PR c++/121889
* decl2.cc (cplus_decl_attributes): Don't upgrade TLS model if
TLS model isn't set yet.
gcc/testsuite/
PR c++/121889
* g++.dg/tls/pr121889.C: New test.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
{
// tls_model attribute can set a stronger TLS access model.
tls_model model = DECL_TLS_MODEL (*decl);
- tls_model default_model = decl_default_tls_model (*decl);
- if (default_model > model)
- set_decl_tls_model (*decl, default_model);
+ // Don't upgrade TLS model if TLS model isn't set yet.
+ if (model != TLS_MODEL_NONE)
+ {
+ tls_model default_model = decl_default_tls_model (*decl);
+ if (default_model > model)
+ set_decl_tls_model (*decl, default_model);
+ }
}
}
\f
--- /dev/null
+// { dg-do compile { target c++11 } }
+// { dg-require-effective-target tls }
+// { dg-options "-O2" }
+// { dg-add-options tls }
+
+extern void pthread_key_create();
+static __typeof(pthread_key_create) __gthrw___pthread_key_create
+ __attribute__((__weakref__("")));
+template <class> void zeta_imp_odd_integer() { thread_local int digits; }