public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-40635-4-yJaqOjn8Ll@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-40635-4@http.gcc.gnu.org/bugzilla/>

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);
     }
 }

  parent reply	other threads:[~2021-03-25 21:07 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-40635-4@http.gcc.gnu.org/bugzilla/>
2013-11-01 21:56 ` manu at gcc dot gnu.org
2013-12-19 10:17 ` manu at gcc dot gnu.org
2013-12-19 10:40 ` philipp at marek dot priv.at
2013-12-19 10:51 ` manu at gcc dot gnu.org
2013-12-19 10:57 ` philipp at marek dot priv.at
2013-12-19 10:59 ` philipp at marek dot priv.at
2021-03-25 21:07 ` msebor at gcc dot gnu.org [this message]
2021-03-25 21:08 ` msebor at gcc dot gnu.org
2021-03-25 22:40 ` msebor at gcc dot gnu.org
2021-12-15 18:43 ` msebor at gcc dot gnu.org
2021-12-15 18:48 ` [Bug tree-optimization/40635] [12 Regression] " msebor at gcc dot gnu.org
2021-12-15 19:00 ` msebor at gcc dot gnu.org
2021-12-15 19:14 ` pinskia at gcc dot gnu.org
2021-12-18 10:46 ` pinskia at gcc dot gnu.org
2022-01-21 13:56 ` rguenth at gcc dot gnu.org
2022-03-17 19:25 ` msebor at gcc dot gnu.org
2022-03-17 22:00 ` pinskia at gcc dot gnu.org
2022-05-06  8:29 ` [Bug tree-optimization/40635] [12/13 " jakub at gcc dot gnu.org
2022-11-20  3:11 ` law at gcc dot gnu.org
2022-12-05 15:00 ` rguenth at gcc dot gnu.org
2022-12-05 15:51 ` cvs-commit at gcc dot gnu.org
2023-05-08 12:21 ` [Bug tree-optimization/40635] [12 " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-40635-4-yJaqOjn8Ll@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).