re PR tree-optimization/48022 (-Wstrict-overflow warning on code that doesn't have...
authorJakub Jelinek <jakub@redhat.com>
Tue, 8 Mar 2011 10:43:10 +0000 (11:43 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 8 Mar 2011 10:43:10 +0000 (11:43 +0100)
PR tree-optimization/48022
* fold-const.c (fold_comparison): Don't call fold_overflow_warning
for EQ/NE_EXPR.

* gcc.dg/pr48022-1.c: New test.
* gcc.dg/pr48022-2.c: New test.

From-SVN: r170772

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr48022-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr48022-2.c [new file with mode: 0644]

index 8b1b64fc47e99bd0c506590d453b62b6a60f476c..ece9ec1638ecada4e4fc7727329dd44abfe3f2af 100644 (file)
@@ -1,3 +1,9 @@
+2011-03-08  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/48022
+       * fold-const.c (fold_comparison): Don't call fold_overflow_warning
+       for EQ/NE_EXPR.
+
 2011-03-07  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/47991
index 07b59d89a32af2d1c8a3b619b2b6823c3a16dff2..957049c0a46cdeba1a73366853b47f0c257c326b 100644 (file)
@@ -1,6 +1,6 @@
 /* Fold a constant sub-tree into a single node for C-compiler
    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -8572,10 +8572,11 @@ fold_comparison (location_t loc, enum tree_code code, tree type,
          && (TREE_CODE (lhs) != INTEGER_CST
              || !TREE_OVERFLOW (lhs)))
        {
-         fold_overflow_warning ("assuming signed overflow does not occur "
-                                 "when changing X +- C1 cmp C2 to "
-                                 "X cmp C1 +- C2",
-                                WARN_STRICT_OVERFLOW_COMPARISON);
+         if (code != EQ_EXPR && code != NE_EXPR)
+           fold_overflow_warning ("assuming signed overflow does not occur "
+                                  "when changing X +- C1 cmp C2 to "
+                                  "X cmp C1 +- C2",
+                                  WARN_STRICT_OVERFLOW_COMPARISON);
          return fold_build2_loc (loc, code, type, variable, lhs);
        }
     }
index bdf3ccac07081ca9408a3936719742ab568e12f7..7c8aad31abd1e2f163fa286e977d89081fa44cee 100644 (file)
@@ -1,3 +1,9 @@
+2011-03-08  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/48022
+       * gcc.dg/pr48022-1.c: New test.
+       * gcc.dg/pr48022-2.c: New test.
+
 2011-03-07  Jason Merrill  <jason@redhat.com>
 
        * g++.dg/template/nontype20.C: New.
diff --git a/gcc/testsuite/gcc.dg/pr48022-1.c b/gcc/testsuite/gcc.dg/pr48022-1.c
new file mode 100644 (file)
index 0000000..14eb550
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR tree-optimization/48022 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wstrict-overflow" } */
+
+int
+foo (const char *x)
+{
+  unsigned long l = 1;
+  const unsigned char *s = (const unsigned char *) (const char *) (x);
+  int r = s[0] - ((const unsigned char *) (const char *) ("/"))[0];
+  if (l > 0 && r == 0)
+    r = (s[1] - ((const unsigned char *) (const char *) ("/"))[1]);
+  return r;
+}
diff --git a/gcc/testsuite/gcc.dg/pr48022-2.c b/gcc/testsuite/gcc.dg/pr48022-2.c
new file mode 100644 (file)
index 0000000..41fcb53
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR tree-optimization/48022 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wstrict-overflow" } */
+
+#include <string.h>
+
+int
+foo (const char *x)
+{
+  return strcmp (x, "/");
+}