aboutsummaryrefslogtreecommitdiff
path: root/gcc/match.pd
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-01-18 09:29:14 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2018-01-18 09:29:14 +0100
commit8ae438811f695dd025fb1fef254bff920777b494 (patch)
tree3ebe287328aa2352463c380f91f601c2002085b1 /gcc/match.pd
parentfcf7923742d34c0cb7270594d4cdab4ea1199672 (diff)
downloadgcc-8ae438811f695dd025fb1fef254bff920777b494.zip
gcc-8ae438811f695dd025fb1fef254bff920777b494.tar.gz
gcc-8ae438811f695dd025fb1fef254bff920777b494.tar.bz2
re PR c/61240 (Incorrect warning "integer overflow in expression" on pointer-pointer subtraction)
PR c/61240 * match.pd ((P + A) - P, P - (P + A), (P + A) - (P + B)): For pointer_diff optimizations use view_convert instead of convert. * gcc.dg/pr61240.c: New test. From-SVN: r256838
Diffstat (limited to 'gcc/match.pd')
-rw-r--r--gcc/match.pd16
1 files changed, 13 insertions, 3 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 3f6e009..b288a36 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1832,7 +1832,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* The second argument of pointer_plus must be interpreted as signed, and
thus sign-extended if necessary. */
(with { tree stype = signed_type_for (TREE_TYPE (@1)); }
- (convert (convert:stype @1))))
+ /* Use view_convert instead of convert here, as POINTER_PLUS_EXPR
+ second arg is unsigned even when we need to consider it as signed,
+ we don't want to diagnose overflow here. */
+ (convert (view_convert:stype @1))))
/* (T)P - (T)(P + A) -> -(T) A */
(simplify
@@ -1876,7 +1879,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* The second argument of pointer_plus must be interpreted as signed, and
thus sign-extended if necessary. */
(with { tree stype = signed_type_for (TREE_TYPE (@1)); }
- (negate (convert (convert:stype @1)))))
+ /* Use view_convert instead of convert here, as POINTER_PLUS_EXPR
+ second arg is unsigned even when we need to consider it as signed,
+ we don't want to diagnose overflow here. */
+ (negate (convert (view_convert:stype @1)))))
/* (T)(P + A) - (T)(P + B) -> (T)A - (T)B */
(simplify
@@ -1927,7 +1933,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* The second argument of pointer_plus must be interpreted as signed, and
thus sign-extended if necessary. */
(with { tree stype = signed_type_for (TREE_TYPE (@1)); }
- (minus (convert (convert:stype @1)) (convert (convert:stype @2)))))))
+ /* Use view_convert instead of convert here, as POINTER_PLUS_EXPR
+ second arg is unsigned even when we need to consider it as signed,
+ we don't want to diagnose overflow here. */
+ (minus (convert (view_convert:stype @1))
+ (convert (view_convert:stype @2)))))))
/* Simplifications of MIN_EXPR, MAX_EXPR, fmin() and fmax(). */