The following fixes a link failure due to missing skeleton
ancestors.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

        PR debug/110885
        * dwarf2out.cc (generate_skeleton_bottom_up): Generate the
        skeleton ancestor tree when moving a new child to the parent
        even for template instantiations.

        * g++.dg/debug/dwarf2/pr110885.C: New testcase.
---
 gcc/dwarf2out.cc                             |  1 +
 gcc/testsuite/g++.dg/debug/dwarf2/pr110885.C | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/debug/dwarf2/pr110885.C

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 345b12134dd..1ad944fc1d0 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -8545,6 +8545,7 @@ generate_skeleton_bottom_up (skeleton_chain_node *parent)
               type unit.  Just move the DIE and its children back to
               the skeleton tree (in the main CU).  */
            remove_child_with_prev (c, prev);
+           generate_skeleton_ancestor_tree (parent);
            add_child_die (parent->new_die, c);
            c = prev;
          }
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/pr110885.C 
b/gcc/testsuite/g++.dg/debug/dwarf2/pr110885.C
new file mode 100644
index 00000000000..48ad8002935
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/pr110885.C
@@ -0,0 +1,16 @@
+// { dg-do link }
+// { dg-options "-gsplit-dwarf -fdebug-types-section" }
+
+inline void foo() {}
+
+struct Y
+{
+    template<void (*func)()>
+    static void bar() {}
+};
+
+int main()
+{
+    Y::bar<foo>();
+    return 0;
+}
-- 
2.51.0

Reply via email to