Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/48605 )

Change subject: base: Always compile the condition of chatty_assert.
......................................................................

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
---
M src/base/logging.hh
1 file changed, 12 insertions(+), 10 deletions(-)



diff --git a/src/base/logging.hh b/src/base/logging.hh
index 56396f8..2dd5aad 100644
--- a/src/base/logging.hh
+++ b/src/base/logging.hh
@@ -282,11 +282,17 @@
     } 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 @@
  *
  * @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__)); \
+                    ::gem5::csprintf(__VA_ARGS__)); \
     } while (0)
-#endif // NDEBUG
 /** @} */ // end of api_logger

 } // namespace gem5

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/48605
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ia5a6273c95f2e7bf1b7443751fed38c62e73b351
Gerrit-Change-Number: 48605
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to