[libc-commits] [PATCH] D156275: [libc] Add back report_assertion_failure
Michael Jones via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Jul 25 16:33:18 PDT 2023
michaelrj created this revision.
michaelrj added reviewers: alfredfo, lntue, sivachandra.
Herald added projects: libc-project, All.
Herald added a subscriber: libc-commits.
michaelrj requested review of this revision.
It's necessary for the assert_fail function, so it needs to stay in for
the moment.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156275
Files:
libc/src/__support/libc_assert.h
Index: libc/src/__support/libc_assert.h
===================================================================
--- libc/src/__support/libc_assert.h
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156275.544144.patch
Type: text/x-patch
Size: 1367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230725/53c64b65/attachment.bin>
More information about the libc-commits
mailing list