From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1EADC398583C; Wed, 11 Aug 2021 17:42:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1EADC398583C From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/101862] [C, C++] Potential '?:' diagnostic for always-true expressions in boolean context Date: Wed, 11 Aug 2021 17:42:55 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: amacleod at redhat dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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: Wed, 11 Aug 2021 17:42:56 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101862 Andrew Macleod changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amacleod at redhat dot com --- Comment #1 from Andrew Macleod --- I'm not sure exactly what you want to do. When we go into SSA we see: : _8 =3D arr[i_15]; i.1_9 =3D (unsigned int) i_15; _10 =3D i.1_9 & 1; _11 =3D _10 !=3D 0; _12 =3D (int) _11; if (_8 =3D=3D _12) goto ; [INV] else goto ; [INV] : iftmp.0_27 =3D i_15 !=3D -1; goto ; [INV] : iftmp.0_26 =3D i_15 !=3D -2; : # iftmp.0_16 =3D PHI if (iftmp.0_16 !=3D 0) goto ; [INV] else goto ; [INV] The EVRP pass recognizes that i_15 has a range of int [0, 32], thus folds=20 # iftmp.0_16 =3D PHI into # iftmp.0_16 =3D PHI <1, 1> and continues to fold away the if that leads to the assert. This seems to be too late to determine that a warning might be appropriate.. and I'm not sure how you would figure that out from this IL. We have to go way back before gimple before we see the conditional expressi= on. I see the front end generates this is the .original file: :; { if (arr[i] =3D=3D (((unsigned int) i & 1) !=3D 0) ? i !=3D -1 : i != =3D -2) { (void) 0; } else { __assert_fail ((const char *) "arr[i] =3D=3D ((i % 2) !=3D 0) ? i= + 1 : i + 2", (const char *) "as.c", 17, (const char *) &__PRETTY_FUNCTION__); } but even by the .gimple listing the COND_EXPR is gone, replaced with the if= tmp sequence. Im not sure how you would determine that this is not working as intended.. ? we usually rejoice when we can fold asserts away :-) The range machinery knows what you want to know, but IM not sure how you co= uld use it. Its only available once we go into SSA.=