public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5638] c++: don't fold away 'if' with constant condition
@ 2021-11-30 21:05 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-11-30 21:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:a3e75c1491cd2d501081210925a89a65b1c1e5e5

commit r12-5638-ga3e75c1491cd2d501081210925a89a65b1c1e5e5
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Nov 25 10:50:59 2021 -0500

    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.

Diff:
---
 gcc/cp/cp-gimplify.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 0988655eeba..0a002db14e7 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);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-30 21:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30 21:05 [gcc r12-5638] c++: don't fold away 'if' with constant condition Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).