From patchwork Thu Dec 22 10:32:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 62256 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 8F1CA385B50B for ; Thu, 22 Dec 2022 10:33:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F1CA385B50B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671705207; bh=kR80+l008ec+Lfru4RYJj6GN3SuAUwCXDTeZ9m35Pyw=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=VedPBY/HGyyFd0cwPUORQAVmG68CY8H1L/vdVEAty+rn9X2GkhvLMrExjqPeIyBqF fiRUKB53eXaYIGMjMYy+5ZCVGB451z1SuzjD9kCfYACHICfAklF3G2XA+W1HO+93PS UQuF8GER5p61reyMZzcwOvZ3keFhedXNFzc+UPI8= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id CDD223858281 for ; Thu, 22 Dec 2022 10:32:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CDD223858281 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-108-RFXHpbtTPuWkb1ee0IN59g-1; Thu, 22 Dec 2022 05:32:55 -0500 X-MC-Unique: RFXHpbtTPuWkb1ee0IN59g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B62718E5282; Thu, 22 Dec 2022 10:32:55 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 53DAA2026D4B; Thu, 22 Dec 2022 10:32:55 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2BMAWqHe1189315 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 22 Dec 2022 11:32:53 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BMAWpIb1189314; Thu, 22 Dec 2022 11:32:51 +0100 Date: Thu, 22 Dec 2022 11:32:51 +0100 To: "Joseph S. Myers" , Jason Merrill , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c, c++, cgraphunit: Prevent duplicated -Wunused-value warnings [PR108079] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! On the following testcase, we warn with -Wunused-value twice, once in the FEs and later on cgraphunit again with slightly different wording. The following patch fixes that by registering a warning suppression in the FEs when we warn and not warning in cgraphunit anymore if that happened. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-12-22 Jakub Jelinek PR c/108079 gcc/ * cgraphunit.cc (check_global_declaration): Don't warn for unused variables which have OPT_Wunused_variable warning suppressed. gcc/c/ * c-decl.cc (pop_scope): Suppress OPT_Wunused_variable warning after diagnosing it. gcc/cp/ * decl.cc (poplevel): Suppress OPT_Wunused_variable warning after diagnosing it. gcc/testsuite/ * c-c++-common/Wunused-var-18.c: New test. Jakub --- gcc/cgraphunit.cc.jj 2022-10-18 10:38:48.000000000 +0200 +++ gcc/cgraphunit.cc 2022-12-21 15:14:34.687939477 +0100 @@ -1122,6 +1122,7 @@ check_global_declaration (symtab_node *s && (TREE_CODE (decl) != FUNCTION_DECL || (!DECL_STATIC_CONSTRUCTOR (decl) && !DECL_STATIC_DESTRUCTOR (decl))) + && (! VAR_P (decl) || !warning_suppressed_p (decl, OPT_Wunused_variable)) /* Otherwise, ask the language. */ && lang_hooks.decls.warn_unused_global (decl)) warning_at (DECL_SOURCE_LOCATION (decl), --- gcc/c/c-decl.cc.jj 2022-12-19 11:08:31.500766238 +0100 +++ gcc/c/c-decl.cc 2022-12-21 14:52:40.251919370 +0100 @@ -1310,7 +1310,10 @@ pop_scope (void) && scope != external_scope) { if (!TREE_USED (p)) - warning (OPT_Wunused_variable, "unused variable %q+D", p); + { + warning (OPT_Wunused_variable, "unused variable %q+D", p); + suppress_warning (p, OPT_Wunused_variable); + } else if (DECL_CONTEXT (p) == current_function_decl) warning_at (DECL_SOURCE_LOCATION (p), OPT_Wunused_but_set_variable, --- gcc/cp/decl.cc.jj 2022-12-21 09:03:45.437566855 +0100 +++ gcc/cp/decl.cc 2022-12-21 14:51:07.043265263 +0100 @@ -693,6 +693,7 @@ poplevel (int keep, int reverse, int fun else warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_variable, "unused variable %qD", decl); + suppress_warning (decl, OPT_Wunused_variable); } else if (DECL_CONTEXT (decl) == current_function_decl // For -Wunused-but-set-variable leave references alone. --- gcc/testsuite/c-c++-common/Wunused-var-18.c.jj 2022-12-21 15:28:03.112273963 +0100 +++ gcc/testsuite/c-c++-common/Wunused-var-18.c 2022-12-21 15:27:05.246107581 +0100 @@ -0,0 +1,10 @@ +/* PR c/108079 */ +/* { dg-do compile } */ +/* { dg-options "-Wunused-variable" } */ + +int +main () +{ + static int x; /* { dg-warning "unused variable 'x'" } */ + /* { dg-bogus "'x' defined but not used" "" { target *-*-* } .-1 } */ +}