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