From 82e796ffa477fe31a30b7fe17626258b23e9d728 Mon Sep 17 00:00:00 2001 From: Mikhail Krichanov Date: Fri, 28 Apr 2023 10:36:34 +0300 Subject: [PATCH] MdePkg: DebugLib: Compilation fix for clang-13 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3704 build -a X64 -t CLANG38 -b RELEASE -p OvmfPkg/OvmfPkgX64.dsc results in UDK/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c:1284:31: error: variable 'Status' set but not used [-Werror,-Wunused-but-set-variable] Signed-off-by: Mikhail Krichanov MdePkg/DebugLib(PerformanceLib): Fix "unused-but-set-variable" warning The current definitions of DEBUG_CODE_BEGIN() and DEBUG_CODE_END() use the local variable __DebugCodeLocal as an attempt to track parity. If DEBUG_CODE_END() is used without a preceding DEBUG_CODE_BEGIN(), __DebugCodeLocal will not have been declared and a compilation error will be issued. The mutations of the variable are not used to track nesting or such. As the value of this variable is never actually used, recent Clang versions issue a "unused-but-set-variable" warning for it. To solve this, re-define __DebugCodeLocal as a BOOLEAN that is always FALSE and use it in a do-while loop condition as done explicitly in many places. Like the previous solution, DEBUG_CODE_END() cannot be used without DEBUG_CODE_BEGIN(), as __DebugCodeLocal will be not have been defined. Signed-off-by: Marvin Häuser --- .../DebugPeCoffExtraActionLib.c | 4 +- .../AArch64/DefaultExceptionHandler.c | 3 -- MdePkg/Include/Library/DebugLib.h | 43 ++++++++++++++++--- MdePkg/Include/Library/PerformanceLib.h | 12 +++++- 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.c b/ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.c index 432112354f..c5c53ef3e1 100644 --- a/ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.c +++ b/ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.c @@ -71,7 +71,7 @@ PeCoffLoaderRelocateImageExtraAction ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - #if !defined (MDEPKG_NDEBUG) + #if defined (__CC_ARM) || defined (__GNUC__) CHAR8 Temp[512]; #endif @@ -106,7 +106,7 @@ PeCoffLoaderUnloadImageExtraAction ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - #if !defined (MDEPKG_NDEBUG) + #if defined (__CC_ARM) || defined (__GNUC__) CHAR8 Temp[512]; #endif diff --git a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c index a39896d576..1d3ea61311 100644 --- a/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c +++ b/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c @@ -157,7 +157,6 @@ DescribeExceptionSyndrome ( DEBUG ((DEBUG_ERROR, "\n %a \n", Message)); } -#ifndef MDEPKG_NDEBUG STATIC CONST CHAR8 * BaseName ( @@ -177,8 +176,6 @@ BaseName ( return Str; } -#endif - /** This is the default action to take on an unexpected exception diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h index f0c9f64487..86a939c42f 100644 --- a/MdePkg/Include/Library/DebugLib.h +++ b/MdePkg/Include/Library/DebugLib.h @@ -403,7 +403,12 @@ UnitTestDebugAssert ( } \ } while (FALSE) #else -#define ASSERT(Expression) +#define ASSERT(Expression) \ + do { \ + if ((FALSE)) { \ + (VOID) (Expression); \ + } \ + } while (FALSE) #endif /** @@ -425,6 +430,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 @@ -452,7 +467,12 @@ UnitTestDebugAssert ( } \ } while (FALSE) #else -#define ASSERT_EFI_ERROR(StatusParameter) +#define ASSERT_EFI_ERROR(StatusParameter) \ + do { \ + if ((FALSE)) { \ + (VOID) (StatusParameter); \ + } \ + } while (FALSE) #endif /** @@ -479,7 +499,12 @@ UnitTestDebugAssert ( } \ } while (FALSE) #else -#define ASSERT_RETURN_ERROR(StatusParameter) +#define ASSERT_RETURN_ERROR(StatusParameter) \ + do { \ + if ((FALSE)) { \ + (VOID) (StatusParameter); \ + } \ + } while (FALSE) #endif /** @@ -534,7 +559,12 @@ UnitTestDebugAssert ( are not included in a module. **/ -#define DEBUG_CODE_BEGIN() do { if (DebugCodeEnabled ()) { UINT8 __DebugCodeLocal +#define DEBUG_CODE_BEGIN() \ + do { \ + BOOLEAN __DebugCodeLocal; \ + __DebugCodeLocal = FALSE; \ + do { \ + if (DebugCodeEnabled ()) { /** The macro that marks the end of debug source code. @@ -545,7 +575,10 @@ UnitTestDebugAssert ( are not included in a module. **/ -#define DEBUG_CODE_END() __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE) +#define DEBUG_CODE_END() \ + } \ + } while (__DebugCodeLocal); \ + } while (FALSE) /** The macro that declares a section of debug source code. diff --git a/MdePkg/Include/Library/PerformanceLib.h b/MdePkg/Include/Library/PerformanceLib.h index d0f2dfb070..57ba45eb7b 100644 --- a/MdePkg/Include/Library/PerformanceLib.h +++ b/MdePkg/Include/Library/PerformanceLib.h @@ -734,7 +734,12 @@ LogPerformanceMeasurement ( Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module. **/ -#define PERF_CODE_BEGIN() do { if (PerformanceMeasurementEnabled ()) { UINT8 __PerformanceCodeLocal +#define PERF_CODE_BEGIN() \ + do { \ + BOOLEAN __PerformanceCodeLocal; \ + __PerformanceCodeLocal = FALSE; \ + do { \ + if (PerformanceMeasurementEnabled ()) { /** Macro that marks the end of performance measurement source code. @@ -744,7 +749,10 @@ LogPerformanceMeasurement ( Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module. **/ -#define PERF_CODE_END() __PerformanceCodeLocal = 0; __PerformanceCodeLocal++; } } while (FALSE) +#define PERF_CODE_END() \ + } \ + } while (__PerformanceCodeLocal); \ + } while (FALSE) /** Macro that declares a section of performance measurement source code.