From d54dd3bb525efdccaf057081c5e789461c06ce88 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Mon, 26 Jul 2021 18:06:40 -0700 Subject: [PATCH] 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 Reviewed-by: Jason Lowe-Power Maintainer: Daniel Carvalho Tested-by: kokoro --- src/base/logging.hh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/base/logging.hh b/src/base/logging.hh index 56396f8141..f00fa201a9 100644 --- a/src/base/logging.hh +++ b/src/base/logging.hh @@ -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(cond))) \ panic("assert(" # cond ") failed: %s", \ ::gem5::csprintf(__VA_ARGS__)); \ } while (0) -#endif // NDEBUG /** @} */ // end of api_logger } // namespace gem5