aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2008-04-14 19:18:31 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2008-04-14 19:18:31 +0000
commit4c9db6e07aba115c21ab02068ccc332ce691775e (patch)
tree5476839d99a5b4e7b501ffa138ec06b5cc5cb144 /gcc/fold-const.c
parent3a5a8be12000125f4c12efea8bd6a466049a688d (diff)
downloadgcc-4c9db6e07aba115c21ab02068ccc332ce691775e.zip
gcc-4c9db6e07aba115c21ab02068ccc332ce691775e.tar.gz
gcc-4c9db6e07aba115c21ab02068ccc332ce691775e.tar.bz2
flags.h (POINTER_TYPE_OVERFLOW_UNDEFINED): Define.
gcc/: * flags.h (POINTER_TYPE_OVERFLOW_UNDEFINED): Define. * fold-const.c (fold_comparison): If appropriate, test POINTER_TYPE_OVERFLOW_UNDEFINED, and issue an overflow warning. (fold_binary): Test POINTER_TYPE_OVERFLOW_UNDEFINED when reassociating a pointer type. * doc/invoke.texi (Optimize Options): Document that -fstrict-overflow applies to pointer wraparound. gcc/testsuite/: * gcc.dg/strict-overflow-6.c: New. * gcc.dg/no-strict-overflow-7.c: New. * gcc.dg/Wstrict-overflow-22.c: New. From-SVN: r134287
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 66e72a7..ce5673e 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8568,7 +8568,9 @@ fold_comparison (enum tree_code code, tree type, tree op0, tree op1)
because pointer arithmetic is restricted to retain within an
object and overflow on pointer differences is undefined as of
6.5.6/8 and /9 with respect to the signed ptrdiff_t. */
- else if (bitpos0 == bitpos1)
+ else if (bitpos0 == bitpos1
+ && ((code == EQ_EXPR || code == NE_EXPR)
+ || POINTER_TYPE_OVERFLOW_UNDEFINED))
{
tree signed_size_type_node;
signed_size_type_node = signed_type_for (size_type_node);
@@ -8587,6 +8589,12 @@ fold_comparison (enum tree_code code, tree type, tree op0, tree op1)
else
offset1 = fold_convert (signed_size_type_node, offset1);
+ if (code != EQ_EXPR && code != NE_EXPR)
+ fold_overflow_warning (("assuming pointer wraparound does not "
+ "occur when comparing P +- C1 with "
+ "P +- C2"),
+ WARN_STRICT_OVERFLOW_COMPARISON);
+
return fold_build2 (code, type, offset0, offset1);
}
}
@@ -9711,7 +9719,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
/* With undefined overflow we can only associate constants
with one variable. */
- if ((POINTER_TYPE_P (type)
+ if (((POINTER_TYPE_P (type) && POINTER_TYPE_OVERFLOW_UNDEFINED)
|| (INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_WRAPS (type)))
&& var0 && var1)
{