]> gcc.gnu.org Git - gcc.git/commitdiff
Remove misleading debug line entries
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 7 Dec 2020 11:00:00 +0000 (12:00 +0100)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Thu, 10 Dec 2020 12:44:39 +0000 (13:44 +0100)
This removes gimple_debug_begin_stmts without block info which remain
after a gimple block originating from an inline function is unused.

The line numbers from these stmts are from the inline function,
but since the inline function is completely optimized away,
there will be no DW_TAG_inlined_subroutine so the debugger has
no callstack available at this point, and therefore those
line table entries are not helpful to the user.

2020-12-10  Bernd Edlinger  <bernd.edlinger@hotmail.de>

* cfgexpand.c (expand_gimple_basic_block): Remove special handling
of debug_inline_entries without block info.
* tree-inline.c (remap_gimple_stmt): Drop debug_nonbind_markers when
the call statement has no block info.
(copy_debug_stmt): Remove debug_nonbind_markers when inlining
and the block info is mapped to NULL.
* tree-ssa-live.c (clear_unused_block_pointer): Remove
debug_nonbind_markers originating from removed inline functions.

gcc/cfgexpand.c
gcc/tree-inline.c
gcc/tree-ssa-live.c

index f7b40911c441bd2e6d258da93e7e1b27eddf49ba..2cbcbc8068258b6c8f2022140fd58e979d2d1e41 100644 (file)
@@ -5956,14 +5956,7 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
              else if (gimple_debug_begin_stmt_p (stmt))
                val = GEN_RTX_DEBUG_MARKER_BEGIN_STMT_PAT ();
              else if (gimple_debug_inline_entry_p (stmt))
-               {
-                 tree block = gimple_block (stmt);
-
-                 if (block)
-                   val = GEN_RTX_DEBUG_MARKER_INLINE_ENTRY_PAT ();
-                 else
-                   goto delink_debug_stmt;
-               }
+               val = GEN_RTX_DEBUG_MARKER_INLINE_ENTRY_PAT ();
              else
                gcc_unreachable ();
 
index d9814bd10d39f006894a115568acc742820fed38..360b85f14dc3535efd05e427fd765870c2a11dbf 100644 (file)
@@ -1819,12 +1819,11 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id)
          /* If the inlined function has too many debug markers,
             don't copy them.  */
          if (id->src_cfun->debug_marker_count
-             > param_max_debug_marker_count)
+             > param_max_debug_marker_count
+             || id->reset_location)
            return stmts;
 
          gdebug *copy = as_a <gdebug *> (gimple_copy (stmt));
-         if (id->reset_location)
-           gimple_set_location (copy, input_location);
          id->debug_stmts.safe_push (copy);
          gimple_seq_add_stmt (&stmts, copy);
          return stmts;
@@ -3169,7 +3168,14 @@ copy_debug_stmt (gdebug *stmt, copy_body_data *id)
     }
 
   if (gimple_debug_nonbind_marker_p (stmt))
-    return;
+    {
+      if (id->call_stmt && !gimple_block (stmt))
+       {
+         gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
+         gsi_remove (&gsi, true);
+       }
+      return;
+    }
 
   /* Remap all the operands in COPY.  */
   memset (&wi, 0, sizeof (wi));
index 21a9ee43e6bb0e59a7686d5187eaf1848c56c2fd..4cad6faa9efb0da0571b5e236d5016e2ac7caeed 100644 (file)
@@ -623,13 +623,43 @@ clear_unused_block_pointer (void)
       {
        unsigned i;
        tree b;
-       gimple *stmt = gsi_stmt (gsi);
+       gimple *stmt;
 
+      next:
+       stmt = gsi_stmt (gsi);
        if (!is_gimple_debug (stmt) && !gimple_clobber_p (stmt))
          continue;
        b = gimple_block (stmt);
        if (b && !TREE_USED (b))
-         gimple_set_block (stmt, NULL);
+         {
+           /* Elide debug marker stmts that have an associated BLOCK from an
+              inline instance removed with also the outermost scope BLOCK of
+              said inline instance removed.  If the outermost scope BLOCK of
+              said inline instance is preserved use that in place of the
+              removed BLOCK.  That keeps the marker associated to the correct
+              inline instance (or no inline instance in case it was not from
+              an inline instance).  */
+           if (gimple_debug_nonbind_marker_p (stmt)
+               && BLOCK_ABSTRACT_ORIGIN (b))
+             {
+               while (TREE_CODE (b) == BLOCK
+                      && !inlined_function_outer_scope_p (b))
+                 b = BLOCK_SUPERCONTEXT (b);
+               if (TREE_CODE (b) == BLOCK)
+                 {
+                   if (TREE_USED (b))
+                     {
+                       gimple_set_block (stmt, b);
+                       continue;
+                     }
+                   gsi_remove (&gsi, true);
+                   if (gsi_end_p (gsi))
+                     break;
+                   goto next;
+                 }
+             }
+           gimple_set_block (stmt, NULL);
+         }
        for (i = 0; i < gimple_num_ops (stmt); i++)
          walk_tree (gimple_op_ptr (stmt, i), clear_unused_block_pointer_1,
                     NULL, NULL);
This page took 0.072341 seconds and 5 git commands to generate.