From 6e4e45eb38ff5b9cdd29e69785d4715f154c219a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20H=C3=A4user?= <8659494+mhaeuser@users.noreply.github.com> Date: Fri, 23 Dec 2022 15:21:02 +0100 Subject: [PATCH] MdePkg/PerformanceLib: Fix "unused-but-set-variable" warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current definitions of PERF_CODE_BEGIN() and PERF_CODE_END() use the local variable __PerformanceCodeLocal as an attempt to track parity. If PERF_CODE_END() is used without a preceding PERF_CODE_BEGIN(), __PerformanceCodeLocal 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 __PerformanceCodeLocal 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, PERF_CODE_END() cannot be used without PERF_CODE_BEGIN(), as __PerformanceCodeLocal will be not have been defined. Signed-off-by: Marvin Häuser --- MdePkg/Include/Library/PerformanceLib.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/MdePkg/Include/Library/PerformanceLib.h b/MdePkg/Include/Library/PerformanceLib.h index 711e3fc06f..5ca72d4fd0 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.