diff options
author | Paolo Bonzini <bonzini@gnu.org> | 2009-04-24 10:29:18 +0000 |
---|---|---|
committer | Paolo Bonzini <bonzini@gcc.gnu.org> | 2009-04-24 10:29:18 +0000 |
commit | 30349c7400289ab4b00f07c73a2d630bb28f3b23 (patch) | |
tree | eeeac29485c66b9f6da709cfda3303b2e42fab32 /gcc/fold-const.c | |
parent | 8d8256c19709b2ec4a2231f2e1b320966b503b3d (diff) | |
download | gcc-30349c7400289ab4b00f07c73a2d630bb28f3b23.zip gcc-30349c7400289ab4b00f07c73a2d630bb28f3b23.tar.gz gcc-30349c7400289ab4b00f07c73a2d630bb28f3b23.tar.bz2 |
re PR middle-end/39867 (Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp)
2009-04-24 Paolo Bonzini <bonzini@gnu.org>
PR middle-end/39867
* fold-const.c (fold_cond_expr_with_comparison): When folding
> and >= to MAX, make sure the MAX uses the same type as the
comparison operands.
testsuite:
2009-04-24 Paolo Bonzini <bonzini@gnu.org>
PR middle-end/39867
* gcc.dg/pr39867.c: New.
From-SVN: r146695
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index f0ff5b6..9a2687a 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -5337,31 +5337,34 @@ fold_cond_expr_with_comparison (tree type, tree arg0, tree arg1, tree arg2) break; case GT_EXPR: - /* If C1 is C2 - 1, this is max(A, C2). */ + /* If C1 is C2 - 1, this is max(A, C2), but use ARG00's type for + MAX_EXPR, to preserve the signedness of the comparison. */ if (! operand_equal_p (arg2, TYPE_MIN_VALUE (type), OEP_ONLY_CONST) && operand_equal_p (arg01, const_binop (MINUS_EXPR, arg2, build_int_cst (type, 1), 0), OEP_ONLY_CONST)) - return pedantic_non_lvalue (fold_build2 (MAX_EXPR, - type, - fold_convert (type, arg1), - arg2)); + return pedantic_non_lvalue (fold_convert (type, + fold_build2 (MAX_EXPR, TREE_TYPE (arg00), + arg00, + fold_convert (TREE_TYPE (arg00), + arg2)))); break; case GE_EXPR: - /* If C1 is C2 + 1, this is max(A, C2). */ + /* If C1 is C2 + 1, this is max(A, C2), with the same care as above. */ if (! operand_equal_p (arg2, TYPE_MAX_VALUE (type), OEP_ONLY_CONST) && operand_equal_p (arg01, const_binop (PLUS_EXPR, arg2, build_int_cst (type, 1), 0), OEP_ONLY_CONST)) - return pedantic_non_lvalue (fold_build2 (MAX_EXPR, - type, - fold_convert (type, arg1), - arg2)); + return pedantic_non_lvalue (fold_convert (type, + fold_build2 (MAX_EXPR, TREE_TYPE (arg00), + arg00, + fold_convert (TREE_TYPE (arg00), + arg2)))); break; case NE_EXPR: break; |