]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Do not emit a redundant DW_TAG_lexical_block for inlined subroutines
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Fri, 16 Aug 2024 10:26:27 +0000 (12:26 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Thu, 22 Aug 2024 10:35:36 +0000 (12:35 +0200)
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.

gcc/dwarf2out.cc
gcc/testsuite/gcc.dg/debug/dwarf2/inline7.c [new file with mode: 0644]

index d5144714c6e6a15d753fa857932856428eaae1b8..75ce91efd47c3dad9581ec5f84ce4866ea5b55c3 100644 (file)
@@ -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 (file)
index 0000000..48d4572
--- /dev/null
@@ -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;
+}