Blame SOURCES/gcc8-pr85400.patch

f56e54
2018-05-10  Eric Botcazou  <ebotcazou@adacore.com>
f56e54
f56e54
	PR c++/85400
f56e54
	* c-attribs.c (handle_visibility_attribute): Do not set no_add_attrs.
f56e54
f56e54
	* decl2.c (adjust_var_decl_tls_model): New static function.
f56e54
	(comdat_linkage): Call it on a variable.
f56e54
	(maybe_make_one_only): Likewise.
f56e54
f56e54
--- gcc/c-family/c-attribs.c
f56e54
+++ gcc/c-family/c-attribs.c
f56e54
@@ -2299,14 +2299,13 @@ handle_visibility_attribute (tree *node, tree name, tree args,
f56e54
 
f56e54
 static tree
f56e54
 handle_tls_model_attribute (tree *node, tree name, tree args,
f56e54
-			    int ARG_UNUSED (flags), bool *no_add_attrs)
f56e54
+			    int ARG_UNUSED (flags),
f56e54
+			    bool *ARG_UNUSED (no_add_attrs))
f56e54
 {
f56e54
   tree id;
f56e54
   tree decl = *node;
f56e54
   enum tls_model kind;
f56e54
 
f56e54
-  *no_add_attrs = true;
f56e54
-
f56e54
   if (!VAR_P (decl) || !DECL_THREAD_LOCAL_P (decl))
f56e54
     {
f56e54
       warning (OPT_Wattributes, "%qE attribute ignored", name);
f56e54
--- gcc/cp/decl2.c
f56e54
+++ gcc/cp/decl2.c
f56e54
@@ -1838,6 +1838,17 @@ mark_vtable_entries (tree decl)
f56e54
     }
f56e54
 }
f56e54
 
f56e54
+/* Adjust the TLS model on variable DECL if need be, typically after
f56e54
+   the linkage of DECL has been modified.  */
f56e54
+
f56e54
+static void
f56e54
+adjust_var_decl_tls_model (tree decl)
f56e54
+{
f56e54
+  if (CP_DECL_THREAD_LOCAL_P (decl)
f56e54
+      && !lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl)))
f56e54
+    set_decl_tls_model (decl, decl_default_tls_model (decl));
f56e54
+}
f56e54
+
f56e54
 /* Set DECL up to have the closest approximation of "initialized common"
f56e54
    linkage available.  */
f56e54
 
f56e54
@@ -1888,6 +1899,9 @@ comdat_linkage (tree decl)
f56e54
 
f56e54
   if (TREE_PUBLIC (decl))
f56e54
     DECL_COMDAT (decl) = 1;
f56e54
+
f56e54
+  if (VAR_P (decl))
f56e54
+    adjust_var_decl_tls_model (decl);
f56e54
 }
f56e54
 
f56e54
 /* For win32 we also want to put explicit instantiations in
f56e54
@@ -1926,6 +1940,8 @@ maybe_make_one_only (tree decl)
f56e54
 	  /* Mark it needed so we don't forget to emit it.  */
f56e54
           node->forced_by_abi = true;
f56e54
 	  TREE_USED (decl) = 1;
f56e54
+
f56e54
+	  adjust_var_decl_tls_model (decl);
f56e54
 	}
f56e54
     }
f56e54
 }
f56e54
--- /dev/null
f56e54
+++ gcc/testsuite/g++.dg/tls/pr85400.C
f56e54
@@ -0,0 +1,24 @@
f56e54
+// PR c++/85400
f56e54
+// Testcase by Brian Vandenberg <phantall@gmail.com>
f56e54
+
f56e54
+// { dg-do link { target c++11 } }
f56e54
+// { dg-require-effective-target fpic }
f56e54
+// { dg-require-effective-target shared }
f56e54
+// { dg-require-effective-target tls }
f56e54
+// { dg-options "-shared -fPIC -O" }
f56e54
+// { dg-add-options tls }
f56e54
+
f56e54
+struct Test
f56e54
+{
f56e54
+  int blah (int y)
f56e54
+  {
f56e54
+    thread_local int mything = 3;
f56e54
+    mything = y > 0 ? y : mything;
f56e54
+    return mything;
f56e54
+  }
f56e54
+};
f56e54
+
f56e54
+int stuff (Test& test, int y)
f56e54
+{
f56e54
+  return test.blah(y);
f56e54
+}