Blame SOURCES/gcc8-pr85400.patch

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