re PR middle-end/36227 (POINTER_PLUS folding introduces undefined overflow)
authorRichard Guenther <rguenther@suse.de>
Tue, 13 May 2008 14:01:53 +0000 (14:01 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 13 May 2008 14:01:53 +0000 (14:01 +0000)
2008-05-13  Richard Guenther  <rguenther@suse.de>

PR middle-end/36227
* fold-const.c (fold_sign_changed_comparison): Do not allow
changes in pointer-ness.

* gcc.dg/pr36227.c: New testcase.

From-SVN: r135260

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

index cf2d013540f5e281eae626b44f2f5578b065253e..efb05f229aa7fa270a7d35be7d9f57032c6d7d9c 100644 (file)
@@ -1,3 +1,9 @@
+2008-05-13  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/36227
+       * fold-const.c (fold_sign_changed_comparison): Do not allow
+       changes in pointer-ness.
+
 2008-05-12  Kaz Kojima  <kkojima@gcc.gnu.org>
 
        PR target/24713
index 358a6166f177f957c6d881cfcc586ba5d0c25519..c167bc4f6706ae3fe8b86c16a46bc8c12c0a58ae 100644 (file)
@@ -6831,7 +6831,8 @@ fold_sign_changed_comparison (enum tree_code code, tree type,
           && TREE_TYPE (TREE_OPERAND (arg1, 0)) == inner_type))
     return NULL_TREE;
 
-  if (TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
+  if ((TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
+       || POINTER_TYPE_P (inner_type) != POINTER_TYPE_P (outer_type))
       && code != NE_EXPR
       && code != EQ_EXPR)
     return NULL_TREE;
index e870fb4bac3b41019fa0bb381904e754a34a5e80..199a80ea711e13150cf477942d4c397245161904 100644 (file)
@@ -1,3 +1,8 @@
+2008-05-13  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/36227
+       * gcc.dg/pr36227.c: New testcase.
+
 2008-05-13  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/discr7.adb: New test
diff --git a/gcc/testsuite/gcc.dg/pr36227.c b/gcc/testsuite/gcc.dg/pr36227.c
new file mode 100644 (file)
index 0000000..d665763
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wstrict-overflow=3" } */
+
+volatile unsigned long *
+sat_add(volatile unsigned long *ptr, unsigned long i, volatile unsigned long *end)
+{
+  if ((unsigned long)ptr + i * sizeof(*ptr) > (unsigned long)ptr) /* { dg-bogus "pointer wraparound" } */
+    return ptr + i;
+  else
+    return end;
+}
+