1 //===-- Implementation of __assert_fail -----------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/assert/assert.h"
10 #include "src/stdlib/abort.h"
12 // These includes are temporary.
13 #include "config/linux/syscall.h" // For internal syscall function.
14 #include "include/sys/syscall.h" // For syscall numbers.
16 namespace __llvm_libc
{
18 // This is just a temporary solution to make assert available to internal
19 // llvm libc code. In the future writeToStderr will not exist and __assert_fail
20 // will call fprintf(stderr, ...).
21 static void writeToStderr(const char *s
) {
23 for (const char *curr
= s
; *curr
; ++curr
, ++length
);
24 __llvm_libc::syscall(SYS_write
, 2, s
, length
);
27 void LLVM_LIBC_ENTRYPOINT(__assert_fail
)(const char *assertion
, const char *file
,
28 unsigned line
, const char *function
) {
30 writeToStderr(": Assertion failed: '");
31 writeToStderr(assertion
);
32 writeToStderr("' in function: '");
33 writeToStderr(function
);
38 } // namespace __llvm_libc