Skip to content

Commit

Permalink
DebugLib: Simplify DEBUG and ASSERT macros used when MDEPKG_NDEBUG is…
Browse files Browse the repository at this point in the history
… defined

The variants provided when MDEPKG_NDEBUG is defined will be optimised
away in RELEASE builds, but by referencing the argument (or argument list,
in the case of DEBUG) avoid unused variable errors from valid debug code,
for example when STATIC variables are used only in DEBUG statements.
  • Loading branch information
mikebeaton committed Dec 13, 2023
1 parent 8023b33 commit 892bba0
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions MdePkg/Include/Library/DebugLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,9 @@ UnitTestDebugAssert (
} while (FALSE)
#else
#define ASSERT(Expression) \
do { \
if ((FALSE)) { \
(VOID) (Expression); \
} \
} while (FALSE)
if (FALSE) { \
(VOID) (Expression); \
}
#endif

/**
Expand All @@ -433,18 +431,11 @@ UnitTestDebugAssert (
_DEBUG (Expression); \
} \
} while (FALSE)
#elif defined (__GNUC__) || defined (__clang__)
#define DEBUG(Expression) \
do { \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wunused-value\"") \
if ((FALSE)) { \
(VOID) Expression; \
} \
_Pragma("GCC diagnostic pop") \
} while (FALSE)
#else
#define DEBUG(Expression)
#define DEBUG(Expression) \
if (FALSE) { \
_DEBUG (Expression); \
}
#endif

/**
Expand All @@ -471,11 +462,9 @@ UnitTestDebugAssert (
} while (FALSE)
#else
#define ASSERT_EFI_ERROR(StatusParameter) \
do { \
if ((FALSE)) { \
(VOID) (StatusParameter); \
} \
} while (FALSE)
if (FALSE) { \
(VOID) (StatusParameter); \
}
#endif

/**
Expand Down Expand Up @@ -503,11 +492,9 @@ UnitTestDebugAssert (
} while (FALSE)
#else
#define ASSERT_RETURN_ERROR(StatusParameter) \
do { \
if ((FALSE)) { \
(VOID) (StatusParameter); \
} \
} while (FALSE)
if (FALSE) { \
(VOID) (StatusParameter); \
}
#endif

/**
Expand Down

0 comments on commit 892bba0

Please sign in to comment.