This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR33122, wrong types with pointer-plus
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 21 Aug 2007 10:22:18 +0200 (CEST)
- Subject: [PATCH] Fix PR33122, wrong types with pointer-plus
The folding for (PTR +p B) +p A generates wrong types for the resulting
POINTER_PLUS_EXPR. This is what fixes it. I took care to also remove
a folding that never can trigger due to the assert in build2_stat.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to mainline.
Richard.
2007-08-20 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
(PTR +p B) +p A.
Index: fold-const.c
===================================================================
*** fold-const.c (revision 127644)
--- fold-const.c (working copy)
*************** fold_binary (enum tree_code code, tree t
*** 9528,9547 ****
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)
{
tree inner;
tree arg01 = fold_convert (sizetype, TREE_OPERAND (arg0, 1));
tree arg00 = TREE_OPERAND (arg0, 0);
! inner = fold_build2 (PLUS_EXPR, sizetype, arg01, fold_convert (sizetype, arg1));
! return fold_build2 (POINTER_PLUS_EXPR, type, arg00, inner);
}
/* PTR_CST +p CST -> CST1 */
--- 9534,9550 ----
fold_convert (sizetype, arg1),
fold_convert (sizetype, arg0)));
/* (PTR +p B) +p A -> PTR +p (B + A) */
if (TREE_CODE (arg0) == POINTER_PLUS_EXPR)
{
tree inner;
tree arg01 = fold_convert (sizetype, TREE_OPERAND (arg0, 1));
tree arg00 = TREE_OPERAND (arg0, 0);
! inner = fold_build2 (PLUS_EXPR, sizetype,
! arg01, fold_convert (sizetype, arg1));
! return fold_convert (type,
! fold_build2 (POINTER_PLUS_EXPR,
! TREE_TYPE (arg00), arg00, inner));
}
/* PTR_CST +p CST -> CST1 */
*************** fold_binary (enum tree_code code, tree t
*** 9559,9564 ****
--- 9562,9568 ----
}
return NULL_TREE;
+
case PLUS_EXPR:
/* PTR + INT -> (INT)(PTR p+ INT) */
if (POINTER_TYPE_P (TREE_TYPE (arg0))
Index: testsuite/gcc.c-torture/compile/pr33122.c
===================================================================
--- testsuite/gcc.c-torture/compile/pr33122.c (revision 0)
+++ testsuite/gcc.c-torture/compile/pr33122.c (revision 0)
@@ -0,0 +1,14 @@
+struct dis386 {
+ const char *x;
+};
+
+static const struct dis386 float_reg[][2] = {
+ { { "fadd" }, { "fadd" } },
+};
+
+void foo(int i, int j)
+{
+ const struct dis386 *dp;
+
+ dp = &float_reg[i - 1][j];
+}