From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C537F384C002; Mon, 5 Apr 2021 20:34:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C537F384C002 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/85301] bitfield check causes maybe-uninitialized warning Date: Mon, 05 Apr 2021 20:34:34 +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: 8.0.1 X-Bugzilla-Keywords: diagnostic, missed-optimization 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 see_also 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: Mon, 05 Apr 2021 20:34:34 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D85301 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2018-04-09 00:00:00 |2021-4-5 Known to fail| |10.2.0, 11.0, 8.3.0, 9.3.0 See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=3D99919 CC| |msebor at gcc dot gnu.org --- Comment #8 from Martin Sebor --- Reconfirmed with GCC 11 with the ever-so-slightly slightly simplified progr= am below and enhanced output. The warning has been issued since at least GCC = 4.1 and so is not a regression. $ cat pr85301.c && gcc -O2 -S -Wall -DUSE_BITFIELD pr85301.c struct A { #ifdef USE_BITFIELD unsigned i : 1; unsigned j : 1; #else unsigned i; unsigned j; #endif }; int z, f (void); struct A a; void h (void) { int y; if (a.j || a.i) y =3D f (); if (a.i) z =3D y; } pr85301.c: In function =E2=80=98h=E2=80=99: pr85301.c:24:7: warning: =E2=80=98y=E2=80=99 may be used uninitialized in t= his function [-Wmaybe-uninitialized] 24 | z =3D y; | ~~^~~ pr85301.c:18:7: note: when =E2=80=98!(((unsigned char*)&a)[0] & 3)=E2=80=99 18 | int y; | ^ pr85301.c:18:7: note: used when =E2=80=98prephitmp_15 =3D PHI <_1(7), pretm= p_14(3)> & 1=E2=80=99 pr85301.c:18:7: note: =E2=80=98y=E2=80=99 was declared here Jump threading and other optimization opportunities aside (I have raised pr99918 for one of those), there does also seem to be a limitation in the warning code in that it doesn't understand BIT_FIELD_REF expressions. The warning sees the IL below from which it should be able to determine that y's use is conditional on its definition (i.e., the use predicate a strict subs= et of the predicate controlling the definition). void h () { int y; unsigned char _1; unsigned char _2; unsigned char _4; unsigned char pretmp_14; unsigned char prephitmp_15; [local count: 1073741824]: # VUSE <.MEM_8(D)> _1 =3D BIT_FIELD_REF ; _2 =3D _1 & 3; if (_2 !=3D 0) goto ; [33.00%] else goto ; [67.00%] [local count: 719407024]: goto ; [100.00%] [local count: 354334800]: # .MEM_10 =3D VDEF <.MEM_8(D)> y_11 =3D f (); # VUSE <.MEM_10> pretmp_14 =3D BIT_FIELD_REF ; [local count: 1073741824]: # y_5 =3D PHI # .MEM_6 =3D PHI <.MEM_8(D)(7), .MEM_10(3)> # prephitmp_15 =3D PHI <_1(7), pretmp_14(3)> _4 =3D prephitmp_15 & 1; if (_4 !=3D 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870912]: goto ; [100.00%] [local count: 536870913]: ## y_5 =3D PHI ## uninit when: _2 =3D=3D 0 ## : BIT_FIELD_REF & 3 =3D=3D 0 ## ## used when: prephitmp_15 & !=3D 0 ## : PHI <_1(7), pretmp_14(3)> ## : _1(7) !=3D 0 || pretmp_14 !=3D 0 ## : BIT_FIELD_REF !=3D 0 || BIT_FIELD_REF != =3D 0 ## : BIT_FIELD_REF !=3D 0 # .MEM_12 =3D VDEF <.MEM_6> z =3D y_5; [local count: 1073741824]: # .MEM_7 =3D PHI <.MEM_6(8), .MEM_12(5)> # VUSE <.MEM_7> return; }=