MdePkg/PerformanceLib: Fix "unused-but-set-variable" warning

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 <mhaeuser@posteo.de>
This commit is contained in:
Marvin Häuser 2022-12-23 15:21:02 +01:00
parent 4f19426aec
commit 6e4e45eb38

View File

@ -734,7 +734,12 @@ LogPerformanceMeasurement (
Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module. 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. 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. 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. Macro that declares a section of performance measurement source code.