Commit 9402f6fb by Roger Sayle Committed by Roger Sayle

fold-const.c (fold_binary_op_with_conditional_arg): Improve handling of cases…

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
parent 9b5b7e3a
2002-10-30 Roger Sayle <roger@eyesopen.com>
* 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.
2002-10-30 Mark Mitchell <mark@codesourcery.com>
PR c++/8333
......
2002-10-30 Roger Sayle <roger@eyesopen.com>
* 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.
2002-10-26 Andris Pavenis <pavenis@latnet.lv>
* lang-specs.h: Fix ratfor specs.
......
......@@ -806,6 +806,7 @@ ffecom_subscript_check_ (tree array, tree element, int dim, int total_dims,
die = ffecom_call_gfrt (FFECOM_gfrtRANGE,
args, NULL_TREE);
TREE_SIDE_EFFECTS (die) = 1;
die = convert (void_type_node, die);
element = ffecom_3 (COND_EXPR,
TREE_TYPE (element),
......@@ -14772,10 +14773,17 @@ ffe_truthvalue_conversion (expr)
return ffe_truthvalue_conversion (TREE_OPERAND (expr, 0));
case COND_EXPR:
/* Distribute the conversion into the arms of a COND_EXPR. */
return fold (build (COND_EXPR, integer_type_node, TREE_OPERAND (expr, 0),
ffe_truthvalue_conversion (TREE_OPERAND (expr, 1)),
ffe_truthvalue_conversion (TREE_OPERAND (expr, 2))));
{
/* Distribute the conversion into the arms of a COND_EXPR. */
tree arg1 = TREE_OPERAND (expr, 1);
tree arg2 = TREE_OPERAND (expr, 2);
if (! VOID_TYPE_P (TREE_TYPE (arg1)))
arg1 = ffe_truthvalue_conversion (arg1);
if (! VOID_TYPE_P (TREE_TYPE (arg2)))
arg2 = ffe_truthvalue_conversion (arg2);
return fold (build (COND_EXPR, integer_type_node,
TREE_OPERAND (expr, 0), arg1, arg2));
}
case CONVERT_EXPR:
/* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
......
......@@ -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))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment