aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2003-08-29 02:50:10 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2003-08-29 02:50:10 +0000
commita1652802438d07879f83cc1f018f72fcabcba839 (patch)
tree78da144d2f561564fbbafd52691da9046e9cc06b
parent2be570f916a5bfa25b09f4acd44c14f5df662889 (diff)
downloadgcc-a1652802438d07879f83cc1f018f72fcabcba839.zip
gcc-a1652802438d07879f83cc1f018f72fcabcba839.tar.gz
gcc-a1652802438d07879f83cc1f018f72fcabcba839.tar.bz2
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
-rw-r--r--gcc/cp/ChangeLog3
-rw-r--r--gcc/cp/call.c2
-rw-r--r--gcc/cp/init.c18
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/expr/cond3.C6
5 files changed, 31 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 87857b2..402b177 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 739ce71..a74fd63 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -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. */
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 032959c..ace82cd 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -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)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3c76266..ea39a5d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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.
diff --git a/gcc/testsuite/g++.dg/expr/cond3.C b/gcc/testsuite/g++.dg/expr/cond3.C
new file mode 100644
index 0000000..50a4d9a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/expr/cond3.C
@@ -0,0 +1,6 @@
+const int i = 7;
+const int j = 3;
+
+void f(bool b) {
+ &(b ? i : j);
+}