https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106628

            Bug ID: 106628
           Summary: Missed folding with COMPOUND_EXPR due to C frontend
                    bugs
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

Doing

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 4f4ec81c8d4..698f115507a 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -12595,14 +12595,9 @@ fold_binary_loc (location_t loc, enum tree_code code,
tree type,
       return NULL_TREE;

     case COMPOUND_EXPR:
-      /* When pedantic, a compound expression can be neither an lvalue
-        nor an integer constant expression.  */
-      if (TREE_SIDE_EFFECTS (arg0) || TREE_CONSTANT (arg1))
+      if (TREE_SIDE_EFFECTS (arg0))
        return NULL_TREE;
-      /* Don't let (0, 0) be null pointer constant.  */
-      tem = integer_zerop (arg1) ? build1_loc (loc, NOP_EXPR, type, arg1)
-                                : fold_convert_loc (loc, type, arg1);
-      return tem;
+      return op1;

     case ASSERT_EXPR:
       /* An ASSERT_EXPR should never be passed to fold_binary.  */


results in missed diagnostics:

FAIL: gcc.dg/array-5.c bad vla handling (test for bogus messages, line 40)
FAIL: gcc.dg/c99-const-expr-12.c (test for excess errors)
FAIL: gcc.dg/pr61096-1.c  (test for errors, line 29)
FAIL: gcc.dg/pr61096-1.c (test for excess errors)

Reply via email to