re PR middle-end/64491 (incorrect warning: loop exit may only be reached after undefi...
authorAndrew Stubbs <ams@codesourcery.com>
Wed, 18 Mar 2015 14:27:13 +0000 (14:27 +0000)
committerAndrew Stubbs <ams@gcc.gnu.org>
Wed, 18 Mar 2015 14:27:13 +0000 (14:27 +0000)
Fix PR64491

2015-03-18  Andrew Stubbs  <ams@codesourcery.com>

PR middle-end/64491
Revert:
2014-11-20  Andrew Stubbs  <ams@codesourcery.com>

* tree-ssa-loop-niter.c (maybe_lower_iteration_bound): Warn if a loop
condition would be removed due to undefined behaviour.

2015-03-18  Andrew Stubbs  <ams@codesourcery.com>

PR middle-end/64491
Revert:
2014-11-20  Andrew Stubbs  <ams@codesourcery.com>

* gcc.dg/undefined-loop-1.c: New file.
* gcc.dg/undefined-loop-2.c: New file.

2014-12-24  Andrew Stubbs  <ams@codesourcery.com>

PR testsuite/64032
* gcc.dg/undefined-loop-2.c: Don't allow GCC to optimize away the
loop exits too early.

From-SVN: r221492

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/undefined-loop-1.c [deleted file]
gcc/testsuite/gcc.dg/undefined-loop-2.c [deleted file]
gcc/tree-ssa-loop-niter.c

index 7325636dd25aa4ab32b3c8a61eff7bec5403cad7..a447690324f543c5bd21c98898f185b2a390261c 100644 (file)
@@ -1,3 +1,12 @@
+2015-03-18  Andrew Stubbs  <ams@codesourcery.com>
+
+       PR middle-end/64491
+       Revert:
+       2014-11-20  Andrew Stubbs  <ams@codesourcery.com>
+
+       * tree-ssa-loop-niter.c (maybe_lower_iteration_bound): Warn if a loop
+       condition would be removed due to undefined behaviour.
+
 2015-03-18  Martin Liska  <mliska@suse.cz>
 
        PR ipa/65432
index c4d283c0d95fd117996b7a7ac1cde76b03253d16..7530c2b9b01d7c1a6beeb6bfb98c5ac15458d35d 100644 (file)
@@ -1,3 +1,18 @@
+2015-03-18  Andrew Stubbs  <ams@codesourcery.com>
+
+       PR middle-end/64491
+       Revert:
+       2014-11-20  Andrew Stubbs  <ams@codesourcery.com>
+
+       * gcc.dg/undefined-loop-1.c: New file.
+       * gcc.dg/undefined-loop-2.c: New file.
+
+       2014-12-24  Andrew Stubbs  <ams@codesourcery.com>
+
+       PR testsuite/64032
+       * gcc.dg/undefined-loop-2.c: Don't allow GCC to optimize away the
+       loop exits too early.
+
 2015-03-18  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/65450
diff --git a/gcc/testsuite/gcc.dg/undefined-loop-1.c b/gcc/testsuite/gcc.dg/undefined-loop-1.c
deleted file mode 100644 (file)
index 80260cc..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Check that loops whose final iteration is undefined are detected.  */
-/* { dg-do compile } */
-/* { dg-options "-O2 -Waggressive-loop-optimizations" } */
-
-void doSomething(char);
-
-char array[5];
-
-void
-foo (void)
-{
-  int i;
-  for (i = 0;
-       array[i]  /* { dg-message "note: possible undefined statement is here" } */
-       && i < 5; /* { dg-warning "loop exit may only be reached after undefined behavior" } */
-       i++)
-    doSomething(array[i]);
-}
diff --git a/gcc/testsuite/gcc.dg/undefined-loop-2.c b/gcc/testsuite/gcc.dg/undefined-loop-2.c
deleted file mode 100644 (file)
index 7ab37f4..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Check that loops whose final iteration is undefined are detected.  */
-/* { dg-do compile } */
-/* { dg-options "-O2 -Waggressive-loop-optimizations" } */
-
-void doSomething(char);
-
-char array1[5];
-char array2[5];
-
-void
-foo (int p)
-{
-  int i;
-  for (i=0;
-       (p
-        ? array1[i]  /* { dg-message "note: possible undefined statement is here" } */
-        : array2[i]) /* { dg-message "note: possible undefined statement is here" } */
-       && i < 100;   /* { dg-warning "loop exit may only be reached after undefined behavior" } */
-       i++)
-    {
-      if (i >= 5)    /* { dg-warning "loop exit may only be reached after undefined behavior" } */
-       break;
-      doSomething(array1[i]);
-    }
-}
index 7f6c451c0c29854e1ccb3b559f60eca2ea53e17e..fc63825904fa7c61414a6dd353e0724e95586547 100644 (file)
@@ -3329,7 +3329,6 @@ maybe_lower_iteration_bound (struct loop *loop)
   struct nb_iter_bound *elt;
   bool found_exit = false;
   vec<basic_block> queue = vNULL;
-  vec<gimple> problem_stmts = vNULL;
   bitmap visited;
 
   /* Collect all statements with interesting (i.e. lower than
@@ -3375,7 +3374,6 @@ maybe_lower_iteration_bound (struct loop *loop)
          if (not_executed_last_iteration->contains (stmt))
            {
              stmt_found = true;
-             problem_stmts.safe_push (stmt);
              break;
            }
          if (gimple_has_side_effects (stmt))
@@ -3419,53 +3417,10 @@ maybe_lower_iteration_bound (struct loop *loop)
                 "undefined statement must be executed at the last iteration.\n");
       record_niter_bound (loop, loop->nb_iterations_upper_bound - 1,
                          false, true);
-
-      if (warn_aggressive_loop_optimizations)
-       {
-         bool exit_warned = false;
-         for (elt = loop->bounds; elt; elt = elt->next)
-           {
-             if (elt->is_exit
-                 && wi::gtu_p (elt->bound, loop->nb_iterations_upper_bound))
-               {
-                 basic_block bb = gimple_bb (elt->stmt);
-                 edge exit_edge = EDGE_SUCC (bb, 0);
-                 struct tree_niter_desc niter;
-
-                 if (!loop_exit_edge_p (loop, exit_edge))
-                   exit_edge = EDGE_SUCC (bb, 1);
-
-                 if(number_of_iterations_exit (loop, exit_edge,
-                                               &niter, false, false)
-                    && integer_onep (niter.assumptions)
-                    && integer_zerop (niter.may_be_zero)
-                    && niter.niter
-                    && TREE_CODE (niter.niter) == INTEGER_CST
-                    && wi::ltu_p (loop->nb_iterations_upper_bound,
-                                  wi::to_widest (niter.niter)))
-                  {
-                    if (warning_at (gimple_location (elt->stmt),
-                                    OPT_Waggressive_loop_optimizations,
-                                    "loop exit may only be reached after undefined behavior"))
-                      exit_warned = true;
-                  }
-               }
-           }
-
-         if (exit_warned && !problem_stmts.is_empty ())
-           {
-             gimple stmt;
-             int index;
-             FOR_EACH_VEC_ELT (problem_stmts, index, stmt)
-               inform (gimple_location (stmt),
-                       "possible undefined statement is here");
-           }
-      }
     }
 
   BITMAP_FREE (visited);
   queue.release ();
-  problem_stmts.release ();
   delete not_executed_last_iteration;
 }