From f7d1e0c6cb12146eaddeac1386e1a5b9394f5955 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 21 Aug 2007 09:18:15 +0000 Subject: [PATCH] fold-const.c (fold_binary): Revert removing of index +p PTR 2007-08-21 Richard Guenther * fold-const.c (fold_binary): Revert removing of index +p PTR * folding. * gcc.dg/pointer-arith-10.c: New testcase. From-SVN: r127660 --- gcc/ChangeLog | 4 ++++ gcc/fold-const.c | 7 +++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/pointer-arith-10.c | 10 ++++++++++ 4 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pointer-arith-10.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8223bdd3797..aa40fb4d138 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2007-08-21 Richard Guenther + + * fold-const.c (fold_binary): Revert removing of index +p PTR folding. + 2007-08-21 Richard Guenther PR middle-end/33122 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 8faf77d8751..33467eb88f2 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) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 29500ed8fdf..9f0b0c8584d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2007-08-21 Richard Guenther + + * gcc.dg/pointer-arith-10.c: New testcase. + 2007-08-21 Richard Guenther PR middle-end/33122 diff --git a/gcc/testsuite/gcc.dg/pointer-arith-10.c b/gcc/testsuite/gcc.dg/pointer-arith-10.c new file mode 100644 index 00000000000..220891e2097 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pointer-arith-10.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-original" } */ + +char *foo(char *p, __SIZE_TYPE__ i) +{ + return (char *)i + (__SIZE_TYPE__)p; +} + +/* { dg-final { scan-tree-dump "p +" "original" } } */ +/* { dg-final { cleanup-tree-dump "original" } } */