Commit 25d62480 by Jason Merrill

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.
parent 99eb1a82
2020-01-28 Jason Merrill <jason@redhat.com> 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 PR c++/90546
* call.c (build_user_type_conversion_1): Allow a template conversion * call.c (build_user_type_conversion_1): Allow a template conversion
returning an rvalue reference to bind directly to an lvalue. returning an rvalue reference to bind directly to an lvalue.
......
...@@ -3228,8 +3228,12 @@ copy_linkage (tree guard, tree decl) ...@@ -3228,8 +3228,12 @@ copy_linkage (tree guard, tree decl)
{ {
CP_DECL_THREAD_LOCAL_P (guard) = CP_DECL_THREAD_LOCAL_P (decl); CP_DECL_THREAD_LOCAL_P (guard) = CP_DECL_THREAD_LOCAL_P (decl);
set_decl_tls_model (guard, DECL_TLS_MODEL (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 if (DECL_ONE_ONLY (decl))
they may not be set until import_export_decl at EOF. */ 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)) if (vague_linkage_p (decl))
comdat_linkage (guard); comdat_linkage (guard);
DECL_VISIBILITY (guard) = DECL_VISIBILITY (decl); DECL_VISIBILITY (guard) = DECL_VISIBILITY (decl);
......
// 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();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment