From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 83C1E385801A; Tue, 6 Apr 2021 23:13:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83C1E385801A From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/90710] Bogus Wmaybe-uninitialized caused by __builtin_expect when compiled with -Og Date: Tue, 06 Apr 2021 23:13:51 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 9.1.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor 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: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cf_reconfirmed_on cf_known_to_fail 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, 06 Apr 2021 23:13:51 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D90710 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2019-06-02 00:00:00 |2021-4-6 Known to fail| |10.2.1, 11.0, 9.3.0 CC| |msebor at gcc dot gnu.org --- Comment #3 from Martin Sebor --- Reconfirmed with GCC 11. My enhanced version of trunk under test prints: pr90710.c: In function =E2=80=98testFunction=E2=80=99: pr90710.c:22:17: warning: =E2=80=98value=E2=80=99 may be used uninitialized= in this function [-Wmaybe-uninitialized] 22 | printf("My if() causes -Wmaybe-uninitialized for my= use of `value': %d\n",value); |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~~ pr90710.c:17:22: note: when =E2=80=98x =3D=3D 0=E2=80=99 17 | unsigned int value; | ^~~~~ pr90710.c:17:22: note: used when =E2=80=98_11 =3D PHI <0(3), 1(9)> !=3D 0= =E2=80=99 pr90710.c:17:22: note: =E2=80=98value=E2=80=99 was declared here The IL the warning sees (annotated with my comments) is below. The predica= te that guards the possibly uninitialized use is (was_ok_8 !=3D 0 && was_ok_8 = =3D=3D 0), which the warning should be able to determine is false. It doesn't because= , as a result of the __builtin_expect() intrinsic which converts the first argum= ent to long int, the assignment 'was_ok_8 =3D (int) _11' in bb 4 involves a conversion that the warning code doesn't handle. Changing the type of the variables to long avoids the warning. __attribute__((noinline)) void testFunction () { int was_ok; unsigned int value; volatile unsigned int x; unsigned int x.0_1; long int _2; unsigned int _11; [local count: 1073741824]: # .MEM_7 =3D VDEF <.MEM_6(D)> x =3D{v} 1; # VUSE <.MEM_7> x.0_1 =3D{v} x; if (x.0_1 =3D=3D 0) goto ; [34.00%] else goto ; [66.00%] [local count: 708669600]: goto ; [100.00%] [local count: 365072224]: [local count: 1073741824]: # _11 =3D PHI <0(3), 1(9)> # value_12 =3D PHI was_ok_8 =3D (int) _11; <<< int to long conversion gets in the= way if (was_ok_8 !=3D 0) goto ; [33.00%] else goto ; [67.00%] <<< was_ok_8 =3D=3D 0 [local count: 719407024]: goto ; [100.00%] [local count: 354334800]: # .MEM_9 =3D VDEF <.MEM_7> printf ("My if() compiles fine: %d\n", value_12); [local count: 1073741824]: # .MEM_4 =3D PHI <.MEM_7(10), .MEM_9(5)> _2 =3D (long int) was_ok_8; if (_2 !=3D 0) goto ; [90.00%] <<< was_ok_8 !=3D 0 else goto ; [10.00%] [local count: 107374184]: goto ; [100.00%] [local count: 966367641]: ## value_12 used when was_ok_8 !=3D 0 AND was_ok_8 =3D=3D 0 <<< must be= false # .MEM_10 =3D VDEF <.MEM_4> printf ("My if() causes -Wmaybe-uninitialized for my use of `value\': %d\= n", value_12); [local count: 1073741824]: # .MEM_5 =3D PHI <.MEM_4(11), .MEM_10(7)> # VUSE <.MEM_5> return; }=