re PR tree-optimization/31602 (Overflow warning causes GDB -Werror build failure)
authorIan Lance Taylor <iant@google.com>
Tue, 24 Apr 2007 20:44:45 +0000 (20:44 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 24 Apr 2007 20:44:45 +0000 (20:44 +0000)
./: PR tree-optimization/31602
* tree-ssa-loop-ch.c (copy_loop_headers): Set TREE_NO_WARNING for
conditionals in the copied loop header.
* tree-cfg.c (fold_cond_expr_cond): Don't issue undefined overflow
warnings if TREE_NO_WARNING is set.
* doc/invoke.texi (Warning Options): Clarify that
-Wstrict-overflow does not warn about loops.
testsuite/:
PR tree-optimization/31602
* gcc.dg/Wstrict-overflow-11.c: We no longer issue a warning.

From-SVN: r124120

gcc/ChangeLog
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wstrict-overflow-11.c
gcc/tree-cfg.c
gcc/tree-ssa-loop-ch.c

index 7f72336a82a3b7790510f14db273f593ba41f265..88718264dcbab2754ab0c27ac2c6851bf3c68440 100644 (file)
@@ -1,3 +1,13 @@
+2007-04-24  Ian Lance Taylor  <iant@google.com>
+
+       PR tree-optimization/31602
+       * tree-ssa-loop-ch.c (copy_loop_headers): Set TREE_NO_WARNING for
+       conditionals in the copied loop header.
+       * tree-cfg.c (fold_cond_expr_cond): Don't issue undefined overflow
+       warnings if TREE_NO_WARNING is set.
+       * doc/invoke.texi (Warning Options): Clarify that
+       -Wstrict-overflow does not warn about loops.
+
 2007-04-24  Janis Johnson  <janis187@us.ibm.com>
 
        * config/rs6000/rs6000.c (function_arg_advance): For 32-bit ELF ABI,
index c6ddd9fb4bb6c9d2e86bc581d8723135a4020013..cea120c1dc0194455900bf3d8f8a585f7dfde514 100644 (file)
@@ -3029,7 +3029,10 @@ perfectly safe if the values of the variables involved are such that
 overflow never does, in fact, occur.  Therefore this warning can
 easily give a false positive: a warning about code which is not
 actually a problem.  To help focus on important issues, several
-warning levels are defined.
+warning levels are defined.  No warnings are issued for the use of
+undefined signed overflow when estimating how many iterations a loop
+will require, in particular when determining whether a loop will be
+executed at all.
 
 @table @option
 @item -Wstrict-overflow=1
index 0504789f109ba910773e9139c0f413565e49faf4..6a69bff59d13e14e454fc01903f85405746e05e7 100644 (file)
@@ -1,3 +1,8 @@
+2007-04-24  Ian Lance Taylor  <iant@google.com>
+
+       PR tree-optimization/31602
+       * gcc.dg/Wstrict-overflow-11.c: We no longer issue a warning.
+
 2007-04-24  Janis Johnson  <janis187@us.ibm.com>
 
        * gcc.target/powerpc/ppc32-abi-dfp-1.c: New test.
index c98610e48a6d7ccb5f4cafed297e34b8efb4ae94..3caf1cb6f09fa56d7b9142983d62cd231d2a615c 100644 (file)
@@ -3,14 +3,16 @@
 
 /* Based on strict-overflow-5.c.  */
 
-/* We can only unroll when using strict overflow semantics.  */
+/* We can only unroll when using strict overflow semantics.  But we
+   don't issue a warning for relying on undefined overflow in
+   loops.  */
 
 int foo (int i)
 {
   int index;
   int r=0;
  
-  for (index = i; index <= i+4; index+=2) /* { dg-warning "assuming signed overflow does not occur" "correct warning" } */
+  for (index = i; index <= i+4; index+=2)
     r++;
  
   return r;
index 191d3101c549038565b64eea7e652afc669b224e..a621d9d6b0588b6199ff15468ff5bd8d35e2a43b 100644 (file)
@@ -416,7 +416,9 @@ fold_cond_expr_cond (void)
          cond = fold (COND_EXPR_COND (stmt));
          zerop = integer_zerop (cond);
          onep = integer_onep (cond);
-         fold_undefer_overflow_warnings (zerop || onep, stmt,
+         fold_undefer_overflow_warnings (((zerop || onep)
+                                          && !TREE_NO_WARNING (stmt)),
+                                         stmt,
                                          WARN_STRICT_OVERFLOW_CONDITIONAL);
          if (zerop)
            COND_EXPR_COND (stmt) = boolean_false_node;
index 3033c9082ef40a5483c0271b787d48f71d6e2612..e2e272b2266f2441054cca69aa5157ebdc0bb9ce 100644 (file)
@@ -1,5 +1,5 @@
 /* Loop header copying on trees.
-   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
    
 This file is part of GCC.
    
@@ -200,6 +200,27 @@ copy_loop_headers (void)
          continue;
        }
 
+      /* If the loop has the form "for (i = j; i < j + 10; i++)" then
+        this copying can introduce a case where we rely on undefined
+        signed overflow to eliminate the preheader condition, because
+        we assume that "j < j + 10" is true.  We don't want to warn
+        about that case for -Wstrict-overflow, because in general we
+        don't warn about overflow involving loops.  Prevent the
+        warning by setting TREE_NO_WARNING.  */
+      if (warn_strict_overflow > 0)
+       {
+         unsigned int i;
+
+         for (i = 0; i < n_bbs; ++i)
+           {
+             tree last;
+
+             last = last_stmt (copied_bbs[i]);
+             if (TREE_CODE (last) == COND_EXPR)
+               TREE_NO_WARNING (last) = 1;
+           }
+       }
+
       /* Ensure that the latch and the preheader is simple (we know that they
         are not now, since there was the loop exit condition.  */
       split_edge (loop_preheader_edge (loop));