From patchwork Mon Sep 19 18:25:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 57761 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 500FE3858CDA for ; Mon, 19 Sep 2022 18:26:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 500FE3858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663612004; bh=+VEgL4piTc9jnJnvtUyeM7rSe4C9y5tSFoh79AxgPs0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wHXoWKGxz7IBbofIfkvo4DwJ81EWXFtXQNZB3NvSs+Ffd7+hLoT1ulZiw+6YV0eIO TL0Y1MLQSPL5pP4sYSoLMbFZ4SpE4HRfBdtzUXdkrDKIfuf315zvfRIbCFwRS/2Edn HUrSc0zDuUDgmDOhVIY87dgV+D6V+xJnW4K3EWM8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DD6A03858D37 for ; Mon, 19 Sep 2022 18:26:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DD6A03858D37 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-21-PPATCv18MXSgi_sizRAX9A-1; Mon, 19 Sep 2022 14:26:10 -0400 X-MC-Unique: PPATCv18MXSgi_sizRAX9A-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E10F4101AA66; Mon, 19 Sep 2022 18:26:09 +0000 (UTC) Received: from pdp-11.lan (unknown [10.22.9.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id A500849BB61; Mon, 19 Sep 2022 18:26:09 +0000 (UTC) To: GCC Patches , Joseph Myers , Jason Merrill Subject: [PATCH] c: Stray inform note with -Waddress [PR106947] Date: Mon, 19 Sep 2022 14:25:59 -0400 Message-Id: <20220919182559.46958-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/12? 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. --- gcc/c/c-typeck.cc | 19 ++++++++++--------- gcc/testsuite/c-c++-common/Waddress-7.c | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/Waddress-7.c base-commit: de40fab2f32b03c3d8f69f72c7f1e38694f93d35 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; +}