diff options
author | Roger Sayle <roger@eyesopen.com> | 2002-10-30 23:07:48 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2002-10-30 23:07:48 +0000 |
commit | 9402f6fb7450c77691ef079abae90b2130a65117 (patch) | |
tree | d3d4b7bca2e8518146b0b70b1283cd27604f517d /gcc/fold-const.c | |
parent | 9b5b7e3a8fe143a9b1be4cfdb17fccc1e5ae58ff (diff) | |
download | gcc-9402f6fb7450c77691ef079abae90b2130a65117.zip gcc-9402f6fb7450c77691ef079abae90b2130a65117.tar.gz gcc-9402f6fb7450c77691ef079abae90b2130a65117.tar.bz2 |
fold-const.c (fold_binary_op_with_conditional_arg): Improve handling of cases where one or both branches of the conditional have...
* fold-const.c (fold_binary_op_with_conditional_arg): Improve
handling of cases where one or both branches of the conditional
have void type, i.e. throw an exception or don't return.
(fold): Only apply (and undo) type conversion to the non-void
branches of a COND_EXPR.
* f/com.c (ffecom_subscript_check_): Cast the failure branch
of the bounds check COND_EXPR to void, to indicate noreturn.
(ffe_truthvalue_conversion): Only apply truth value conversion
to the non-void branches of a COND_EXPR.
From-SVN: r58661
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 5f5e25f..c08d44e 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4456,15 +4456,23 @@ fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p) we simply build `a, throw 3'. */ if (VOID_TYPE_P (TREE_TYPE (true_value))) { - lhs_code = COMPOUND_EXPR; - if (!cond_first_p) - lhs_type = void_type_node; + if (! cond_first_p) + { + lhs_code = COMPOUND_EXPR; + lhs_type = void_type_node; + } + else + lhs = true_value; } if (VOID_TYPE_P (TREE_TYPE (false_value))) { - rhs_code = COMPOUND_EXPR; - if (!cond_first_p) - rhs_type = void_type_node; + if (! cond_first_p) + { + rhs_code = COMPOUND_EXPR; + rhs_type = void_type_node; + } + else + rhs = false_value; } } else @@ -4491,7 +4499,8 @@ fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p) if (TREE_CODE (arg) == SAVE_EXPR) save = 1; - else if (!TREE_CONSTANT (arg) + else if (lhs == 0 && rhs == 0 + && !TREE_CONSTANT (arg) && (*lang_hooks.decls.global_bindings_p) () == 0 && ((TREE_CODE (arg) != VAR_DECL && TREE_CODE (arg) != PARM_DECL) || TREE_SIDE_EFFECTS (arg))) @@ -4726,9 +4735,14 @@ fold (expr) fold (build1 (code, type, TREE_OPERAND (arg0, 1)))); else if (TREE_CODE (arg0) == COND_EXPR) { + tree arg01 = TREE_OPERAND (arg0, 1); + tree arg02 = TREE_OPERAND (arg0, 2); + if (! VOID_TYPE_P (TREE_TYPE (arg01))) + arg01 = fold (build1 (code, type, arg01)); + if (! VOID_TYPE_P (TREE_TYPE (arg02))) + arg02 = fold (build1 (code, type, arg02)); t = fold (build (COND_EXPR, type, TREE_OPERAND (arg0, 0), - fold (build1 (code, type, TREE_OPERAND (arg0, 1))), - fold (build1 (code, type, TREE_OPERAND (arg0, 2))))); + arg01, arg02)); /* If this was a conversion, and all we did was to move into inside the COND_EXPR, bring it back out. But leave it if @@ -4744,6 +4758,8 @@ fold (expr) && TREE_CODE (t) == COND_EXPR && TREE_CODE (TREE_OPERAND (t, 1)) == code && TREE_CODE (TREE_OPERAND (t, 2)) == code + && ! VOID_TYPE_P (TREE_OPERAND (t, 1)) + && ! VOID_TYPE_P (TREE_OPERAND (t, 2)) && (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 1), 0)) == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 2), 0))) && ! (INTEGRAL_TYPE_P (TREE_TYPE (t)) |