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