From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671705179; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=kR80+l008ec+Lfru4RYJj6GN3SuAUwCXDTeZ9m35Pyw=; b=WHdEnkPzDbuiTd6aBsgokamawnmTRz/vil89oo40aimLdtf8+/4qSETKy+iz764F5fQiOv 2C+crRN38gHbkDVwUNVyflr8uR3EfN45I4hj80fLkhnQFQkuNI2SDHEgnTv2lCk4eeuQPT dbnlOpgXHbjCMqfc7zNH0KDF88yLP6I= 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 From: Jakub Jelinek 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: Reply-To: Jakub Jelinek 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-Type: text/plain; charset=us-ascii 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 List-Id: 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. --- 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 } */ +} Jakub