* fold-const.c (fold_binary): Revert removing of index +p PTR
* folding.
* gcc.dg/pointer-arith-10.c: New testcase.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127660
138bc75d-0d04-0410-961f-
82ee72b054a4
2007-08-21 Richard Guenther <rguenther@suse.de>
+ * fold-const.c (fold_binary): Revert removing of index +p PTR folding.
+
+2007-08-21 Richard Guenther <rguenther@suse.de>
+
PR middle-end/33122
* fold-const.c (fold_binary): Remove index +p PTR folding.
Fix types of POINTER_PLUS_EXPR generated by folding of
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)
{
2007-08-21 Richard Guenther <rguenther@suse.de>
+ * gcc.dg/pointer-arith-10.c: New testcase.
+
+2007-08-21 Richard Guenther <rguenther@suse.de>
+
PR middle-end/33122
* gcc.c-torture/compile/pr33122.c: New testcase.
--- /dev/null
+/* { 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" } } */