MdePkg/DebugLib: 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 <mhaeuser@posteo.de>
This commit is contained in:
Marvin Häuser 2022-12-23 15:20:20 +01:00
parent 76b839a71f
commit 4f19426aec

View File

@ -557,7 +557,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.
@ -568,7 +573,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.