https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89905

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-debug
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2019-04-03
             Blocks|                            |82738
         Depends on|                            |89892
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed, same issue as PR89892.  DCE removes the last real stmt in a BB
which then is removed as a forwarder by CFG cleanup but that has to drop
debug stmts on the floor because there's no place for it to safely insert
them.

Applying the following

Index: gcc/tree-cfgcleanup.c
===================================================================
--- gcc/tree-cfgcleanup.c       (revision 270114)
+++ gcc/tree-cfgcleanup.c       (working copy)
@@ -565,14 +565,24 @@ remove_forwarder_block (basic_block bb)
     }

   /* Move debug statements if the destination has a single predecessor.  */
-  if (can_move_debug_stmts && !gsi_end_p (gsi))
+  if (!gsi_end_p (gsi))
     {
+      bool informed = false;
       gsi_to = gsi_after_labels (dest);
       do
        {
          gimple *debug = gsi_stmt (gsi);
          gcc_assert (is_gimple_debug (debug));
-         gsi_move_before (&gsi, &gsi_to);
+         if (can_move_debug_stmts)
+           gsi_move_before (&gsi, &gsi_to);
+         else
+           {
+             if (!informed)
+               inform (gimple_location (debug),
+                       "dropping (multiple) debug stmt");
+             informed = true;
+             gsi_next (&gsi);
+           }
        }
       while (!gsi_end_p (gsi));
     }

shows this happens quite a lot :/

> ./xgcc -B. t.c -Og -g -fdump-tree-all -w
t.c: In function ā€˜i’:
t.c:13:7: note: dropping (multiple) debug stmt
   13 |       for (; d >= 33;) {
      |       ^~~
t.c:18:7: note: dropping (multiple) debug stmt
   18 |     j = b() || m[2];
      |     ~~^~~~~~~~~~~~~
t.c:17:5: note: dropping (multiple) debug stmt
   17 |     i++;
      |     ^


Doing the suggested resetting "fixes" the issue (gdb prints <optimized out>).

Index: gcc/tree-cfgcleanup.c
===================================================================
--- gcc/tree-cfgcleanup.c       (revision 270114)
+++ gcc/tree-cfgcleanup.c       (working copy)
@@ -564,8 +564,9 @@ remove_forwarder_block (basic_block bb)
        gsi_next (&gsi);
     }

-  /* Move debug statements if the destination has a single predecessor.  */
-  if (can_move_debug_stmts && !gsi_end_p (gsi))
+  /* Move debug statements.  Reset them if the destination does not
+     have a single predecessor.  */
+  if (!gsi_end_p (gsi))
     {
       gsi_to = gsi_after_labels (dest);
       do
@@ -573,6 +574,9 @@ remove_forwarder_block (basic_block bb)
          gimple *debug = gsi_stmt (gsi);
          gcc_assert (is_gimple_debug (debug));
          gsi_move_before (&gsi, &gsi_to);
+         if (!can_move_debug_stmts
+             && gimple_debug_bind_p (debug))
+           gimple_debug_bind_reset_value (debug);
        }
       while (!gsi_end_p (gsi));
     }


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82738
[Bug 82738] [meta-bug] issues with the -Og optimization level
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89892
[Bug 89892] gcc generates wrong debug information at -O2

Reply via email to