Hi folks.

Ben brought this bug to my attention which was causing a failure in libabigail.

The problem is that varargs functions are getting two DW_TAG_unspecified_parameters DIEs, because they are being emitted in early debug and again in late debug.

This problem appears in GCC 6 and in mainline.

The attached patch fixes the problem everywhere.

Tested on x86-64 Linux.

OK for mainline?

p.s. I don't know what the rules are for GCC 6 right now, but if it's open for bugfixes, I'd be more than happy to commit it there if the patch is approved.
commit c1531a5d6f2394e4ba350d216a19d84bc8796c12
Author: Aldy Hernandez <al...@redhat.com>
Date:   Tue Jul 19 12:18:48 2016 -0400

        PR debug/71855
        * dwarf2out.c (gen_subprogram_die): Only call
        gen_unspecified_parameters_die while dumping early dwarf.

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index fe09868..45ed28c 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -20730,14 +20730,17 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
         void_type_node 2) an unprototyped function declaration (not a
         definition).  This just means that we have no info about the
         parameters at all.  */
-      if (prototype_p (TREE_TYPE (decl)))
+      if (early_dwarf)
        {
-         /* This is the prototyped case, check for....  */
-         if (stdarg_p (TREE_TYPE (decl)))
+         if (prototype_p (TREE_TYPE (decl)))
+           {
+             /* This is the prototyped case, check for....  */
+             if (stdarg_p (TREE_TYPE (decl)))
+               gen_unspecified_parameters_die (decl, subr_die);
+           }
+         else if (DECL_INITIAL (decl) == NULL_TREE)
            gen_unspecified_parameters_die (decl, subr_die);
        }
-      else if (DECL_INITIAL (decl) == NULL_TREE)
-       gen_unspecified_parameters_die (decl, subr_die);
     }
 
   if (subr_die != old_die)
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/pr71855.c 
b/gcc/testsuite/gcc.dg/debug/dwarf2/pr71855.c
new file mode 100644
index 0000000..4fd8b74
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr71855.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O0 -g -dA" } */
+
+// Test that there is only one DW_TAG_unspecified_parameters DIE.
+
+void
+foo (const char *format, ...)
+{
+}
+
+// { dg-final { scan-assembler-times "DIE.*DW_TAG_unspecified_parameters" 1 } }

Reply via email to