From 0aa93aecb7e83b9eeaaac801b1e842eaf6423f08 Mon Sep 17 00:00:00 2001 From: Mike Beaton Date: Sat, 6 Apr 2024 23:06:38 +0100 Subject: [PATCH] MdePkg: Fix DEBUG_CODE and PERF_CODE macros for XCODE5 Without these changes, we get the error: error: variable '__DebugCodeLocal' set but not used from the DebugLib.h DEBUG_CODE_BEGIN()/END() macros on XCODE5. Similarly, in NOOPT builds only, we get: error: variable '__PerformanceCodeLocal' set but not used from the PerformanceLib.h PERF_CODE_BEGIN()/END() macros on XCODE5. It is important to note that the previous code involving a local variable was intended to ensure correct behaviour of ; following the macros, in particular that ; should be required: - https://github.com/tianocore/edk2/pull/6226#issuecomment-2364087866 - https://github.com/tianocore/edk2/pull/6226#issuecomment-2364619759 This converted version repeats the standard do { ... } while (FALSE) idiom (which is already used in the END macro) to achieve the same affect. The modified versions work on all toolchains. Signed-off-by: Mike Beaton --- MdePkg/Include/Library/DebugLib.h | 9 +++++++-- MdePkg/Include/Library/PerformanceLib.h | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h index fc5c83463d..b0742969a8 100644 --- a/MdePkg/Include/Library/DebugLib.h +++ b/MdePkg/Include/Library/DebugLib.h @@ -534,7 +534,10 @@ UnitTestDebugAssert ( are not included in a module. **/ -#define DEBUG_CODE_BEGIN() do { if (DebugCodeEnabled ()) { UINT8 __DebugCodeLocal +#define DEBUG_CODE_BEGIN() \ + do { \ + if (DebugCodeEnabled ()) { \ + do { } while (FALSE) /** The macro that marks the end of debug source code. @@ -545,7 +548,9 @@ UnitTestDebugAssert ( are not included in a module. **/ -#define DEBUG_CODE_END() __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE) +#define DEBUG_CODE_END() \ + } \ + } 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..40e99d0c4a 100644 --- a/MdePkg/Include/Library/PerformanceLib.h +++ b/MdePkg/Include/Library/PerformanceLib.h @@ -734,7 +734,10 @@ 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 { \ + if (PerformanceMeasurementEnabled ()) { \ + do { } while (FALSE) /** Macro that marks the end of performance measurement source code. @@ -744,7 +747,9 @@ 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 (FALSE) /** Macro that declares a section of performance measurement source code.