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
This commit is contained in:
Mark Mitchell 2003-08-29 02:50:10 +00:00 committed by Mark Mitchell
parent 2be570f916
commit a165280243
5 changed files with 31 additions and 2 deletions

View File

@ -1,5 +1,8 @@
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.

View File

@ -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. */

View File

@ -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)

View File

@ -1,3 +1,7 @@
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.

View File

@ -0,0 +1,6 @@
const int i = 7;
const int j = 3;
void f(bool b) {
&(b ? i : j);
}