OSDN Git Service

2008-05-13 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 13 May 2008 14:01:53 +0000 (14:01 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 13 May 2008 14:01:53 +0000 (14:01 +0000)
PR middle-end/36227
* fold-const.c (fold_sign_changed_comparison): Do not allow
changes in pointer-ness.

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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@135260 138bc75d-0d04-0410-961f-82ee72b054a4

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

index cf2d013..efb05f2 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 358a616..c167bc4 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 e870fb4..199a80e 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;
+}
+