aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2007-08-21 09:18:15 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2007-08-21 09:18:15 +0000
commitf7d1e0c6cb12146eaddeac1386e1a5b9394f5955 (patch)
treeda8009658e74e845d6bc8c65006d9ea505a606a8 /gcc/fold-const.c
parent8015455a87e3e516d3238fb3231ab50214234289 (diff)
downloadgcc-f7d1e0c6cb12146eaddeac1386e1a5b9394f5955.zip
gcc-f7d1e0c6cb12146eaddeac1386e1a5b9394f5955.tar.gz
gcc-f7d1e0c6cb12146eaddeac1386e1a5b9394f5955.tar.bz2
fold-const.c (fold_binary): Revert removing of index +p PTR
2007-08-21 Richard Guenther <rguenther@suse.de> * fold-const.c (fold_binary): Revert removing of index +p PTR * folding. * gcc.dg/pointer-arith-10.c: New testcase. From-SVN: r127660
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 8faf77d..33467eb 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -9528,6 +9528,13 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
fold_convert (sizetype, arg1),
fold_convert (sizetype, arg0)));
+ /* index +p PTR -> PTR +p index */
+ if (POINTER_TYPE_P (TREE_TYPE (arg1))
+ && INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
+ return fold_build2 (POINTER_PLUS_EXPR, type,
+ fold_convert (type, arg1),
+ fold_convert (sizetype, arg0));
+
/* (PTR +p B) +p A -> PTR +p (B + A) */
if (TREE_CODE (arg0) == POINTER_PLUS_EXPR)
{