Blame SOURCES/gcc8-pr85400.patch

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