Blame SOURCES/gcc8-pr85400.patch

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