From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id 342773858D37; Mon, 19 Sep 2022 18:41:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 342773858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663612911; bh=Z4Qo5CvPukpghkFG0jAHYxphBPnN/aOzOgy2LHeBgEQ=; h=From:To:Subject:Date:From; b=Pvb+vt9yk9y6FlqHQ1L9fL5AwqO6rscMmyJIMVn/Matjtc23kOtPdNzgPRLl55n6J qX84ddvLPKuwieD/W4kQGXJkgYLUoab5y9BzPMGJAH+KMASKV6VV/6pReppDlXk6oY 0FQbkOQIWpbJur65sypwJ0KPBhVEGBBq1xsnopes= 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 r13-2723] c: Stray inform note with -Waddress [PR106947] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: de40fab2f32b03c3d8f69f72c7f1e38694f93d35 X-Git-Newrev: 2d9429d5c0f86f588bdfd85bb9e236d2be367d3f Message-Id: <20220919184151.342773858D37@sourceware.org> Date: Mon, 19 Sep 2022 18:41:51 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2d9429d5c0f86f588bdfd85bb9e236d2be367d3f commit r13-2723-g2d9429d5c0f86f588bdfd85bb9e236d2be367d3f 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. 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 43a910d5df2..33d1e8439db 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -11738,18 +11738,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; +}