diff options
author | Dale Johannesen <dalej@gcc.gnu.org> | 2005-01-31 18:00:52 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@gcc.gnu.org> | 2005-01-31 18:00:52 +0000 |
commit | 3b70b82ab91b33eaa01866cce11853ff60ad780c (patch) | |
tree | c1d172e58eba26c1ee44c265c85f4c1494fbb719 /gcc/fold-const.c | |
parent | c0736a9ddbfc1651bd3c5602cccade4e9f69f3bd (diff) | |
download | gcc-3b70b82ab91b33eaa01866cce11853ff60ad780c.zip gcc-3b70b82ab91b33eaa01866cce11853ff60ad780c.tar.gz gcc-3b70b82ab91b33eaa01866cce11853ff60ad780c.tar.bz2 |
re PR middle-end/19650 (miscompiling of array acess of (int)(a==2))
2005-01-31 Roger Sayle <roger@eyesopen.com>
Dale Johannesen <dalej@apple.com>
PR middle-end/19650
* fold-const.c (fold_binary_op_with_conditional_arg):
Make types match original operands, before STRIP_NOPS.
From-SVN: r94485
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 5d6e713..13c57e0 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -121,8 +121,8 @@ static tree optimize_minmax_comparison (tree); static tree extract_muldiv (tree, tree, enum tree_code, tree); static tree extract_muldiv_1 (tree, tree, enum tree_code, tree); static int multiple_of_p (tree, tree, tree); -static tree fold_binary_op_with_conditional_arg (enum tree_code, tree, tree, - tree, int); +static tree fold_binary_op_with_conditional_arg (tree, enum tree_code, + tree, tree, int); static bool fold_real_zero_addition_p (tree, tree, int); static tree fold_mathfn_compare (enum built_in_function, enum tree_code, tree, tree, tree); @@ -5435,9 +5435,14 @@ extract_array_ref (tree expr, tree *base, tree *offset) possible. */ static tree -fold_binary_op_with_conditional_arg (enum tree_code code, tree type, - tree cond, tree arg, int cond_first_p) +fold_binary_op_with_conditional_arg (tree t, enum tree_code code, tree cond, + tree arg, int cond_first_p) { + const tree type = TREE_TYPE (t); + tree cond_type = cond_first_p ? TREE_TYPE (TREE_OPERAND (t, 0)) + : TREE_TYPE (TREE_OPERAND (t, 1)); + tree arg_type = cond_first_p ? TREE_TYPE (TREE_OPERAND (t, 1)) + : TREE_TYPE (TREE_OPERAND (t, 0)); tree test, true_value, false_value; tree lhs = NULL_TREE; tree rhs = NULL_TREE; @@ -5469,12 +5474,19 @@ fold_binary_op_with_conditional_arg (enum tree_code code, tree type, false_value = constant_boolean_node (false, testtype); } + arg = fold_convert (arg_type, arg); if (lhs == 0) - lhs = fold (cond_first_p ? build2 (code, type, true_value, arg) + { + true_value = fold_convert (cond_type, true_value); + lhs = fold (cond_first_p ? build2 (code, type, true_value, arg) : build2 (code, type, arg, true_value)); + } if (rhs == 0) - rhs = fold (cond_first_p ? build2 (code, type, false_value, arg) + { + false_value = fold_convert (cond_type, false_value); + rhs = fold (cond_first_p ? build2 (code, type, false_value, arg) : build2 (code, type, arg, false_value)); + } test = fold (build3 (COND_EXPR, type, test, lhs, rhs)); return fold_convert (type, test); @@ -6516,7 +6528,7 @@ fold (tree expr) if (TREE_CODE (arg0) == COND_EXPR || COMPARISON_CLASS_P (arg0)) { - tem = fold_binary_op_with_conditional_arg (code, type, arg0, arg1, + tem = fold_binary_op_with_conditional_arg (t, code, arg0, arg1, /*cond_first_p=*/1); if (tem != NULL_TREE) return tem; @@ -6524,8 +6536,8 @@ fold (tree expr) if (TREE_CODE (arg1) == COND_EXPR || COMPARISON_CLASS_P (arg1)) { - tem = fold_binary_op_with_conditional_arg (code, type, arg1, arg0, - /*cond_first_p=*/0); + tem = fold_binary_op_with_conditional_arg (t, code, arg1, arg0, + /*cond_first_p=*/0); if (tem != NULL_TREE) return tem; } |