From 80c73c39231df17ca066483c4bee5030d2f6c65f Mon Sep 17 00:00:00 2001 From: Mikhail Krichanov Date: Mon, 22 Jul 2024 12:37:00 +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 --- .../AArch64/DefaultExceptionHandler.c | 3 -- MdePkg/Include/Library/DebugLib.h | 40 ++++++++++++++++--- MdePkg/Include/Library/PerformanceLib.h | 12 +++++- 3 files changed, 44 insertions(+), 11 deletions(-) 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 0db3b78ec8..4c073825c2 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 /** @@ -426,7 +431,12 @@ UnitTestDebugAssert ( } \ } while (FALSE) #else -#define DEBUG(Expression) +#define DEBUG(Expression) \ + do { \ + if (FALSE) { \ + _DEBUG (Expression); \ + } \ + } while (FALSE) #endif /** @@ -452,7 +462,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 +494,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 +554,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 +570,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.