From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DDBAE3858401; Tue, 7 Dec 2021 12:09:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDBAE3858401 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/103597] [12 Regression] False -Wimplicit-fallthrough= involving macro since r12-5638-ga3e75c1491cd2d50 Date: Tue, 07 Dec 2021 12:09:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Dec 2021 12:09:30 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103597 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org, | |mpolacek at gcc dot gnu.org --- Comment #4 from Jakub Jelinek --- -Wimplicit-fallthrough is performed on the freshly gimplified IL, so cxx_block_may_fallthru is irrelevant to it. And so it sees switch (n) , case 0: , case 1: > : if (1 !=3D 0) goto ; else goto ; : D.1986 =3D 0; // predicted unlikely by early return (on trees) predictor. return D.1986; : : D.1986 =3D 1; return D.1986; : D.1986 =3D 2; return D.1986; where it sees that : falls through to : aka case 1:, and because this is done before cfg is created, we can't cheaply go back and see that D.1985 is only reachable from else of if (1). What we could if we have a spare bit on LABEL_DECL or GIMPLE_LABEL is do roughly what the C++ FE did previously in gimplify_cond_expr, but not throu= gh actually not emitting that cond, but by setting a flag on the LABEL_DECL or GIMPLE_LABEL that for the purposes of -Wimplicit-fallthrough warning we wou= ld consider unreachable and set it on labels for COND_EXPR with integer_nonzer= op condition if !TREE_OPERANDS (expr, 2) || !TREE_SIDE_EFFECTS (TREE_OPERANDS (expr, 2)) on the label_false label and if integer_zerop condition and if !TREE_OPERANDS (expr, 1) || !TREE_SIDE_EFFECTS (TREE_OPERANDS (expr, 1)) on the label_true label. Perhaps only do that for the freshly created artificial labels though? After gimplification of the COND_EXPR this is harder because we could have = if (1) { whatever; } else { ...; lab: ... } and goto lab; from somewhere etc. Unfortunately I'm not familiar enough with the -Wimplicit-fallthrough code,= so I can help with setting a flag in gimplify_cond_expr for labels that should= be ignored (i.e. we should act as if they weren't there, so when walking back = look at what is before them etc.). Marek, could you please have a look?=