Bug 106628 - Missed folding with COMPOUND_EXPR due to C frontend bugs
Summary: Missed folding with COMPOUND_EXPR due to C frontend bugs
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, missed-optimization
Depends on:
Blocks:
 
Reported: 2022-08-15 13:57 UTC by Richard Biener
Modified: 2022-08-15 16:04 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-08-15 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2022-08-15 13:57:05 UTC
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)
Comment 1 Andrew Pinski 2022-08-15 16:04:30 UTC
Confirmed.