From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BFC6A3856DD2; Wed, 14 Sep 2022 20:39:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFC6A3856DD2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663187944; bh=u3kO6LUmFCs1ybwtSCQABAjwSyCoNt3T+b7cdZYE9SU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bvVBDanFPA6Y2rkfgqWSsA6yi4OkKDPyW4brIbBTt8O60tALHJgTsZR5NkiFQuV/T eg25yEjDIGueTq7aMbSgMO5lzkXRrDgjh86MoHYCKX2TK3UdQbUts1Ef8ihEkPYl2z pF6vL0361GA2L7pb0mfrxxzIk3006kts3RZ6U89c= From: "pinskia at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.1.1 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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: component 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106947 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Component|middle-end |c --- Comment #1 from Andrew Pinski --- 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 =3D 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 =3D=3D EQ_EXPR) - warning_at (loc, OPT_Waddress, + do_note =3D warning_at (loc, OPT_Waddress, "the comparison will always evaluate as % " "for the address of %qE will never be NULL", op); else - warning_at (loc, OPT_Waddress, + do_note =3D warning_at (loc, OPT_Waddress, "the comparison will always evaluate as % " "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); }=