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.129.124]) by sourceware.org (Postfix) with ESMTPS id 0795C385B529 for ; Thu, 22 Dec 2022 21:44:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0795C385B529 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=1671745470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DtIjaDl/iIiDdlyN8udDYTnGzA4Oiyb97HeWdqBRvu8=; b=G6+s8tUiQ7OoSRWZtwBHq9JVLGE+FZbl3ih98UYsssmXDcH6P6hRr73eM7MgFNlPOnKI+4 dXKJNComIf+n/UOQshSIA8VYI67v6Z47xgH7IWrD3gKHfjcE+2ZaXp7I+i3siMjx7XBz1w TTj5cJQSI1Ir4Qb17yvj7cDqKL/TKqg= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-249-6gsv5UbbMCqRMv8jKjmbhw-1; Thu, 22 Dec 2022 16:44:29 -0500 X-MC-Unique: 6gsv5UbbMCqRMv8jKjmbhw-1 Received: by mail-qk1-f199.google.com with SMTP id bm30-20020a05620a199e00b006ff813575b1so1981384qkb.16 for ; Thu, 22 Dec 2022 13:44:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DtIjaDl/iIiDdlyN8udDYTnGzA4Oiyb97HeWdqBRvu8=; b=Te7+TAcxstotRfAC5zvelTE/llNDmWXvGoteloC+WTggqt2HHNwLm+HQjNzHAA9i61 QU1QrMPp5KuVWQdNGTPsWlwCFffwYQGk3IyG9/gyAVXvokLHtKqezC8v29R7+valL7+F P0JTQ2A3cVo31Mp8s/nVKczgWgs7TyuDXqSspgPD9NHCZL/qqG/N6d/PiavuZDIZP8Td 4Q6Ymi0ov5Knxm+BdYj2GSUry1uiYtZ/Ohb7kuu57CQOCdlTXlnx4PNYsedDoVY3C3d+ 78F+Cf0rdusNAN+KKUJfTXvP/cEI3U5JvIRzRPh4C7CB8Qc4Wy5vz983Dxar+RYO/lDa hyng== X-Gm-Message-State: AFqh2koiI7nNdnBN+Cn0/kONbfrVIMlH1XRI3430ezB4hSvqxXG3LGeq 4oP1quxmGwmaQMWRvAC5xYLI2yFYlxlPjFVBDHd+hfBt/QY6HkizbOdxPzWpY9IVxO8aBYXG2j9 YJ6JVU2288g8HLr3nOA== X-Received: by 2002:ac8:75c5:0:b0:3a4:472e:bd6d with SMTP id z5-20020ac875c5000000b003a4472ebd6dmr9981265qtq.23.1671745468780; Thu, 22 Dec 2022 13:44:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXuUZ35x9c+aeFfKsZzGsejC6vsRrm93PsbEa/NzgTklME8OsNoH/KKiIBt69Mq2RXVX4cJ0Eg== X-Received: by 2002:ac8:75c5:0:b0:3a4:472e:bd6d with SMTP id z5-20020ac875c5000000b003a4472ebd6dmr9981223qtq.23.1671745468187; Thu, 22 Dec 2022 13:44:28 -0800 (PST) Received: from [192.168.1.108] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id n23-20020ac86757000000b003a826e25bc4sm929314qtp.64.2022.12.22.13.44.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Dec 2022 13:44:27 -0800 (PST) Message-ID: <48f2a344-5f25-9c0b-a241-98920e4ce63c@redhat.com> Date: Thu, 22 Dec 2022 16:44:26 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH] c, c++, cgraphunit: Prevent duplicated -Wunused-value warnings [PR108079] To: Jakub Jelinek , "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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: On 12/22/22 05:32, Jakub Jelinek wrote: > 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? OK. > 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 >