Skip to content

Commit 49eb1ae

Browse files
[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
1 parent b66b176 commit 49eb1ae

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

libc/src/__support/libc_assert.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@
2525
#include "src/__support/integer_to_string.h"
2626
#include "src/__support/macros/attributes.h" // For LIBC_INLINE
2727

28+
namespace __llvm_libc {
29+
30+
// This is intended to be removed in a future patch to use a similar design to
31+
// below, but it's necessary for the external assert.
32+
LIBC_INLINE void report_assertion_failure(const char *assertion,
33+
const char *filename, unsigned line,
34+
const char *funcname) {
35+
char line_str[IntegerToString::dec_bufsize<unsigned>()];
36+
// dec returns an optional, will always be valid for this size buffer
37+
auto line_number = IntegerToString::dec(line, line_str);
38+
__llvm_libc::write_to_stderr(filename);
39+
__llvm_libc::write_to_stderr(":");
40+
__llvm_libc::write_to_stderr(*line_number);
41+
__llvm_libc::write_to_stderr(": Assertion failed: '");
42+
__llvm_libc::write_to_stderr(assertion);
43+
__llvm_libc::write_to_stderr("' in function: '");
44+
__llvm_libc::write_to_stderr(funcname);
45+
__llvm_libc::write_to_stderr("'\n");
46+
}
47+
48+
} // namespace __llvm_libc
49+
2850
#ifdef LIBC_ASSERT
2951
#error "Unexpected: LIBC_ASSERT macro already defined"
3052
#endif

0 commit comments

Comments
 (0)