[gcc(refs/vendors/redhat/heads/gcc-10-branch)] c++: Fix guard variable and attribute weak.
Jakub Jelinek
jakub@gcc.gnu.org
Thu Jan 30 20:52:00 GMT 2020
https://gcc.gnu.org/g:25d62480c89d6db90a66ba69f6dbaa820a1ac90b
commit 25d62480c89d6db90a66ba69f6dbaa820a1ac90b
Author: Jason Merrill <jason@redhat.com>
Date: Tue Jan 28 15:15:20 2020 -0500
c++: Fix guard variable and attribute weak.
My patch for PR 91476 worked for decls that are implicitly comdat/weak due
to C++ linkage rules, but broke variables explicitly marked weak.
PR c++/93477
PR c++/91476
* decl2.c (copy_linkage): Do copy DECL_ONE_ONLY and DECL_WEAK.
Diff:
---
gcc/cp/ChangeLog | 4 ++++
gcc/cp/decl2.c | 8 ++++++--
gcc/testsuite/g++.dg/abi/guard4.C | 11 +++++++++++
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a110efe..0a959bb 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2020-01-28 Jason Merrill <jason@redhat.com>
+ PR c++/93477
+ PR c++/91476
+ * decl2.c (copy_linkage): Do copy DECL_ONE_ONLY and DECL_WEAK.
+
PR c++/90546
* call.c (build_user_type_conversion_1): Allow a template conversion
returning an rvalue reference to bind directly to an lvalue.
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 1ecf0b9..98d8e6a 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -3228,8 +3228,12 @@ copy_linkage (tree guard, tree decl)
{
CP_DECL_THREAD_LOCAL_P (guard) = CP_DECL_THREAD_LOCAL_P (decl);
set_decl_tls_model (guard, DECL_TLS_MODEL (decl));
- /* We can't rely on DECL_WEAK (decl) or DECL_ONE_ONLY (decl) here, as
- they may not be set until import_export_decl at EOF. */
+ if (DECL_ONE_ONLY (decl))
+ make_decl_one_only (guard, cxx_comdat_group (guard));
+ if (TREE_PUBLIC (decl))
+ DECL_WEAK (guard) = DECL_WEAK (decl);
+ /* Also check vague_linkage_p, as DECL_WEAK and DECL_ONE_ONLY might not
+ be set until import_export_decl at EOF. */
if (vague_linkage_p (decl))
comdat_linkage (guard);
DECL_VISIBILITY (guard) = DECL_VISIBILITY (decl);
diff --git a/gcc/testsuite/g++.dg/abi/guard4.C b/gcc/testsuite/g++.dg/abi/guard4.C
new file mode 100644
index 0000000..537c905
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/guard4.C
@@ -0,0 +1,11 @@
+// PR c++/93477
+// { dg-require-weak }
+
+namespace x {
+ struct s {
+ s() {}
+ static int a;
+ };
+ // { dg-final { scan-assembler {.weak[^\n]*_ZGVN1x1bE} } }
+ struct s __attribute__((weak)) b = s();
+}
More information about the Gcc-cvs
mailing list