From: rguenth Date: Thu, 12 Jul 2007 10:27:51 +0000 (+0000) Subject: 2007-07-12 Richard Guenther X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=299888457f91c854ff9ce63d1cd004d7d7df1bc1;ds=sidebyside 2007-07-12 Richard Guenther * gimplify.c (gimplify_conversion): Make sure that the result from maybe_fold_offset_to_reference is trivially convertible to the desired type before doing the simplification. (gimplify_expr): Likewise. * fold-const.c (fold_binary): Use the correct types for building the simplified expression. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@126577 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b31134fe915..13c869f8fcc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2007-07-12 Richard Guenther + + * gimplify.c (gimplify_conversion): Make sure that the result + from maybe_fold_offset_to_reference is trivially convertible + to the desired type before doing the simplification. + (gimplify_expr): Likewise. + * fold-const.c (fold_binary): Use the correct types for + building the simplified expression. + 2007-07-12 Zdenek Dvorak PR rtl-optimization/32729 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 652fd177fba..bff47251c8a 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10271,7 +10271,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) if (integer_zerop (arg1)) return non_lvalue (fold_convert (type, arg0)); if (integer_all_onesp (arg1)) - return fold_build1 (BIT_NOT_EXPR, type, arg0); + return fold_build1 (BIT_NOT_EXPR, type, op0); if (operand_equal_p (arg0, arg1, 0)) return omit_one_operand (type, integer_zero_node, arg0); @@ -10865,7 +10865,8 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) "when distributing negation across " "division"), WARN_STRICT_OVERFLOW_MISC); - return fold_build2 (code, type, TREE_OPERAND (arg0, 0), + return fold_build2 (code, type, + fold_convert (type, TREE_OPERAND (arg0, 0)), negate_expr (arg1)); } if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type)) diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 3b5fa895238..12ed309538b 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1648,7 +1648,11 @@ gimplify_conversion (tree *expr_p) && (tem = maybe_fold_offset_to_reference (TREE_OPERAND (*expr_p, 0), integer_zero_node, TREE_TYPE (TREE_TYPE (*expr_p))))) - *expr_p = build_fold_addr_expr_with_type (tem, TREE_TYPE (*expr_p)); + { + tree ptr_type = build_pointer_type (TREE_TYPE (tem)); + if (useless_type_conversion_p (TREE_TYPE (*expr_p), ptr_type)) + *expr_p = build_fold_addr_expr_with_type (tem, ptr_type); + } /* If we still have a conversion at the toplevel, then canonicalize some constructs. */ @@ -5987,9 +5991,12 @@ gimplify_expr (tree *expr_p, tree *pre_p, tree *post_p, (TREE_OPERAND (*expr_p, 0), TREE_OPERAND (*expr_p, 1), TREE_TYPE (TREE_TYPE (*expr_p))))) { - *expr_p = build_fold_addr_expr_with_type (tmp, - TREE_TYPE (*expr_p)); - break; + tree ptr_type = build_pointer_type (TREE_TYPE (tmp)); + if (useless_type_conversion_p (TREE_TYPE (*expr_p), ptr_type)) + { + *expr_p = build_fold_addr_expr_with_type (tmp, ptr_type); + break; + } } /* Convert (void *)&a + 4 into (void *)&a[1]. */ if (TREE_CODE (TREE_OPERAND (*expr_p, 0)) == NOP_EXPR