From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2535A3857C62; Thu, 25 Mar 2021 21:07:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2535A3857C62 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/40635] bogus name and location in 'may be used uninitialized' warning Date: Thu, 25 Mar 2021 21:07:57 +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: 4.4.1 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: Thu, 25 Mar 2021 21:07:58 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D40635 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2019-02-24 00:00:00 |2021-3-25 Known to fail|9.0 |10.2.0, 11.0, 9.3.0 --- Comment #13 from Martin Sebor --- I think the reason why the location for the last PHI argument isn't set is because the argument is itself a PHI whose arguments have different locatio= ns: [local count: 1073741824]: # _16 =3D PHI <[pr40635.c:21:20] -1(13), [pr40635.c:19:15] s42_9(7), [pr40635.c:28:16] -1(15), s42_21(9)> [pr40635.c:37:5] foo (); [pr40635.c:38:8] _28 =3D _16 < 0; [pr40635.c:38:8] _5 =3D (int) _28; [pr40635.c:38:8] _4 =3D -_5; return _4; [local count: 39298952]: [local count: 383953502]: # s42_21 =3D PHI <[pr40635.c:13:9] s42_18(D)(12), [pr40635.c:19:15] s42_9= (14)> goto ; [100.00%] } Even if -Wuninitialized is changed to extract the location from the uninitialized argument to s42_21(9), it doesn't use it because it prefers to use the location of the statement where the variable us used. -Wuninitiali= zed usually prints a note pointing to the uninitialized variable but it has the code below that guards is: if (xloc.file !=3D floc.file || linemap_location_before_p (line_table, location, cfun_loc) || linemap_location_before_p (line_table, cfun->function_end_locu= s, location)) inform (DECL_SOURCE_LOCATION (var), "%qD was declared here", var); Because the location of the variable is in a different function than the current one the note isn't printed. The patch below removes this IMO point= less test and improves the output a bit: pr40635.c:38:8: warning: =E2=80=98s42=E2=80=99 may be used uninitialized in= this function [-Wmaybe-uninitialized] 38 | if (sockt_rd < 0) | ^ pr40635.c:13:9: note: =E2=80=98s42=E2=80=99 was declared here 13 | int s42, x; | ^~~ diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c index 0800f596ab1..a578a596fee 100644 --- a/gcc/tree-ssa-uninit.c +++ b/gcc/tree-ssa-uninit.c @@ -126,8 +126,6 @@ warn_uninit (enum opt_code wc, tree t, tree expr, tree = var, const char *gmsgid, void *data, location_t phiarg_loc) { gimple *context =3D (gimple *) data; - location_t location, cfun_loc; - expanded_location xloc, floc; /* Ignore COMPLEX_EXPR as initializing only a part of a complex turns in a COMPLEX_EXPR with the not initialized part being @@ -170,6 +168,7 @@ warn_uninit (enum opt_code wc, tree t, tree expr, tree = var, || TREE_NO_WARNING (expr)) return; + location_t location; if (context !=3D NULL && gimple_has_location (context)) location =3D gimple_location (context); else if (phiarg_loc !=3D UNKNOWN_LOCATION) @@ -178,9 +177,7 @@ warn_uninit (enum opt_code wc, tree t, tree expr, tree = var, location =3D DECL_SOURCE_LOCATION (var); location =3D linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, NULL); - cfun_loc =3D DECL_SOURCE_LOCATION (cfun->decl); - xloc =3D expand_location (location); - floc =3D expand_location (cfun_loc); + auto_diagnostic_group d; if (warning_at (location, wc, gmsgid, expr)) { @@ -188,11 +185,7 @@ warn_uninit (enum opt_code wc, tree t, tree expr, tree var, if (location =3D=3D DECL_SOURCE_LOCATION (var)) return; - if (xloc.file !=3D floc.file - || linemap_location_before_p (line_table, location, cfun_loc) - || linemap_location_before_p (line_table, cfun->function_end_locu= s, - location)) - inform (DECL_SOURCE_LOCATION (var), "%qD was declared here", var); + inform (DECL_SOURCE_LOCATION (var), "%qD was declared here", var); } }=