[libc-commits] [libc] 49eb1ae - [libc] Add back report_assertion_failure
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Tue Jul 25 16:34:58 PDT 2023
Author: Michael Jones
Date: 2023-07-25T16:34:53-07:00
New Revision: 49eb1aed89c06cb0c2508aa9e42cd0121f0aa23e
URL: https://github.com/llvm/llvm-project/commit/49eb1aed89c06cb0c2508aa9e42cd0121f0aa23e
DIFF: https://github.com/llvm/llvm-project/commit/49eb1aed89c06cb0c2508aa9e42cd0121f0aa23e.diff
LOG: [libc] Add back report_assertion_failure
It's necessary for the assert_fail function, so it needs to stay in for
the moment.
Reviewed By: alfredfo
Differential Revision: https://reviews.llvm.org/D156275
Added:
Modified:
libc/src/__support/libc_assert.h
Removed:
################################################################################
diff --git a/libc/src/__support/libc_assert.h b/libc/src/__support/libc_assert.h
index ff6ed52ecee33a..eabcce8071f340 100644
--- a/libc/src/__support/libc_assert.h
+++ b/libc/src/__support/libc_assert.h
@@ -25,6 +25,28 @@
#include "src/__support/integer_to_string.h"
#include "src/__support/macros/attributes.h" // For LIBC_INLINE
+namespace __llvm_libc {
+
+// This is intended to be removed in a future patch to use a similar design to
+// below, but it's necessary for the external assert.
+LIBC_INLINE void report_assertion_failure(const char *assertion,
+ const char *filename, unsigned line,
+ const char *funcname) {
+ char line_str[IntegerToString::dec_bufsize<unsigned>()];
+ // dec returns an optional, will always be valid for this size buffer
+ auto line_number = IntegerToString::dec(line, line_str);
+ __llvm_libc::write_to_stderr(filename);
+ __llvm_libc::write_to_stderr(":");
+ __llvm_libc::write_to_stderr(*line_number);
+ __llvm_libc::write_to_stderr(": Assertion failed: '");
+ __llvm_libc::write_to_stderr(assertion);
+ __llvm_libc::write_to_stderr("' in function: '");
+ __llvm_libc::write_to_stderr(funcname);
+ __llvm_libc::write_to_stderr("'\n");
+}
+
+} // namespace __llvm_libc
+
#ifdef LIBC_ASSERT
#error "Unexpected: LIBC_ASSERT macro already defined"
#endif
More information about the libc-commits
mailing list