PR c++/79176 - lambda ICE with -flto -Os
authorJason Merrill <jason@redhat.com>
Thu, 26 Jan 2017 15:30:43 +0000 (10:30 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 26 Jan 2017 15:30:43 +0000 (10:30 -0500)
* decl2.c (vague_linkage_p): Handle decloned 'tors.
* tree.c (decl_linkage): Likewise.

From-SVN: r244935

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/cp/tree.c
gcc/testsuite/g++.dg/opt/declone3.C [new file with mode: 0644]

index 7933e02e57de76a86f7a669681cb0e9c16a0e7c3..90b1671e6f0d4467155ae36143cb5934fc2ec448 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-26  Jason Merrill  <jason@redhat.com>
+
+       PR c++/79176 - lambda ICE with -flto -Os
+       * decl2.c (vague_linkage_p): Handle decloned 'tors.
+       * tree.c (decl_linkage): Likewise.
+
 2017-01-25  Martin Sebor  <msebor@redhat.com>
 
        * decl.c (grokdeclarator): Fix a typo in a comment.
index 0a4c5671df16a09ad6667acecc585a27492dc52f..a9a1d2286a84dcda45d4f58a5f61e873001361cb 100644 (file)
@@ -1816,6 +1816,14 @@ vague_linkage_p (tree decl)
 {
   if (!TREE_PUBLIC (decl))
     {
+      /* maybe_thunk_body clears TREE_PUBLIC on the maybe-in-charge 'tor
+        variants, check one of the "clones" for the real linkage.  */
+      if ((DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl)
+          || DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl))
+         && DECL_CHAIN (decl)
+         && DECL_CLONED_FUNCTION (DECL_CHAIN (decl)))
+       return vague_linkage_p (DECL_CHAIN (decl));
+
       gcc_checking_assert (!DECL_COMDAT (decl));
       return false;
     }
index 6fbc99ee56b9088035a380ce645b6f7a98c44159..3ecc2b00fefa6bb70deffecb9fbb52d7e4961837 100644 (file)
@@ -4418,6 +4418,14 @@ decl_linkage (tree decl)
   if (TREE_PUBLIC (decl))
     return lk_external;
 
+  /* maybe_thunk_body clears TREE_PUBLIC on the maybe-in-charge 'tor variants,
+     check one of the "clones" for the real linkage.  */
+  if ((DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl)
+       || DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl))
+      && DECL_CHAIN (decl)
+      && DECL_CLONED_FUNCTION (DECL_CHAIN (decl)))
+    return decl_linkage (DECL_CHAIN (decl));
+
   if (TREE_CODE (decl) == NAMESPACE_DECL)
     return lk_external;
 
diff --git a/gcc/testsuite/g++.dg/opt/declone3.C b/gcc/testsuite/g++.dg/opt/declone3.C
new file mode 100644 (file)
index 0000000..d8c2492
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/79176
+// { dg-do compile { target c++11 } }
+// { dg-options "-flto -Os" }
+
+struct A {};
+struct Object {
+  virtual bool m_fn1();
+  virtual ~Object();
+};
+struct Item : Object, virtual A {
+  ~Item() {
+    [] {};
+  }
+  bool m_fn1();
+};
+bool Item::m_fn1() {}