From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3AB663857023; Mon, 29 Mar 2021 23:22:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AB663857023 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/63518] missing Wuninitialized warning independent of order of arguments Date: Mon, 29 Mar 2021 23:22:14 +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: 4.7.4 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 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, 29 Mar 2021 23:22:14 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D63518 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2019-02-03 00:00:00 |2021-3-29 Known to fail| |10.2.0, 11.0, 4.8.4, 4.9.4, | |5.5.0, 6.4.0, 7.2.0, 8.3.0, | |9.1.0 --- Comment #4 from Martin Sebor --- This is a similar problem to (although not quite the same as) the one we ha= ve been discussing in pr60488. I have changed the test case to C to shorten t= he IL. Here's the C test case and the IL from a GCC instrumented to print it = just as the pass runs. At each point of a variable's use, the warning looks for prior statements that might set its value. If it finds one, it doesn't trigger. In foo() the first such prior statement is the call to setTimeout(&t). In bar(), there is no such prior statement, and so there t= he warning does trigger. I don't see how to fix this except by running the warning in the front end = or just before Gimplification when all the arguments to the wait() call statem= ent are still in the IL. Once the code is Gimplified the arguments are already broken out of the call. This isn't an option today for all the reasons that have been discussed over the years but might perhaps be doable if/when the __builtin_warning() idea comes to fruition. With it in place, the warning could be scheduled to be issued early on, false positives weeded out by run= ning the optimizers as usual, and then issued if the __builtin_warning() call was still left in the IL. This would have to be done under the control of the = same predicate analysis as the one in tree-ssa-uninit.c today (which is why I'm factoring it out into a standalone reusable component). $ cat x.c && gcc -S -Wall x.c void wait (int, _Bool); void wait2 (_Bool, int); _Bool setTimeout (int*); void foo (void) { int t; wait (t, setTimeout (&t)); } void bar (void) { int t; wait2 (setTimeout (&t), t); } void foo () { int t; _Bool _1; int _2; int t.0_3; : # .MEM_5 =3D VDEF <.MEM_4(D)> _1 =3D setTimeout (&t); <<< address of t escapes first _2 =3D (int) _1; # VUSE <.MEM_5> t.0_3 =3D t; <<< missing warning # .MEM_6 =3D VDEF <.MEM_5> wait (t.0_3, _2); # .MEM_7 =3D VDEF <.MEM_6> t =3D{v} {CLOBBER}; # VUSE <.MEM_7> return; } void bar () { int t; int t.1_1; _Bool _2; int _3; : # VUSE <.MEM_4(D)> t.1_1 =3D t; <<< -Wuninitialized # .MEM_5 =3D VDEF <.MEM_4(D)> _2 =3D setTimeout (&t); <<< address of t escapes second _3 =3D (int) _2; # .MEM_6 =3D VDEF <.MEM_5> wait2 (_3, t.1_1); # .MEM_7 =3D VDEF <.MEM_6> t =3D{v} {CLOBBER}; # VUSE <.MEM_7> return; } _1 =3D setTimeout (&t); <<< address of t escapes _2 =3D (int) _1; t.0_3 =3D t; <<< missing warning wait (t.0_3, _2); t =3D{v} {CLOBBER}; return; } void bar () { int t; int t.1_1; _Bool _2; int _3; : t.1_1 =3D t; <<< -Wuninitialized _2 =3D setTimeout (&t); <<< address of t escapes _3 =3D (int) _2; wait2 (_3, t.1_1); t =3D{v} {CLOBBER}; return; } x.c: In function =E2=80=98bar=E2=80=99: x.c:15:3: warning: =E2=80=98t=E2=80=99 is used uninitialized [-Wuninitializ= ed] 15 | wait2 (setTimeout (&t), t); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ x.c:14:7: note: =E2=80=98t=E2=80=99 declared here 14 | int t; | ^=