This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR19854, ICE on valid
- From: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 9 Feb 2005 16:33:33 +0100 (CET)
- Subject: [PATCH] Fix PR19854, ICE on valid
This fixes the ICE on folding &a[i1] + c * i2 to &a[i1 + i2].
Bootstrapped and tested on x86_64-unknown-linux-gnu with no
regressions for all languages apart from treelang and ada.
Ok for mainline?
Richard.
2005-02-09 Richard Guenther <rguenth@gcc.gnu.org>
* fold-const.c (try_move_mult_to_index): Remove redundant
type argument. Create ADDR_EXPR with correct type.
(fold): Update callers of try_move_mult_to_index. Convert
result to the appropriate type.
* g++.dg/tree-ssa/tmmti.C: New testcase.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.502
diff -c -3 -p -r1.502 fold-const.c
*** fold-const.c 3 Feb 2005 06:44:34 -0000 1.502
--- fold-const.c 9 Feb 2005 13:41:07 -0000
*************** fold_sign_changed_comparison (enum tree_
*** 6172,6183 ****
}
/* Tries to replace &a[idx] CODE s * delta with &a[idx CODE delta], if s is
! step of the array. TYPE is the type of the expression. ADDR is the address.
! MULT is the multiplicative expression. If the function succeeds, the new
! address expression is returned. Otherwise NULL_TREE is returned. */
static tree
! try_move_mult_to_index (tree type, enum tree_code code, tree addr, tree mult)
{
tree s, delta, step;
tree arg0 = TREE_OPERAND (mult, 0), arg1 = TREE_OPERAND (mult, 1);
--- 6172,6183 ----
}
/* Tries to replace &a[idx] CODE s * delta with &a[idx CODE delta], if s is
! step of the array. ADDR is the address. MULT is the multiplicative expression.
! If the function succeeds, the new address expression is returned. Otherwise
! NULL_TREE is returned. */
static tree
! try_move_mult_to_index (enum tree_code code, tree addr, tree mult)
{
tree s, delta, step;
tree arg0 = TREE_OPERAND (mult, 0), arg1 = TREE_OPERAND (mult, 1);
*************** try_move_mult_to_index (tree type, enum
*** 6214,6220 ****
/* If the type sizes do not match, we might run into problems
when one of them would overflow. */
! if (TYPE_PRECISION (itype) != TYPE_PRECISION (type))
continue;
if (!operand_equal_p (step, fold_convert (itype, s), 0))
--- 6214,6220 ----
/* If the type sizes do not match, we might run into problems
when one of them would overflow. */
! if (TYPE_PRECISION (itype) != TYPE_PRECISION (TREE_TYPE (s)))
continue;
if (!operand_equal_p (step, fold_convert (itype, s), 0))
*************** try_move_mult_to_index (tree type, enum
*** 6246,6252 ****
TREE_OPERAND (pos, 1),
delta));
! return build1 (ADDR_EXPR, type, ret);
}
--- 6246,6252 ----
TREE_OPERAND (pos, 1),
delta));
! return build1 (ADDR_EXPR, TREE_TYPE (addr), ret);
}
*************** fold (tree expr)
*** 6944,6960 ****
if (TREE_CODE (arg0) == ADDR_EXPR
&& TREE_CODE (arg1) == MULT_EXPR)
{
! tem = try_move_mult_to_index (type, PLUS_EXPR, arg0, arg1);
if (tem)
! return fold (tem);
}
else if (TREE_CODE (arg1) == ADDR_EXPR
&& TREE_CODE (arg0) == MULT_EXPR)
{
! tem = try_move_mult_to_index (type, PLUS_EXPR, arg1, arg0);
if (tem)
! return fold (tem);
}
}
else
{
--- 6944,6961 ----
if (TREE_CODE (arg0) == ADDR_EXPR
&& TREE_CODE (arg1) == MULT_EXPR)
{
! tem = try_move_mult_to_index (PLUS_EXPR, arg0, arg1);
if (tem)
! return fold_convert (type, fold (tem));
}
else if (TREE_CODE (arg1) == ADDR_EXPR
&& TREE_CODE (arg0) == MULT_EXPR)
{
! tem = try_move_mult_to_index (PLUS_EXPR, arg1, arg0);
if (tem)
! return fold_convert (type, fold (tem));
}
+
}
else
{
*************** fold (tree expr)
*** 7332,7340 ****
if (TREE_CODE (arg0) == ADDR_EXPR
&& TREE_CODE (arg1) == MULT_EXPR)
{
! tem = try_move_mult_to_index (type, MINUS_EXPR, arg0, arg1);
if (tem)
! return fold (tem);
}
if (TREE_CODE (arg0) == MULT_EXPR
--- 7333,7341 ----
if (TREE_CODE (arg0) == ADDR_EXPR
&& TREE_CODE (arg1) == MULT_EXPR)
{
! tem = try_move_mult_to_index (MINUS_EXPR, arg0, arg1);
if (tem)
! return fold_convert (type, fold (tem));
}
if (TREE_CODE (arg0) == MULT_EXPR
/* { dg-do compile } */
void bar(unsigned int i)
{
int a[4];
char *p = (char*)&a[1] + 4*i;
}