From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id B7526AC1B4D for ; Tue, 12 Dec 2023 21:46:03 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=UkhKYAQmp4iXPUTkuX6a2M618yEWIIOEHQPedW98IN0=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1702417562; v=1; b=r16Qzp6sgDfB3yaoJgWKhUdc8t9SbtVGQeUS/aJ0oMtGr70aXPi48jJaGKy7XUln6HIaCAI6 gXf3fUFNp0iKSwrwYiiHgNqKtSd9ttni8EoT/AEvAQ8XDO3b48PuNpY76l+wP3u9ZAKKhZv2nE6 mwm5jXyBrByJC267aneaCXMc= X-Received: by 127.0.0.2 with SMTP id 9yhRYY7687511xtkaeFTRcV8; Tue, 12 Dec 2023 13:46:02 -0800 X-Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by mx.groups.io with SMTP id smtpd.web10.8919.1702417561503766056 for ; Tue, 12 Dec 2023 13:46:01 -0800 X-Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-40c0fc1cf3dso63918725e9.0 for ; Tue, 12 Dec 2023 13:46:01 -0800 (PST) X-Gm-Message-State: 9QZMK2FnG81Lt5ImV75daIXOx7686176AA= X-Google-Smtp-Source: AGHT+IHjFSFOBhVlf/SG/4LwLKJshX8qzLcFc21OYZIXKQL84q10IDItuAPCA3QZpZCXlrmfZ+IFag== X-Received: by 2002:a05:600c:1d12:b0:401:d803:624f with SMTP id l18-20020a05600c1d1200b00401d803624fmr3225950wms.4.1702417559037; Tue, 12 Dec 2023 13:45:59 -0800 (PST) X-Received: from mikes-OptiPlex-3070.lan ([95.82.41.203]) by smtp.gmail.com with ESMTPSA id gw18-20020a05600c851200b004053e9276easm20124187wmb.32.2023.12.12.13.45.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 13:45:58 -0800 (PST) From: "Mike Beaton" To: devel@edk2.groups.io Cc: ardb@google.com, lersek@redhat.com, Mikhail Krichanov , Mike Beaton Subject: [edk2-devel] [PATCH V2] DebugLib: Allow -Wunneeded-internal-declaration with clang Date: Tue, 12 Dec 2023 21:45:25 +0000 Message-Id: <20231212214524.49914-1-mjsbeaton@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mjsbeaton@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=r16Qzp6s; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: Mikhail Krichanov Provides a variant of the DEBUG macro for clang when MDEPKG_NDEBUG is defined, which uses but discards the contained expression. This means clang can tell that it has optimised away variable usage as part of valid debug patterns (such as a STATIC variable which is only used in DEBUG statements) - rather than just seeing such variables as completely unused - therefore we can keep -Wunneeded-internal-declaration (as part of -Wall) to warn about mistakenly genuinely unused variables elsewhere. Note that the _Pragma in the clang/gcc variant is to temporarily suppress the warning about `(VOID) Expression;`, whilst the presence of `(VOID) Expression;` (once allowed) is what prevents the unwanted warning about unneeded variables. Signed-off-by: Mikhail Krichanov Signed-off-by: Mike Beaton --- BaseTools/Conf/tools_def.template | 2 +- MdePkg/Include/Library/DebugLib.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index c34ecfd557..eaccf0b698 100755 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -1859,7 +1859,7 @@ DEFINE CLANGDWARF_X64_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x22 DEFINE CLANGDWARF_IA32_TARGET = -target i686-pc-linux-gnu DEFINE CLANGDWARF_X64_TARGET = -target x86_64-pc-linux-gnu -DEFINE CLANGDWARF_WARNING_OVERRIDES = -Wno-parentheses-equality -Wno-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-option -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-unaligned-access -Wno-unneeded-internal-declaration +DEFINE CLANGDWARF_WARNING_OVERRIDES = -Wno-parentheses-equality -Wno-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-option -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-unaligned-access DEFINE CLANGDWARF_ALL_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) DEF(CLANGDWARF_WARNING_OVERRIDES) -fno-stack-protector -mms-bitfields -Wno-address -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-incompatible-library-redeclaration -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -msoft-float -mno-implicit-float -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -funsigned-char -fno-ms-extensions -Wno-null-dereference ########################### diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h index 40772f2e0f..7368004f46 100644 --- a/MdePkg/Include/Library/DebugLib.h +++ b/MdePkg/Include/Library/DebugLib.h @@ -425,6 +425,16 @@ UnitTestDebugAssert ( _DEBUG (Expression); \ } \ } while (FALSE) +#elif defined (__GNUC__) || defined (__clang__) +#define DEBUG(Expression) \ + do { \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wunused-value\"") \ + if ((FALSE)) { \ + (VOID) Expression; \ + } \ + _Pragma("GCC diagnostic pop") \ + } while (FALSE) #else #define DEBUG(Expression) #endif -- 2.39.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#112457): https://edk2.groups.io/g/devel/message/112457 Mute This Topic: https://groups.io/mt/103138778/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-