The following fixes PR90914, we cannot keep local exten declarations
unmarked since they will be re-created when instantiating the function
BLOCKs later.  And that causes issues if by that means new types get
materialized which should not happen at that point.

Bootstrapped / tested on x86_64-unknown-linux-gnu, applied to trunk sofar.

Richard.

2019-06-21  Richard Biener  <rguent...@suse.de>

        PR debug/90914
        * dwarf2out.c (prune_unused_types_walk): Always consider
        function-local extern declarations as used.

        * g++.dg/debug/pr90914.C: New testcase.

Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c     (revision 272545)
+++ gcc/dwarf2out.c     (working copy)
@@ -29419,9 +29419,16 @@ prune_unused_types_walk (dw_die_ref die)
            break;
 
          /* premark_used_variables marks external variables --- don't mark
-            them here.  */
+            them here.  But function-local externals are always considered
+            used.  */
          if (get_AT (die, DW_AT_external))
-           return;
+           {
+             for (c = die->die_parent; c; c = c->die_parent)
+               if (c->die_tag == DW_TAG_subprogram)
+                 break;
+             if (!c)
+               return;
+           }
        }
       /* FALLTHROUGH */
 
Index: gcc/testsuite/g++.dg/debug/pr90914.C
===================================================================
--- gcc/testsuite/g++.dg/debug/pr90914.C        (nonexistent)
+++ gcc/testsuite/g++.dg/debug/pr90914.C        (working copy)
@@ -0,0 +1,8 @@
+// { dg-do compile }
+// { dg-additional-options "-feliminate-unused-debug-symbols" }
+
+template <class> class A;
+void f ()
+{
+  extern A <double> b;
+}

Reply via email to