[libc-commits] [libc] [libc] improve error handling and compiler hints (PR #109026)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Tue Sep 17 13:52:20 PDT 2024


================
@@ -61,27 +105,22 @@ LIBC_INLINE void report_assertion_failure(const char *assertion,
   do {                                                                         \
   } while (false)
 #else
+#define LIBC_ASSERT(COND) LIBC_CHECK(COND)
+#endif // NDEBUG
+#endif // LIBC_COPT_USE_C_ASSERT
 
-// Convert __LINE__ to a string using macros. The indirection is necessary
-// because otherwise it will turn "__LINE__" into a string, not its value. The
-// value is evaluated in the indirection step.
-#define __LIBC_MACRO_TO_STR(x) #x
-#define __LIBC_MACRO_TO_STR_INDIR(y) __LIBC_MACRO_TO_STR(y)
-#define __LIBC_LINE_STR__ __LIBC_MACRO_TO_STR_INDIR(__LINE__)
-
-#define LIBC_ASSERT(COND)                                                      \
-  do {                                                                         \
-    if (!(COND)) {                                                             \
-      LIBC_NAMESPACE::write_to_stderr(__FILE__ ":" __LIBC_LINE_STR__           \
-                                               ": Assertion failed: '" #COND   \
-                                               "' in function: '");            \
-      LIBC_NAMESPACE::write_to_stderr(__PRETTY_FUNCTION__);                    \
-      LIBC_NAMESPACE::write_to_stderr("'\n");                                  \
-      LIBC_NAMESPACE::internal::exit(0xFF);                                    \
-    }                                                                          \
-  } while (false)
+#ifdef NDEBUG
+#define LIBC_ASSUME() LIBC_NAMESPACE::unsafe_assume(true)
----------------
michaelrj-google wrote:

```suggestion
#define LIBC_ASSUME(COND) LIBC_NAMESPACE::unsafe_assume(COND)
```

https://github.com/llvm/llvm-project/pull/109026


More information about the libc-commits mailing list