Commit a1652802 by Mark Mitchell Committed by Mark Mitchell

init.c (decl_constant_value): Deal with COND_EXPR specially.

	* init.c (decl_constant_value): Deal with COND_EXPR specially.
	* call.c (build_conditional_expr): Revert previous patch.

	* g++.dg/expr/cond3.C: New test.

From-SVN: r70899
parent 2be570f9
2003-08-28 Mark Mitchell <mark@codesourcery.com>
* init.c (decl_constant_value): Deal with COND_EXPR specially.
* call.c (build_conditional_expr): Revert previous patch.
PR optimization/5079
* call.c (build_conditional_expr): Use decl_constant_value to
simplify the arguments.
......
......@@ -3358,8 +3358,6 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3)
}
valid_operands:
arg2 = decl_constant_value (arg2);
arg3 = decl_constant_value (arg3);
result = fold (build (COND_EXPR, result_type, arg1, arg2, arg3));
/* We can't use result_type below, as fold might have returned a
throw_expr. */
......
......@@ -1587,6 +1587,24 @@ build_offset_ref (tree type, tree name, bool address_p)
tree
decl_constant_value (tree decl)
{
/* When we build a COND_EXPR, we don't know whether it will be used
as an lvalue or as an rvalue. If it is an lvalue, it's not safe
to replace the second and third operands with their
initializers. So, we do that here. */
if (TREE_CODE (decl) == COND_EXPR)
{
tree d1;
tree d2;
d1 = decl_constant_value (TREE_OPERAND (decl, 1));
d2 = decl_constant_value (TREE_OPERAND (decl, 2));
if (d1 != TREE_OPERAND (decl, 1) || d2 != TREE_OPERAND (decl, 2))
return build (COND_EXPR,
TREE_TYPE (decl),
TREE_OPERAND (decl, 0), d1, d2);
}
if (TREE_READONLY_DECL_P (decl)
&& ! TREE_THIS_VOLATILE (decl)
&& DECL_INITIAL (decl)
......
2003-08-28 Mark Mitchell <mark@codesourcery.com>
* g++.dg/expr/cond3.C: New test.
2003-08-28 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* gcc.dg/builtins-1.c: Add new builtin cases.
......
const int i = 7;
const int j = 3;
void f(bool b) {
&(b ? i : j);
}
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