* C++ PATCH for c++/65209 (linkage of anonymous namespace)
@ 2015-02-25 22:09 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2015-02-25 22:09 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 406 bytes --]
There are two issues with this testcase: one, when we internalize a decl
because it involves an anonymous namespace we need to clear DECL_COMDAT,
now that we're setting it early. Also, our handling of pointers to
local functions also needs to handle references.
Tested x86_64-pc-linux-gnu, applying to trunk. Also applying the second
hunk to 4.9, as the second issue is a regression there as well.
[-- Attachment #2: 65209.patch --]
[-- Type: text/x-patch, Size: 2136 bytes --]
commit 4e63fb3b23cc61a1e8709ae153e7f8e77bb09e39
Author: Jason Merrill <jason@redhat.com>
Date: Wed Feb 25 15:42:35 2015 -0500
PR c++/65209
* decl2.c (constrain_visibility) [VISIBILITY_ANON]: Clear
DECL_COMDAT.
(constrain_visibility_for_template): Handle reference arguments.
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index a7bc08f..a4a5ebf 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -2175,6 +2175,7 @@ constrain_visibility (tree decl, int visibility, bool tmpl)
TREE_PUBLIC (decl) = 0;
DECL_WEAK (decl) = 0;
DECL_COMMON (decl) = 0;
+ DECL_COMDAT (decl) = false;
if (TREE_CODE (decl) == FUNCTION_DECL
|| TREE_CODE (decl) == VAR_DECL)
{
@@ -2215,9 +2216,12 @@ constrain_visibility_for_template (tree decl, tree targs)
tree arg = TREE_VEC_ELT (args, i-1);
if (TYPE_P (arg))
vis = type_visibility (arg);
- else if (TREE_TYPE (arg) && POINTER_TYPE_P (TREE_TYPE (arg)))
+ else
{
- STRIP_NOPS (arg);
+ if (REFERENCE_REF_P (arg))
+ arg = TREE_OPERAND (arg, 0);
+ if (TREE_TYPE (arg))
+ STRIP_NOPS (arg);
if (TREE_CODE (arg) == ADDR_EXPR)
arg = TREE_OPERAND (arg, 0);
if (VAR_OR_FUNCTION_DECL_P (arg))
diff --git a/gcc/testsuite/g++.dg/abi/anon4.C b/gcc/testsuite/g++.dg/abi/anon4.C
new file mode 100644
index 0000000..088ba99
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/anon4.C
@@ -0,0 +1,41 @@
+// PR c++/65209
+// { dg-final { scan-assembler-not "comdat" } }
+
+// Everything involving the anonymous namespace bits should be private, not
+// COMDAT.
+
+struct Bar
+{
+ static Bar *self();
+ char pad[24];
+};
+
+template <Bar *(&holderFunction)()>
+struct BarGlobalStatic
+{
+ Bar *operator()() { return holderFunction(); }
+};
+
+namespace {
+ namespace Q_QGS_s_self {
+ inline Bar *innerFunction() {
+ static struct Holder {
+ Bar value;
+ ~Holder() {}
+ } holder;
+ return &holder.value;
+ }
+ }
+}
+static BarGlobalStatic<Q_QGS_s_self::innerFunction> s_self;
+
+Bar *Bar::self()
+{
+ return s_self();
+}
+
+int main(int argc, char *argv[])
+{
+ Bar* bar = Bar::self();
+ return 0;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-02-25 21:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-25 22:09 C++ PATCH for c++/65209 (linkage of anonymous namespace) Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).