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: 35670 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp247963wrn; Thu, 22 Dec 2022 02:33:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXsNX7Qj3QVb/3fwT26ScIUIL99Z7AUCFFtkh9YDezqZQIaewMaKd3NGkLCoAOg8EYyHMJMU X-Received: by 2002:aa7:d04e:0:b0:45c:835b:ac4d with SMTP id n14-20020aa7d04e000000b0045c835bac4dmr4418793edo.8.1671705223144; Thu, 22 Dec 2022 02:33:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671705223; cv=none; d=google.com; s=arc-20160816; b=RsDzvCc8CrreW+6plAuyV3K81C4JxkNnsFCGd1oMUQJzOYaG6hye4QVPC+ZPEHR0Mb +cIYLmsQBWLlfukxlcN4mRGuJuTKl+CUqW6Q9zJgoC9ZTysg8wnvNFUWQwYLd4jJ7bAx qLKhO0zghNLN3COtVnjllfDLq/6nefzmnEVOkNK3H40Qs5bEc9jN+SW2bGN4CCYirep+ qdXTo1UOKZPyJ4zdCxkQ3+f+P3KTJi2thZLYO85srGmT7FOcLTWdeTgRgXAxN5WQ42jy 3JWXpopc58AvATMw0ws1dbO8KtJDDv1dSiQWAQLg2Mj9HdGSMnxe9Ng7u0aDuAh+b9eL K0DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=kR80+l008ec+Lfru4RYJj6GN3SuAUwCXDTeZ9m35Pyw=; b=L5l/QoJKAf7elAF2e3DMzgptoYojEdbv7Gngh9guGNxFfLK+rPFQNHdO7HY8MZNFtR esBIBH7XK6R1Orzygx3xfckGhguLVES6l9rHVdLt5rC58493HmIcwMm2D2ob4JJgXy+h mKyKOx2doMYMSO2sp1Tq00PFzCBQ6tSAOmlPAi0KOP8tVNhLi0Y/kdC4QkxlHl+eaCYJ kGv6M9UYGGDX2kd7XeCbYwiFRPD701mzFWqTnzgS5zPiqa3KAkgRWxIWj6lTewtERO3D UddyZHbanG28hqLCuLHh+ZTWghhn/M+bQjAOWrS87wBPKW+HsilZyhDP9mMkrkA+ZPyW e9tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IIpLZEUi; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w10-20020aa7d28a000000b0046c2e73c826si369683edq.622.2022.12.22.02.33.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 02:33:43 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IIpLZEUi; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2518C3857B8E for ; Thu, 22 Dec 2022 10:33:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2518C3857B8E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671705222; 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=IIpLZEUikiVBVNuy0xhow0m95F5sYFRcVwZN/PE2X5o5/xHPUazC2FqXWOEH3ADs0 8J7zPhVHZs/lvgRj6l5P69G+yV+AJHF6KOOXpovb220+j+D8APYmk6QItaOm9tb6Lu 4IoFXf4HYPcDotSdoQH/F6BGNz/jLt6W9mV+8HWs= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752909975775558074?= X-GMAIL-MSGID: =?utf-8?q?1752909975775558074?= 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 } */ +}