This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR39937, wrong types in forwprop
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 28 Apr 2009 16:22:34 +0200 (CEST)
- Subject: [PATCH] Fix PR39937, wrong types in forwprop
We loose type conversions in array folding.
Fixed as follows.
Bootstrap / regtest pending.
Richard.
2009-04-28 Richard Guenther <rguenther@suse.de>
PR middle-end/39937
* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Do not
loose type conversions.
* gcc.c-torture/compile/pr39937.c: New testcase.
Index: gcc/tree-ssa-forwprop.c
===================================================================
*** gcc/tree-ssa-forwprop.c (revision 146887)
--- gcc/tree-ssa-forwprop.c (working copy)
*************** forward_propagate_addr_expr_1 (tree name
*** 862,871 ****
of the elements in X into &x[C1 + C2/element size]. */
if (TREE_CODE (rhs2) == INTEGER_CST)
{
! tree new_rhs = maybe_fold_stmt_addition (gimple_expr_type (use_stmt),
def_rhs, rhs2);
if (new_rhs)
{
gimple_assign_set_rhs_from_tree (use_stmt_gsi,
unshare_expr (new_rhs));
use_stmt = gsi_stmt (*use_stmt_gsi);
--- 862,874 ----
of the elements in X into &x[C1 + C2/element size]. */
if (TREE_CODE (rhs2) == INTEGER_CST)
{
! tree new_rhs = maybe_fold_stmt_addition (TREE_TYPE (def_rhs),
def_rhs, rhs2);
if (new_rhs)
{
+ tree type = TREE_TYPE (gimple_assign_lhs (use_stmt));
+ if (!useless_type_conversion_p (type, TREE_TYPE (new_rhs)))
+ new_rhs = fold_convert (type, new_rhs);
gimple_assign_set_rhs_from_tree (use_stmt_gsi,
unshare_expr (new_rhs));
use_stmt = gsi_stmt (*use_stmt_gsi);
Index: gcc/testsuite/gcc.c-torture/compile/pr39937.c
===================================================================
*** gcc/testsuite/gcc.c-torture/compile/pr39937.c (revision 0)
--- gcc/testsuite/gcc.c-torture/compile/pr39937.c (revision 0)
***************
*** 0 ****
--- 1,12 ----
+ int foo (__const char *__restrict __s);
+ static void
+ read_anisou(char line[])
+ {
+ foo (line+1);
+ }
+ void
+ read_pdbfile(void)
+ {
+ char line[4096];
+ read_anisou (line);
+ }