The following fixes PR86523, we failed to assing DIE parents to some
function-local entities with the idea scope vars would pick them up
but that's not true for some of them.

Bootstrapped and tested on x86_64-unknown-linux-gnu, LTO bootstrapped
on the GCC 8 branch (it's said LTO bootstrap is broken on trunk).

Applied to trunk.

Richard.

2018-07-16  Richard Biener  <rguent...@suse.de>

        PR lto/86523
        * dwarf2out.c (dwarf2out_register_external_die): Assign DIE parents
        for function-local FUNCTION_DECL and RESULT_DECL immediately.

        * g++.dg/lto/pr86523-1_0.C: New testcase.
        * g++.dg/lto/pr86523-2_0.C: Likewise.

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index ba5c63eaf0b..1e33cf07f09 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -5959,7 +5959,9 @@ dwarf2out_register_external_die (tree decl, const char 
*sym,
           imports the original CUs.  */
        parent = comp_unit_die ();
       else if (TREE_CODE (ctx) == FUNCTION_DECL
+              && TREE_CODE (decl) != FUNCTION_DECL
               && TREE_CODE (decl) != PARM_DECL
+              && TREE_CODE (decl) != RESULT_DECL
               && TREE_CODE (decl) != BLOCK)
        /* Leave function local entities parent determination to when
           we process scope vars.  */
diff --git a/gcc/testsuite/g++.dg/lto/pr86523-1_0.C 
b/gcc/testsuite/g++.dg/lto/pr86523-1_0.C
new file mode 100644
index 00000000000..3f75cdd9d27
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr86523-1_0.C
@@ -0,0 +1,21 @@
+// { dg-lto-do link }
+// { dg-lto-options {{-O2 -flto -g -shared}} }
+namespace {
+    class a typedef b;
+    class a {};
+} // namespace
+class c {
+    struct C {
+       b d;
+    };
+    C e() const;
+};
+c::C c::e() const {
+    C g;
+    struct h {
+       C g;
+       h(C *) {}
+    } f(&g);
+    return g;
+}
+
diff --git a/gcc/testsuite/g++.dg/lto/pr86523-2_0.C 
b/gcc/testsuite/g++.dg/lto/pr86523-2_0.C
new file mode 100644
index 00000000000..f156230827e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr86523-2_0.C
@@ -0,0 +1,18 @@
+// { dg-lto-do link }
+// { dg-lto-options {{-O2 -flto -g -shared}} }
+class a typedef b;
+class a {};
+class c {
+    struct C {
+       b d;
+    };
+    C e() const;
+};
+c::C c::e() const {
+    C g;
+    struct h {
+       C g;
+       h(C *) {}
+    } f(&g);
+    return g;
+}

Reply via email to