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 2E368AC1BE8 for ; Tue, 12 Dec 2023 21:48:57 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=YgkOIpBAUfCjgt6bO92qY/clBzo20jbuoPSc1Wbzb4Q=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20140610; t=1702417735; v=1; b=Biyynk9Bpgcu4oAAItU3ZaygC67yotlmWahc/uyJR/abQUMGgmtwLPfNDyjRzFKax1glGPwB 4/8FInxd9lrKssbYNcandmFHu+aDr226G5SQttVdfV46aK22sRLqQnis/jw4o1fYHko+619VVPX Q9FH7LWA8oJUgdkKeWIiGbNE= X-Received: by 127.0.0.2 with SMTP id JNOeYY7687511x3xGkGxNkeR; Tue, 12 Dec 2023 13:48:55 -0800 X-Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by mx.groups.io with SMTP id smtpd.web10.8976.1702417735097407831 for ; Tue, 12 Dec 2023 13:48:55 -0800 X-Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3333224c7b9so5369779f8f.1 for ; Tue, 12 Dec 2023 13:48:54 -0800 (PST) X-Gm-Message-State: MyPsdGvB3ireNg9yrInKnqI5x7686176AA= X-Google-Smtp-Source: AGHT+IF3f3DHEh9eZYjU+CkU7TQv0dB+J/t6aEuHFmMjvZJT3YFOYkOta3wdl4RetPUOLtd0gCx90urqMxTq8fK0uv4= X-Received: by 2002:a5d:534d:0:b0:320:8e6:b0cf with SMTP id t13-20020a5d534d000000b0032008e6b0cfmr3378630wrv.42.1702417733105; Tue, 12 Dec 2023 13:48:53 -0800 (PST) MIME-Version: 1.0 References: <20231212214524.49914-1-mjsbeaton@gmail.com> In-Reply-To: <20231212214524.49914-1-mjsbeaton@gmail.com> From: "Mike Beaton" Date: Tue, 12 Dec 2023 21:48:41 +0000 Message-ID: Subject: Re: [edk2-devel] [PATCH V2] DebugLib: Allow -Wunneeded-internal-declaration with clang To: devel@edk2.groups.io Cc: ardb@google.com, lersek@redhat.com, Mikhail Krichanov 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-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=Biyynk9B; 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 On Tue, 12 Dec 2023 at 21:45, wrote: > > 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 =3D -Wl,-= -defsym=3DPECOFF_HEADER_SIZE=3D0x22 > DEFINE CLANGDWARF_IA32_TARGET =3D -target i686-pc-linux-gnu > DEFINE CLANGDWARF_X64_TARGET =3D -target x86_64-pc-linux-gn= u > > -DEFINE CLANGDWARF_WARNING_OVERRIDES =3D -Wno-parentheses-equality -Wn= o-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-o= ption -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-unaligne= d-access -Wno-unneeded-internal-declaration > +DEFINE CLANGDWARF_WARNING_OVERRIDES =3D -Wno-parentheses-equality -Wn= o-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-o= ption -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-unaligne= d-access > DEFINE CLANGDWARF_ALL_CC_FLAGS =3D DEF(GCC48_ALL_CC_FLAGS) DEF(C= LANGDWARF_WARNING_OVERRIDES) -fno-stack-protector -mms-bitfields -Wno-addre= ss -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-incompatible-library= -redeclaration -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -msoft-flo= at -mno-implicit-float -ftrap-function=3Dundefined_behavior_has_been_optim= ized_away_by_clang -funsigned-char -fno-ms-extensions -Wno-null-dereference > > ########################### > diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/D= ebugLib.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 > Hi Mikhail, Are you okay to reply confirming that you're happy with your Signed-off-by in the above? Thanks, Mike -=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 (#112458): https://edk2.groups.io/g/devel/message/112458 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] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-