base: Always compile the condition of chatty_assert.

The condition must always be valid code and will always exist to
satisfy the compiler as far as what variables are used, etc, but it
will only actually be evaluated if NDEBUG is not set.

Change-Id: Ia5a6273c95f2e7bf1b7443751fed38c62e73b351
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/48605
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Daniel Carvalho <odanrc@yahoo.com.br>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2021-07-26 18:06:40 -07:00
parent 97760cb5a3
commit d54dd3bb52

View File

@@ -282,11 +282,17 @@ class Logger
} while (0)
/** @} */ // end of api_logger
#ifdef NDEBUG
#define NDEBUG_DEFINED 1
#else
#define NDEBUG_DEFINED 0
#endif
/**
* The chatty assert macro will function like a normal assert, but will allow
* the specification of additional, helpful material to aid debugging why the
* assertion actually failed. Like the normal assertion, the chatty_assert
* will not be active in fast builds.
* assertion actually failed. chatty_assert will not actually check its
* condition for fast builds, but the condition must still be valid code.
*
* @param cond Condition that is checked; if false -> assert
* @param ... Printf-based format string with arguments, extends printout.
@@ -295,16 +301,12 @@ class Logger
*
* @ingroup api_logger
*/
#ifdef NDEBUG
#define chatty_assert(cond, ...)
#else //!NDEBUG
#define chatty_assert(cond, ...) \
do { \
if (GEM5_UNLIKELY(!(cond))) \
#define chatty_assert(cond, ...) \
do { \
if (GEM5_UNLIKELY(!NDEBUG_DEFINED && !static_cast<bool>(cond))) \
panic("assert(" # cond ") failed: %s", \
::gem5::csprintf(__VA_ARGS__)); \
} while (0)
#endif // NDEBUG
/** @} */ // end of api_logger
} // namespace gem5