From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id D7C6D3858D32; Mon, 19 Sep 2022 18:43:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7C6D3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663612993; bh=4ZrqQD/85QlSor3w1yv7g1F7QlzO7qpwiVdnfFfnVTQ=; h=From:To:Subject:Date:From; b=jGAnT9tOMbXpiBTDCpcEpJcowGvoe5QdHbPHpBtv9fIOGfDZRlMqdzDnA4yQdYyX4 U7feSk5EjltjtytGcWVSJYqgxFswojLtcJoMAUEzr3Kuv/z89WrjADKs2RYAqdxyDW 6OryYVg3zP/RVr5a2oHKvaCBN1RVXaOvkpsPu/g4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marek Polacek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8774] c: Stray inform note with -Waddress [PR106947] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 57896e8cddd2eb952145fa32ca25635fd63246b4 X-Git-Newrev: 97803ee561c7a2692a6d7863a5d86797d79a18b1 Message-Id: <20220919184313.D7C6D3858D32@sourceware.org> Date: Mon, 19 Sep 2022 18:43:13 +0000 (GMT) List-Id: https://gcc.gnu.org/g:97803ee561c7a2692a6d7863a5d86797d79a18b1 commit r12-8774-g97803ee561c7a2692a6d7863a5d86797d79a18b1 Author: Marek Polacek Date: Mon Sep 19 14:12:55 2022 -0400 c: Stray inform note with -Waddress [PR106947] A trivial fix for maybe_warn_for_null_address where we print an inform note without first checking the return value of a warning call. PR c/106947 gcc/c/ChangeLog: * c-typeck.cc (maybe_warn_for_null_address): Don't emit stray notes. gcc/testsuite/ChangeLog: * c-c++-common/Waddress-7.c: New test. (cherry picked from commit 2d9429d5c0f86f588bdfd85bb9e236d2be367d3f) Diff: --- gcc/c/c-typeck.cc | 19 ++++++++++--------- gcc/testsuite/c-c++-common/Waddress-7.c | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index e130196a3a7..0e55fd1db4b 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -11681,18 +11681,19 @@ maybe_warn_for_null_address (location_t loc, tree op, tree_code code) || from_macro_expansion_at (loc)) return; + bool w; if (code == EQ_EXPR) - warning_at (loc, OPT_Waddress, - "the comparison will always evaluate as % " - "for the address of %qE will never be NULL", - op); + w = 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, - "the comparison will always evaluate as % " - "for the address of %qE will never be NULL", - op); + w = 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 (w && DECL_P (op)) inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op); } diff --git a/gcc/testsuite/c-c++-common/Waddress-7.c b/gcc/testsuite/c-c++-common/Waddress-7.c new file mode 100644 index 00000000000..179948553c5 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Waddress-7.c @@ -0,0 +1,22 @@ +/* PR c/106947 */ +/* { dg-do compile } */ +/* { dg-options "-Waddress" } */ + +#ifndef __cplusplus +# define bool _Bool +#endif + +#pragma GCC diagnostic ignored "-Waddress" +int s; /* { dg-bogus "declared" } */ +bool e = &s; +int +main () +{ + int error = 0; + { + bool e1 = &s; + if (!e1) + error = 1; + } + return error; +}