From nobody Wed May 15 03:34:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+112457+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112457+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1702417562; cv=none; d=zohomail.com; s=zohoarc; b=F/ztGKd3SO7OKk4sokbwwW4rOTx8iwELaukrDdCNGpsH0znzbNT5ki7jiUs6Sx94d5FLGJx0+GwsqSdUeICl/BzL/tz4HTU70zWlT0rDljMZ+iXi5s2wwFkAtKRV+xUDL6dN1dzLPNeuc+gEHERUC5KM3Mi2UQ3vmter9cZ8ADA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702417562; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=3bxpBWNJTTCN5G1iLcCoNpB/Evu4qMCalcGaAyk3p5k=; b=Q1KS2Z0kIUiJqu1yUZm+7KyKgc+zSJyCTTlqksdzqcDj1cCAwvmaSb0z3KZko5ef3Bkd+qLJcf+HFko34Facwqf0xRDN7XrfEZAxDxXDamo1tOrz18L2WWJRnJ4NgPbKd8llKJ7NutA71hAXS5DL1oiLqsAauxmh4HhhP9nTZ+g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112457+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1702417562858776.311623168437; Tue, 12 Dec 2023 13:46:02 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Oiw6/X6g/zRJLxbJnbLrIhYD+fzHdCLBiTuTy1lmigk=; 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=KA4xzNRp9hdGAAE1fPutb148R/SavuK5VNAxQH3C+AAdYrK0l/ez2BEpcieo3Rg5fWXpj6Wv grNuKXb4XiZotVw5oymyrXzQEVHpknxorl99FvJor7FLsBDcJyTEOf1ys5zJf7YuT+Cvj8z/bvz TS+8TGysINRy90Wx+QkVIgsY= X-Received: by 127.0.0.2 with SMTP id PWV6YY1788612x456y1lIlsg; 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: ECOKkMjUtP4YKlQDaxqTRPDtx1787277AA= 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: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1702417563985100001 Content-Type: text/plain; charset="utf-8" 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.t= emplate 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 =3D -Wl,--d= efsym=3DPECOFF_HEADER_SIZE=3D0x22 DEFINE CLANGDWARF_IA32_TARGET =3D -target i686-pc-linux-gnu DEFINE CLANGDWARF_X64_TARGET =3D -target x86_64-pc-linux-gnu =20 -DEFINE CLANGDWARF_WARNING_OVERRIDES =3D -Wno-parentheses-equality -Wno-= empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-opt= ion -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-unaligned-= access -Wno-unneeded-internal-declaration +DEFINE CLANGDWARF_WARNING_OVERRIDES =3D -Wno-parentheses-equality -Wno-= empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-opt= ion -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-unaligned-= access DEFINE CLANGDWARF_ALL_CC_FLAGS =3D DEF(GCC48_ALL_CC_FLAGS) DEF(CLA= NGDWARF_WARNING_OVERRIDES) -fno-stack-protector -mms-bitfields -Wno-address= -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-incompatible-library-r= edeclaration -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -msoft-float= -mno-implicit-float -ftrap-function=3Dundefined_behavior_has_been_optimiz= ed_away_by_clang -funsigned-char -fno-ms-extensions -Wno-null-dereference =20 ########################### diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/Deb= ugLib.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 --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-