aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-11-25 10:50:59 -0500
committerJason Merrill <jason@redhat.com>2021-11-30 16:05:24 -0500
commita3e75c1491cd2d501081210925a89a65b1c1e5e5 (patch)
tree9efcd2c09b97a67d67d1ada9daa470d19b0a8c91
parent91c26004037db689954318d3d1c801eea18d45f4 (diff)
downloadgcc-a3e75c1491cd2d501081210925a89a65b1c1e5e5.zip
gcc-a3e75c1491cd2d501081210925a89a65b1c1e5e5.tar.gz
gcc-a3e75c1491cd2d501081210925a89a65b1c1e5e5.tar.bz2
c++: don't fold away 'if' with constant condition
richi's recent unreachable code warning experiments had trouble with the C++ front end folding away an 'if' with a constant condition. Let's do less folding at the statement level. gcc/cp/ChangeLog: * cp-gimplify.c (genericize_if_stmt): Always build a COND_EXPR.
-rw-r--r--gcc/cp/cp-gimplify.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 0988655..0a002db 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -166,11 +166,8 @@ genericize_if_stmt (tree *stmt_p)
can contain unfolded immediate function calls, we have to discard
the then_ block regardless of whether else_ has side-effects or not. */
if (IF_STMT_CONSTEVAL_P (stmt))
- stmt = else_;
- else if (integer_nonzerop (cond) && !TREE_SIDE_EFFECTS (else_))
- stmt = then_;
- else if (integer_zerop (cond) && !TREE_SIDE_EFFECTS (then_))
- stmt = else_;
+ stmt = build3 (COND_EXPR, void_type_node, boolean_false_node,
+ void_node, else_);
else
stmt = build3 (COND_EXPR, void_type_node, cond, then_, else_);
protected_set_expr_location_if_unset (stmt, locus);