aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/cp/name-lookup.c7
-rw-r--r--gcc/testsuite/g++.dg/tls/pr102496-1.C20
-rw-r--r--gcc/testsuite/g++.dg/tls/pr102496-2.C6
3 files changed, 32 insertions, 1 deletions
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index ddee8b3..c414a10 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -3375,7 +3375,10 @@ set_decl_context_in_fn (tree ctx, tree decl)
void
push_local_extern_decl_alias (tree decl)
{
- if (dependent_type_p (TREE_TYPE (decl)))
+ if (dependent_type_p (TREE_TYPE (decl))
+ || (processing_template_decl
+ && VAR_P (decl)
+ && CP_DECL_THREAD_LOCAL_P (decl)))
return;
/* EH specs were not part of the function type prior to c++17, but
we still can't go pushing dependent eh specs into the namespace. */
@@ -3471,6 +3474,8 @@ push_local_extern_decl_alias (tree decl)
push_nested_namespace (ns);
alias = do_pushdecl (alias, /* hiding= */true);
pop_nested_namespace (ns);
+ if (VAR_P (decl) && CP_DECL_THREAD_LOCAL_P (decl))
+ set_decl_tls_model (alias, DECL_TLS_MODEL (decl));
}
}
diff --git a/gcc/testsuite/g++.dg/tls/pr102496-1.C b/gcc/testsuite/g++.dg/tls/pr102496-1.C
new file mode 100644
index 0000000..8220e1e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tls/pr102496-1.C
@@ -0,0 +1,20 @@
+// PR c++/102496
+// { dg-do link { target c++11 } }
+// { dg-require-effective-target tls }
+// { dg-add-options tls }
+// { dg-additional-sources pr102496-2.C }
+
+template <int N>
+int
+foo ()
+{
+ extern __thread int t1;
+ return t1;
+}
+
+int
+main ()
+{
+ extern __thread int t2;
+ return foo <0> () + t2;
+}
diff --git a/gcc/testsuite/g++.dg/tls/pr102496-2.C b/gcc/testsuite/g++.dg/tls/pr102496-2.C
new file mode 100644
index 0000000..a71a9cd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tls/pr102496-2.C
@@ -0,0 +1,6 @@
+// PR c++/102496
+// { dg-do compile { target c++11 } }
+// { dg-require-effective-target tls }
+
+__thread int t1;
+__thread int t2;