From 8ebc39d80aceb9bf0e0a49160c3fe6843759bddb Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 13 May 2008 14:01:53 +0000 Subject: [PATCH] re PR middle-end/36227 (POINTER_PLUS folding introduces undefined overflow) 2008-05-13 Richard Guenther 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 | 6 ++++++ gcc/fold-const.c | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr36227.c | 12 ++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr36227.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cf2d013540f..efb05f229aa 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-05-13 Richard Guenther + + PR middle-end/36227 + * fold-const.c (fold_sign_changed_comparison): Do not allow + changes in pointer-ness. + 2008-05-12 Kaz Kojima PR target/24713 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 358a6166f17..c167bc4f670 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e870fb4bac3..199a80ea711 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-05-13 Richard Guenther + + PR middle-end/36227 + * gcc.dg/pr36227.c: New testcase. + 2008-05-13 Eric Botcazou * 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 index 00000000000..d6657632b91 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr36227.c @@ -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; +} + -- 2.30.2