From: Jason Merrill Date: Tue, 10 Nov 2020 23:02:04 +0000 (-0500) Subject: dwarf2: Set DW_AT_declaration for undefined fns [PR97060] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=87b7d45e358e4df93b6a93b2e7a55b123ea76f5d;p=gcc.git dwarf2: Set DW_AT_declaration for undefined fns [PR97060] If DECL_INITIAL isn't set, we can't emit anything about the body of the function, so add the declaration attribute. gcc/ChangeLog: PR debug/97060 * dwarf2out.c (gen_subprogram_die): It's a declaration if DECL_INITIAL isn't set. gcc/testsuite/ChangeLog: PR debug/97060 * gcc.dg/debug/dwarf2/pr97060.c: New test. --- diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index bea02f9fbce..4452b9fa89e 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -22859,6 +22859,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die) available. */ int declaration = (current_function_decl != decl + || (!DECL_INITIAL (decl) && !origin) || class_or_namespace_scope_p (context_die)); /* A declaration that has been previously dumped needs no diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/pr97060.c b/gcc/testsuite/gcc.dg/debug/dwarf2/pr97060.c new file mode 100644 index 00000000000..c07b9046d9a --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr97060.c @@ -0,0 +1,13 @@ +/* PR debug/97060 */ +/* { dg-do compile } */ +/* { dg-options "-g -dA" } */ +/* { dg-final { scan-assembler-times "DW_AT_declaration" 2 } } */ + +extern int foo (unsigned int, unsigned int); + +int +bar (void) +{ + foo (1, 2); + return 0; +}