[AA] Pass query info.
[llvm-project.git] / libc / src / assert / __assert_fail.cpp
blob8b75a3bfeb70ce7ad60141e5eefd93dc8884074d
1 //===-- Implementation of __assert_fail -----------------------------------===//
2 //
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
6 //
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) {
22 size_t length = 0;
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) {
29 writeToStderr(file);
30 writeToStderr(": Assertion failed: '");
31 writeToStderr(assertion);
32 writeToStderr("' in function: '");
33 writeToStderr(function);
34 writeToStderr("'\n");
35 __llvm_libc::abort();
38 } // namespace __llvm_libc