aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2017-04-04 09:06:04 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2017-04-04 09:06:04 +0000
commit248179b5fc812b294e2488b23fedaaabe099ad9d (patch)
tree46598b536dd7896cb9ef0ba26970bcac31af8696 /gcc/fold-const.c
parenta577fcf2d5ec9695efb5c086fd328cf378289a55 (diff)
downloadgcc-248179b5fc812b294e2488b23fedaaabe099ad9d.zip
gcc-248179b5fc812b294e2488b23fedaaabe099ad9d.tar.gz
gcc-248179b5fc812b294e2488b23fedaaabe099ad9d.tar.bz2
re PR tree-optimization/80281 (Wrong constant folding)
2017-04-04 Richard Biener <rguenther@suse.de> PR middle-end/80281 * match.pd (A + (-B) -> A - B): Make sure to preserve unsigned arithmetic done for the negate or the plus. Simplify. (A - (-B) -> A + B): Likewise. * fold-const.c (split_tree): Make sure to not negate pointers. * gcc.dg/torture/pr80281.c: New testcase. From-SVN: r246674
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index d0f1c06..b4c117c 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -831,8 +831,12 @@ split_tree (location_t loc, tree in, tree type, enum tree_code code,
/* Now do any needed negations. */
if (neg_litp_p)
*minus_litp = *litp, *litp = 0;
- if (neg_conp_p)
- *conp = negate_expr (*conp);
+ if (neg_conp_p && *conp)
+ {
+ /* Convert to TYPE before negating. */
+ *conp = fold_convert_loc (loc, type, *conp);
+ *conp = negate_expr (*conp);
+ }
if (neg_var_p && var)
{
/* Convert to TYPE before negating. */
@@ -859,7 +863,12 @@ split_tree (location_t loc, tree in, tree type, enum tree_code code,
*minus_litp = *litp, *litp = 0;
else if (*minus_litp)
*litp = *minus_litp, *minus_litp = 0;
- *conp = negate_expr (*conp);
+ if (*conp)
+ {
+ /* Convert to TYPE before negating. */
+ *conp = fold_convert_loc (loc, type, *conp);
+ *conp = negate_expr (*conp);
+ }
if (var)
{
/* Convert to TYPE before negating. */