public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/106947] -Waddress + bool + pragma generates meaningless diagnostic
Date: Wed, 14 Sep 2022 20:39:04 +0000	[thread overview]
Message-ID: <bug-106947-4-xRYMz5XO0C@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106947-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106947

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |c

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The bug is in the C front-end.
Specifically the bug is in maybe_warn_for_null_address which does not check the
return value of warning if it should do the inform.

Something like this will fix the issue:
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index d37de2a313b..59e384ac997 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -11619,6 +11619,7 @@ build_vec_cmp (tree_code code, tree type,
 static void
 maybe_warn_for_null_address (location_t loc, tree op, tree_code code)
 {
+  bool do_note = false;
   /* Prevent warnings issued for macro expansion.  */
   if (!warn_address
       || warning_suppressed_p (op, OPT_Waddress)
@@ -11706,17 +11707,17 @@ maybe_warn_for_null_address (location_t loc, tree op,
tree_code code)
     return;

   if (code == EQ_EXPR)
-    warning_at (loc, OPT_Waddress,
+    do_note = warning_at (loc, OPT_Waddress,
                "the comparison will always evaluate as %<false%> "
                "for the address of %qE will never be NULL",
                op);
   else
-    warning_at (loc, OPT_Waddress,
+    do_note = warning_at (loc, OPT_Waddress,
                "the comparison will always evaluate as %<true%> "
                "for the address of %qE will never be NULL",
                op);

-  if (DECL_P (op))
+  if (do_note && DECL_P (op))
     inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
 }

  reply	other threads:[~2022-09-14 20:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14 20:31 [Bug middle-end/106947] New: " eggert at cs dot ucla.edu
2022-09-14 20:39 ` pinskia at gcc dot gnu.org [this message]
2022-09-14 20:39 ` [Bug c/106947] " pinskia at gcc dot gnu.org
2022-09-14 20:42 ` [Bug c/106947] [12/13 Regression] " pinskia at gcc dot gnu.org
2022-09-15  7:19 ` rguenth at gcc dot gnu.org
2022-09-15 15:19 ` mpolacek at gcc dot gnu.org
2022-09-19 18:41 ` cvs-commit at gcc dot gnu.org
2022-09-19 18:43 ` cvs-commit at gcc dot gnu.org
2022-09-19 18:43 ` mpolacek at gcc dot gnu.org
2023-03-16 12:25 ` marxin 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-106947-4-xRYMz5XO0C@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).