Gabe Black has submitted this change. ( 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
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/48605
Reviewed-by: Daniel Carvalho <[email protected]>
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Daniel Carvalho <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/base/logging.hh
1 file changed, 11 insertions(+), 9 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved
Daniel Carvalho: Looks good to me, but someone else must approve; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/base/logging.hh b/src/base/logging.hh
index 56396f8..f00fa20 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__)); \
     } 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: 3
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-CC: Gabe Black <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to