From d18a96e8564bf2b70123602c9c8f129f7cd06158 Mon Sep 17 00:00:00 2001 From: Maurice Ma Date: Tue, 29 Oct 2019 12:18:09 -0700 Subject: [PATCH] Replace ASSERT macro in DebugLib for klocwork scanning This patch replace the standard ASSERT macro with klocwork specific implementation as indicated on: https://docs.roguewave.com/en/klocwork/current/tuningccanalysis This can provide hints to klocwork scanning on the ASSERT() statement so as to avoid false positives. Signed-off-by: Maurice Ma --- MdePkg/Include/Library/DebugLib.h | 36 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h index 2d6c91ff..13e851af 100644 --- a/MdePkg/Include/Library/DebugLib.h +++ b/MdePkg/Include/Library/DebugLib.h @@ -289,10 +289,14 @@ DebugPrintLevelEnabled ( @param Expression Boolean expression that evaluated to FALSE **/ -#ifdef LITE_PRINT -#define _ASSERT(Expression) DebugAssert (gEfiCallerBaseName, __LINE__, "") +#ifdef __KLOCWORK__ + #define _ASSERT(Expression) do { if (!(Expression)) abort(); } while (0) #else -#define _ASSERT(Expression) DebugAssert (__FILE__, __LINE__, #Expression) + #ifdef LITE_PRINT + #define _ASSERT(Expression) DebugAssert (gEfiCallerBaseName, __LINE__, "") + #else + #define _ASSERT(Expression) DebugAssert (__FILE__, __LINE__, #Expression) + #endif #endif /** @@ -332,18 +336,22 @@ DebugPrintLevelEnabled ( @param Expression Boolean expression. **/ -#if !defined(MDEPKG_NDEBUG) - #define ASSERT(Expression) \ - do { \ - if (DebugAssertEnabled ()) { \ - if (!(Expression)) { \ - _ASSERT (Expression); \ - ANALYZER_UNREACHABLE (); \ - } \ - } \ - } while (FALSE) +#ifdef __KLOCWORK__ + #define ASSERT(Expression) _ASSERT (Expression) #else - #define ASSERT(Expression) + #if !defined(MDEPKG_NDEBUG) + #define ASSERT(Expression) \ + do { \ + if (DebugAssertEnabled ()) { \ + if (!(Expression)) { \ + _ASSERT (Expression); \ + ANALYZER_UNREACHABLE (); \ + } \ + } \ + } while (FALSE) + #else + #define ASSERT(Expression) + #endif #endif /**