re PR debug/49602 (verify_ssa failed (definition does not dominate use) with "-O2...
authorJakub Jelinek <jakub@redhat.com>
Mon, 4 Jul 2011 17:19:52 +0000 (19:19 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 4 Jul 2011 17:19:52 +0000 (19:19 +0200)
PR debug/49602
* tree-into-ssa.c (rewrite_debug_stmt_uses): Disregard
get_current_def return value if it can't be trusted to be
the current value of the variable in the current bb.

* gcc.dg/pr49602.c: New test.

From-SVN: r175818

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr49602.c [new file with mode: 0644]
gcc/tree-into-ssa.c

index 230bc256eadb105df34bcfe6b2bf7dc02f032410..0823aa84fe02219c4ec6ca25b9a73df28f6fa1cd 100644 (file)
@@ -1,3 +1,10 @@
+2011-07-04  Jakub Jelinek  <jakub@redhat.com>
+
+       PR debug/49602
+       * tree-into-ssa.c (rewrite_debug_stmt_uses): Disregard
+       get_current_def return value if it can't be trusted to be
+       the current value of the variable in the current bb.
+
 2011-07-04  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/49600
index 21bab4d45ef243ef65653010bc1f2f9622ffb530..5a7d801c377e4564c354f5dd804d34f8ddf7ac86 100644 (file)
@@ -1,3 +1,8 @@
+2011-07-04  Jakub Jelinek  <jakub@redhat.com>
+
+       PR debug/49602
+       * gcc.dg/pr49602.c: New test.
+
 2011-07-04  Georg-Johann Lay  <avr@gjlay.de>
        
        PR target/34734
diff --git a/gcc/testsuite/gcc.dg/pr49602.c b/gcc/testsuite/gcc.dg/pr49602.c
new file mode 100644 (file)
index 0000000..bb8eeb0
--- /dev/null
@@ -0,0 +1,17 @@
+/* PR debug/49602 */
+/* { dg-do compile } */
+/* { dg-options "-g -O2" } */
+
+static void
+foo (int *x)
+{
+}
+
+void
+bar (int *x)
+{
+  int i;
+  for (i = 0; i == 1; ++i)
+    x = 0;
+  foo (x);
+}
index 0db9085f0530b66eba8c4d13d916e1920653aa84..5fd34455df4092d090e830f9e3444bc0a276e40b 100644 (file)
@@ -1343,7 +1343,41 @@ rewrite_debug_stmt_uses (gimple stmt)
            }
        }
       else
-       def = get_current_def (var);
+       {
+         def = get_current_def (var);
+         /* Check if get_current_def can be trusted.  */
+         if (def)
+           {
+             basic_block bb = gimple_bb (stmt);
+             basic_block def_bb
+               = SSA_NAME_IS_DEFAULT_DEF (def)
+                 ? NULL : gimple_bb (SSA_NAME_DEF_STMT (def));
+
+             /* If definition is in current bb, it is fine.  */
+             if (bb == def_bb)
+               ;
+             /* If definition bb doesn't dominate the current bb,
+                it can't be used.  */
+             else if (def_bb && !dominated_by_p (CDI_DOMINATORS, bb, def_bb))
+               def = NULL;
+             /* If there is just one definition and dominates the current
+                bb, it is fine.  */
+             else if (get_phi_state (var) == NEED_PHI_STATE_NO)
+               ;
+             else
+               {
+                 struct def_blocks_d *db_p = get_def_blocks_for (var);
+
+                 /* If there are some non-debug uses in the current bb,
+                    it is fine.  */
+                 if (bitmap_bit_p (db_p->livein_blocks, bb->index))
+                   ;
+                 /* Otherwise give up for now.  */
+                 else
+                   def = NULL;
+               }
+           }
+       }
       if (def == NULL)
        {
          gimple_debug_bind_reset_value (stmt);