From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sender-0.a4lg.com (mail-sender-0.a4lg.com [IPv6:2401:2500:203:30b:4000:6bfe:4757:0]) by sourceware.org (Postfix) with ESMTPS id E4F1C381DCD0; Thu, 15 Sep 2022 03:10:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E4F1C381DCD0 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=irq.a4lg.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=irq.a4lg.com Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 41870300089; Thu, 15 Sep 2022 03:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irq.a4lg.com; s=2017s01; t=1663211453; bh=W5fehORkCTZM0gX41LSOyh28oD+t9SJB02gpiY4t5AE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Mime-Version:Content-Transfer-Encoding; b=jPnNMhoFHbVs+hZev4d8nwKG7udamkjNdpVF56XO+VnYu/83tCyfxqbq/PZeoLrLz CSy+5AzmKQxHPyCfZpUOqvsho97bxc2rM/EjrTN6z5iNJWHNOV1nM7dIVLAr1+rnEY RG4vj+PIqr0/4aj3/LirkJr0T2MhmMm/xJkIftgo= From: Tsukasa OI To: Tsukasa OI , Pedro Alves , Joel Brobecker , Enze Li Cc: gdb-patches@sourceware.org, binutils@sourceware.org Subject: [PATCH 2/4] include: Add macro to ignore -Wunused-but-set-variable Date: Thu, 15 Sep 2022 03:10:24 +0000 Message-Id: <288e836e59e0e9307473fe0b0f717e54fbfb87c3.1663211419.git.research_trasio@irq.a4lg.com> In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: "-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 -- 2.34.1