From 0c6c135bb38bbf0f03087aa29a7e517319b4c241 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Wed, 9 Feb 2005 18:15:40 +0000 Subject: [PATCH] fold-const.c (try_move_mult_to_index): Remove redundant type argument. 2005-02-09 Richard Guenther * 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. From-SVN: r94767 --- gcc/ChangeLog | 8 ++++++++ gcc/fold-const.c | 24 ++++++++++++------------ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/tree-ssa/tmmti.C | 7 +++++++ 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/tmmti.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b8675fb..3399695 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2005-02-09 Richard Guenther + + PR middle-end/19854 + * 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. + 2005-02-09 Roger Sayle PR target/19597 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 1d2efbd..294f94c 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6172,12 +6172,12 @@ fold_sign_changed_comparison (enum tree_code code, tree type, } /* 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. */ + 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 (tree type, enum tree_code code, tree addr, tree mult) +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); @@ -6214,7 +6214,7 @@ try_move_mult_to_index (tree type, enum tree_code code, tree addr, tree mult) /* 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)) + if (TYPE_PRECISION (itype) != TYPE_PRECISION (TREE_TYPE (s))) continue; if (!operand_equal_p (step, fold_convert (itype, s), 0)) @@ -6246,7 +6246,7 @@ try_move_mult_to_index (tree type, enum tree_code code, tree addr, tree mult) TREE_OPERAND (pos, 1), delta)); - return build1 (ADDR_EXPR, type, ret); + return build1 (ADDR_EXPR, TREE_TYPE (addr), ret); } @@ -6944,16 +6944,16 @@ fold (tree expr) if (TREE_CODE (arg0) == ADDR_EXPR && TREE_CODE (arg1) == MULT_EXPR) { - tem = try_move_mult_to_index (type, PLUS_EXPR, arg0, arg1); + tem = try_move_mult_to_index (PLUS_EXPR, arg0, arg1); if (tem) - return fold (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 (type, PLUS_EXPR, arg1, arg0); + tem = try_move_mult_to_index (PLUS_EXPR, arg1, arg0); if (tem) - return fold (tem); + return fold_convert (type, fold (tem)); } } else @@ -7332,9 +7332,9 @@ fold (tree expr) if (TREE_CODE (arg0) == ADDR_EXPR && TREE_CODE (arg1) == MULT_EXPR) { - tem = try_move_mult_to_index (type, MINUS_EXPR, arg0, arg1); + tem = try_move_mult_to_index (MINUS_EXPR, arg0, arg1); if (tem) - return fold (tem); + return fold_convert (type, fold (tem)); } if (TREE_CODE (arg0) == MULT_EXPR diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5e9697f..135e31d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-02-09 Richard Guenther + + PR middle-end/19854 + * g++.dg/tree-ssa/tmmti.C: New testcase. + 2005-02-09 Joseph S. Myers * g++.dg/rtti/tinfo1.C: Allow newline after assembler label. diff --git a/gcc/testsuite/g++.dg/tree-ssa/tmmti.C b/gcc/testsuite/g++.dg/tree-ssa/tmmti.C new file mode 100644 index 0000000..111127b --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/tmmti.C @@ -0,0 +1,7 @@ +/* { dg-do compile } */ + +void bar(unsigned int i) +{ + int a[4]; + char *p = (char*)&a[1] + 4*i; +} -- 2.7.4