https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40635
Martin Sebor <msebor at gcc dot gnu.org> 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 <msebor at gcc dot gnu.org> --- 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 locations: <bb 8> [local count: 1073741824]: # _16 = 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 = _16 < 0; [pr40635.c:38:8] _5 = (int) _28; [pr40635.c:38:8] _4 = -_5; return _4; <bb 12> [local count: 39298952]: <bb 9> [local count: 383953502]: # s42_21 = PHI <[pr40635.c:13:9] s42_18(D)(12), [pr40635.c:19:15] s42_9(14)> goto <bb 8>; [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. -Wuninitialized usually prints a note pointing to the uninitialized variable but it has the code below that guards is: if (xloc.file != floc.file || linemap_location_before_p (line_table, location, cfun_loc) || linemap_location_before_p (line_table, cfun->function_end_locus, 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 pointless test and improves the output a bit: pr40635.c:38:8: warning: ‘s42’ may be used uninitialized in this function [-Wmaybe-uninitialized] 38 | if (sockt_rd < 0) | ^ pr40635.c:13:9: note: ‘s42’ 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 = (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 != NULL && gimple_has_location (context)) location = gimple_location (context); else if (phiarg_loc != UNKNOWN_LOCATION) @@ -178,9 +177,7 @@ warn_uninit (enum opt_code wc, tree t, tree expr, tree var, location = DECL_SOURCE_LOCATION (var); location = linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, NULL); - cfun_loc = DECL_SOURCE_LOCATION (cfun->decl); - xloc = expand_location (location); - floc = 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 == DECL_SOURCE_LOCATION (var)) return; - if (xloc.file != floc.file - || linemap_location_before_p (line_table, location, cfun_loc) - || linemap_location_before_p (line_table, cfun->function_end_locus, - location)) - inform (DECL_SOURCE_LOCATION (var), "%qD was declared here", var); + inform (DECL_SOURCE_LOCATION (var), "%qD was declared here", var); } }