https://gcc.gnu.org/g:bcb33b1237042e9540a905d9de19219f876e26c0
commit r15-3083-gbcb33b1237042e9540a905d9de19219f876e26c0 Author: Bernd Edlinger <bernd.edlin...@hotmail.de> Date: Fri Aug 16 12:26:27 2024 +0200 Do not emit a redundant DW_TAG_lexical_block for inlined subroutines While this already works correctly for the case when an inlined subroutine contains only one subrange, a redundant DW_TAG_lexical_block is still emitted when the subroutine has multiple blocks. Fixes: ac02e5b75451 ("re PR debug/37801 (DWARF output for inlined functions doesn't always use DW_TAG_inlined_subroutine)") gcc/ChangeLog: PR debug/87440 * dwarf2out.cc (gen_inlined_subroutine_die): Handle the case of multiple subranges correctly. gcc/testsuite/ChangeLog: * gcc.dg/debug/dwarf2/inline7.c: New test. Diff: --- gcc/dwarf2out.cc | 15 ++++++++++++--- gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index d5144714c6e6..75ce91efd47c 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -25194,17 +25194,26 @@ gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die) Do that by doing the recursion to subblocks on the single subblock of STMT. */ bool unwrap_one = false; - if (BLOCK_SUBBLOCKS (stmt) && !BLOCK_CHAIN (BLOCK_SUBBLOCKS (stmt))) + tree sub = BLOCK_SUBBLOCKS (stmt); + if (sub) { - tree origin = block_ultimate_origin (BLOCK_SUBBLOCKS (stmt)); + tree origin = block_ultimate_origin (sub); if (origin && TREE_CODE (origin) == BLOCK && BLOCK_SUPERCONTEXT (origin) == decl) unwrap_one = true; + for (tree next = BLOCK_CHAIN (sub); unwrap_one && next; + next = BLOCK_CHAIN (next)) + if (BLOCK_FRAGMENT_ORIGIN (next) != sub) + unwrap_one = false; } decls_for_scope (stmt, subr_die, !unwrap_one); if (unwrap_one) - decls_for_scope (BLOCK_SUBBLOCKS (stmt), subr_die); + { + decls_for_scope (sub, subr_die); + for (sub = BLOCK_CHAIN (sub); sub; sub = BLOCK_CHAIN (sub)) + gen_block_die (sub, subr_die); + } } /* Generate a DIE for a field in a record, or structure. CTX is required: see diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c b/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c new file mode 100644 index 000000000000..48d457216b10 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c @@ -0,0 +1,20 @@ +/* Verify that both inline instances have a DW_AT_ranges but + no extra DW_TAG_lexical_block. */ +/* { dg-options "-O -gdwarf -dA" } */ +/* { dg-do compile } */ +/* { dg-final { scan-assembler-times "\\(DIE \\(\[^\n\]*\\) DW_TAG_inlined_subroutine" 2 } } */ +/* { dg-final { scan-assembler-times " DW_AT_ranges" 2 } } */ +/* { dg-final { scan-assembler-times "\\(DIE \\(\[^\n\]*\\) DW_TAG_lexical_block" 0 } } */ + +static int foo (int i) +{ + volatile int j = i + 3; + if (j == 3) + return 0; + return j - 2; +} +int main() +{ + volatile int z = foo (-2) && foo (-1); + return z; +}