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