[gcc r15-3083] Do not emit a redundant DW_TAG_lexical_block for inlined subroutines
https://gcc.gnu.org/g:bcb33b1237042e9540a905d9de19219f876e26c0 commit r15-3083-gbcb33b1237042e9540a905d9de19219f876e26c0 Author: Bernd Edlinger 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 ..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; +}
[gcc r15-3084] RISC-V: Enable -gvariable-location-views by default
https://gcc.gnu.org/g:76c29548b3de8bd06c3eef6084c19696019a7a2f commit r15-3084-g76c29548b3de8bd06c3eef6084c19696019a7a2f Author: Bernd Edlinger Date: Mon Aug 19 07:11:18 2024 +0200 RISC-V: Enable -gvariable-location-views by default This affects only the RISC-V targets, where the compiler options -gvariable-location-views and consequently also -ginline-points are disabled by default, which is unexpected and disables some useful features of the generated debug info. Due to a bug in the gas assembler the .loc statement is not usable to generate location view debug info. That is detected by configure: configure:31500: checking assembler for dwarf2 debug_view support configure:31509: .../riscv-unknown-elf/bin/as-o conftest.o conftest.s >&5 conftest.s: Assembler messages: conftest.s:5: Error: .uleb128 only supports constant or subtract expressions conftest.s:6: Error: .uleb128 only supports constant or subtract expressions configure:31512: $? = 1 configure: failed program was .file 1 "conftest.s" .loc 1 3 0 view .LVU1 nop .data .uleb128 .LVU1 .uleb128 .LVU1 configure:31523: result: no This results in dwarf2out_as_locview_support being set to false, and that creates a sequence of events, with the end result that most inlined functions either have no DW_AT_entry_pc, or one with a wrong entry pc value. But the location views can also be generated without using any .loc statements, therefore we should enable the option -gvariable-location-views by default, regardless of the status of -gas-locview-support. Note however, that the combination of the following compiler options -g -O2 -gvariable-location-views -gno-as-loc-support turned out to create invalid assembler intermediate files, with lots of assembler errors like: Error: leb128 operand is an undefined symbol: .LVU3 This affects all targets, except RISC-V of course ;-) and is fixed by the changes in dwarf2out.cc Finally the .debug_loclists created without assembler locview support did contain location view pairs like v000 v000 which is the value from FORCE_RESET_NEXT_VIEW, but that is most likely not as expected either, so change that as well. gcc/ChangeLog: * dwarf2out.cc (dwarf2out_maybe_output_loclist_view_pair, output_loc_list): Correct handling of -gno-as-loc-support, use ZERO_VIEW_P to output view number as zero value. * toplev.cc (process_options): Do not automatically disable -gvariable-location-views when -gno-as-loc-support or -gno-as-locview-support is used, instead do automatically disable -gas-locview-support if -gno-as-loc-support is used. gcc/testsuite/ChangeLog: * gcc.dg/debug/dwarf2/inline2.c: Add checks for inline entry_pc. * gcc.dg/debug/dwarf2/inline6.c: Add -gno-as-loc-support and check the resulting location views. Diff: --- gcc/dwarf2out.cc| 12 gcc/testsuite/gcc.dg/debug/dwarf2/inline2.c | 3 +++ gcc/testsuite/gcc.dg/debug/dwarf2/inline6.c | 7 ++- gcc/toplev.cc | 12 +--- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 75ce91efd47c..a26a07e34242 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -10396,8 +10396,10 @@ dwarf2out_maybe_output_loclist_view_pair (dw_loc_list_ref curr) } else { - dw2_asm_output_data_uleb128 (curr->vbegin, "Location view begin"); - dw2_asm_output_data_uleb128 (curr->vend, "Location view end"); + dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vbegin) + ? 0 : curr->vbegin, "Location view begin"); + dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vend) + ? 0 : curr->vend, "Location view end"); } #endif /* DW_LLE_view_pair */ @@ -10460,10 +10462,12 @@ output_loc_list (dw_loc_list_ref list_head) } else { - dw2_asm_output_data_uleb128 (curr->vbegin, + dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vbegin) + ? 0 : curr->vbegin, "View list begin (%s)", list_head->vl_symbol); - dw2_asm_output_data_uleb128 (curr->vend, + dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vend) + ? 0 : curr->vend, "View list end (%s)", list_head->vl_symbol); } diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/inline2.
[gcc r15-3118] Fix test failure on powerpc targets
https://gcc.gnu.org/g:a8ae8f9c2ed055b9e4408209f1c724493c5a3e3c commit r15-3118-ga8ae8f9c2ed055b9e4408209f1c724493c5a3e3c Author: Bernd Edlinger Date: Fri Aug 23 06:22:55 2024 +0200 Fix test failure on powerpc targets Apparently due to slightly different optimization levels not always both subroutines have multiple subranges, but having at least one such, and no lexical blocks is sufficient to prove that the fix worked. Q.E.D. So reduce the test expectations to only at least one inlined subroutine with multiple subranges. gcc/testsuite/ChangeLog: PR other/116462 * gcc.dg/debug/dwarf2/inline7.c: Reduce test expectations. Diff: --- gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c b/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c index 48d457216b10..083df5b586cd 100644 --- a/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c @@ -1,9 +1,9 @@ -/* Verify that both inline instances have a DW_AT_ranges but - no extra DW_TAG_lexical_block. */ +/* Verify that at least one of 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 " DW_AT_ranges" } } */ /* { dg-final { scan-assembler-times "\\(DIE \\(\[^\n\]*\\) DW_TAG_lexical_block" 0 } } */ static int foo (int i)
[gcc r15-3193] Fix bootstap-errors due to enabling -gvariable-location-views
https://gcc.gnu.org/g:eb63f9580f0220e347034ef337dbc93d12931d6c commit r15-3193-geb63f9580f0220e347034ef337dbc93d12931d6c Author: Bernd Edlinger Date: Sat Aug 24 08:37:53 2024 +0200 Fix bootstap-errors due to enabling -gvariable-location-views This recent change triggered various bootstap-errors, mostly on x86 targets because line info advance address entries were output in the wrong section table. The switch to the wrong line table happened in dwarfout_set_ignored_loc. It must use the same section as the earlier called dwarf2out_switch_text_section. But also ft32-elf was affected, because the assembler choked on something simple as ".2byte .LM2-.LM1", but fortunately it is able to use native location views, the configure test was just not executed because the ft32 "nop" instruction was missing. gcc/ChangeLog: PR debug/116470 * configure.ac: Add the "nop" instruction for cpu type ft32. * configure: Regenerate. * dwarf2out.cc (dwarf2out_set_ignored_loc): Use the correct line info section. Diff: --- gcc/configure| 2 +- gcc/configure.ac | 2 +- gcc/dwarf2out.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gcc/configure b/gcc/configure index 557ea5fa3ac9..3d301b6ecd3d 100755 --- a/gcc/configure +++ b/gcc/configure @@ -31398,7 +31398,7 @@ esac case "$cpu_type" in aarch64 | alpha | arc | arm | avr | bfin | cris | csky | i386 | loongarch | m32c \ | m68k | microblaze | mips | nds32 | nios2 | pa | riscv | rs6000 | score | sparc \ - | visium | xstormy16 | xtensa) + | visium | xstormy16 | xtensa | ft32) insn="nop" ;; ia64 | s390) diff --git a/gcc/configure.ac b/gcc/configure.ac index eaa01d0d7e56..8a2d2b0438e7 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5610,7 +5610,7 @@ esac case "$cpu_type" in aarch64 | alpha | arc | arm | avr | bfin | cris | csky | i386 | loongarch | m32c \ | m68k | microblaze | mips | nds32 | nios2 | pa | riscv | rs6000 | score | sparc \ - | visium | xstormy16 | xtensa) + | visium | xstormy16 | xtensa | ft32) insn="nop" ;; ia64 | s390) diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 633900b035fe..3f040da33a63 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -28939,7 +28939,7 @@ dwarf2out_set_ignored_loc (unsigned int line, unsigned int column, dw_fde_ref fde = cfun->fde; fde->ignored_debug = false; - set_cur_line_info_table (function_section (fde->decl)); + set_cur_line_info_table (current_function_section ()); dwarf2out_source_line (line, column, filename, 0, true); }
[gcc r15-3209] Fix another inline7.c test failure on sparc targets
https://gcc.gnu.org/g:103127cd9398d140222c9da44715d447641bf791 commit r15-3209-g103127cd9398d140222c9da44715d447641bf791 Author: Bernd Edlinger Date: Mon Aug 26 18:06:52 2024 +0200 Fix another inline7.c test failure on sparc targets This new test was reported to be still failing on sparc targets. Here the number of DW_AT_ranges dropped to zero. The test should pass on this architecture with -Os, -O2 and -O3. I tried to improve also different known problematic targets, where only one subroutine had DW_AT_ranges: Those are armhf (arm with hard float), powerpc and powerpc64. The best option is to use -Os: So far the only one, where all two inline instances in this test had two DW_AT_ranges. gcc/testsuite/ChangeLog: PR other/116462 * gcc.dg/debug/dwarf2/inline7.c: Switch to -Os optimization. Diff: --- gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c b/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c index 083df5b586cd..8b2fa1210adf 100644 --- a/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c @@ -1,6 +1,6 @@ /* Verify that at least one of both inline instances have a DW_AT_ranges but no extra DW_TAG_lexical_block. */ -/* { dg-options "-O -gdwarf -dA" } */ +/* { dg-options "-Os -gdwarf -dA" } */ /* { dg-do compile } */ /* { dg-final { scan-assembler-times "\\(DIE \\(\[^\n\]*\\) DW_TAG_inlined_subroutine" 2 } } */ /* { dg-final { scan-assembler " DW_AT_ranges" } } */