From patchwork Thu Sep 22 08:25:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 57885 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 5AB56385742B for ; Thu, 22 Sep 2022 08:26:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5AB56385742B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663835198; bh=W5fehORkCTZM0gX41LSOyh28oD+t9SJB02gpiY4t5AE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=DtQmvv4bXipHuiSk4xpe9HGf6mc1vtqYVqBQQ27KqtFhwIF6wXGdPTdHkRRM5IQJx 9B1LNcZjnLg3HFe3FYssW8RVXoWhmrrRPh+ldOWTTIJ5SaC9z/XyKe2seaV8MkLLVL FTXLEz1yXAFeLdhjqt8H9wOKFx74Hzaj4YggUQ4o= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id 91E3B3857C52; Thu, 22 Sep 2022 08:26:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 91E3B3857C52 Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id DF926300089; Thu, 22 Sep 2022 08:26:10 +0000 (UTC) To: Tsukasa OI , Pedro Alves , Joel Brobecker , Enze Li Subject: [PATCH v2 2/4] include: Add macro to ignore -Wunused-but-set-variable Date: Thu, 22 Sep 2022 08:25:45 +0000 Message-Id: <6c1a2fe519fa913a0ad96e6debdec77ecdd9cdf6.1663835104.git.research_trasio@irq.a4lg.com> In-Reply-To: References: Mime-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tsukasa OI via Gdb-patches From: Tsukasa OI Reply-To: Tsukasa OI Cc: binutils@sourceware.org, gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" "-Wunused-but-set-variable" warning option can be helpful to track variables that are written but not read thereafter. But it can be harmful if some of the code is auto-generated and we have no ways to deal with it. The particular example is Bison-generated code. The new DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE macro can be helpful on such cases. A typical use of this macro is to place this macro before the end of user prologues on Bison (.y) files. include/ChangeLog: * diagnostics.h (DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE): New. --- include/diagnostics.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/diagnostics.h b/include/diagnostics.h index dbe6288d3d6..4161dff6abc 100644 --- a/include/diagnostics.h +++ b/include/diagnostics.h @@ -68,6 +68,11 @@ DIAGNOSTIC_IGNORE ("-Wuser-defined-warnings") # endif +# if __has_warning ("-Wunused-but-set-variable") +# define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE \ + DIAGNOSTIC_IGNORE ("-Wunused-but-set-variable") +# endif + # define DIAGNOSTIC_ERROR_SWITCH \ DIAGNOSTIC_ERROR ("-Wswitch") @@ -89,6 +94,11 @@ # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \ DIAGNOSTIC_IGNORE ("-Wformat-nonliteral") +# if __GNUC__ >= 5 +# define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE \ + DIAGNOSTIC_IGNORE ("-Wunused-but-set-variable") +# endif + /* GCC 4.8's "diagnostic push/pop" seems broken when using this, -Wswitch remains enabled at the error level even after a pop. Therefore, don't use it for GCC < 5. */ @@ -130,6 +140,10 @@ # define DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS #endif +#ifndef DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE +# define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE +#endif + #ifndef DIAGNOSTIC_ERROR_SWITCH # define DIAGNOSTIC_ERROR_SWITCH #endif