diff --git a/libc/src/assert/CMakeLists.txt b/libc/src/assert/CMakeLists.txt --- a/libc/src/assert/CMakeLists.txt +++ b/libc/src/assert/CMakeLists.txt @@ -3,6 +3,7 @@ SRCS __assert_fail.cpp HDRS + __assert_fail.h assert.h DEPENDS # These two dependencies are temporary and should be replaced by fprintf diff --git a/libc/src/assert/__assert_fail.h b/libc/src/assert/__assert_fail.h new file mode 100644 --- /dev/null +++ b/libc/src/assert/__assert_fail.h @@ -0,0 +1,21 @@ +//===-- Internal header for __assert_fail -----------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_ASSERT_ASSERT_FAIL_H +#define LLVM_LIBC_SRC_ASSERT_ASSERT_FAIL_H + +#include + +namespace __llvm_libc { + +[[noreturn]] void __assert_fail(const char *assertion, const char *file, + unsigned line, const char *function); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_ASSERT_ASSERT_FAIL_H diff --git a/libc/src/assert/__assert_fail.cpp b/libc/src/assert/__assert_fail.cpp --- a/libc/src/assert/__assert_fail.cpp +++ b/libc/src/assert/__assert_fail.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/assert/assert.h" +#include "src/assert/__assert_fail.h" #include "src/stdlib/abort.h" // These includes are temporary. diff --git a/libc/src/assert/assert.h b/libc/src/assert/assert.h --- a/libc/src/assert/assert.h +++ b/libc/src/assert/assert.h @@ -6,19 +6,11 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SRC_ASSERT_ASSERT_H -#define LLVM_LIBC_SRC_ASSERT_ASSERT_H +#include "src/assert/__assert_fail.h" -#include - -namespace __llvm_libc { - -[[noreturn]] void __assert_fail(const char *assertion, const char *file, unsigned line, - const char *function); - -} // namespace __llvm_libc - -#endif // LLVM_LIBC_SRC_ASSERT_ASSERT_H +// There is no header guard here since assert is intended to be able to be +// able to be included multiple times with NDEBUG defined differently, causing +// different behavior. #undef assert diff --git a/libc/src/errno/CMakeLists.txt b/libc/src/errno/CMakeLists.txt --- a/libc/src/errno/CMakeLists.txt +++ b/libc/src/errno/CMakeLists.txt @@ -1,7 +1,8 @@ add_entrypoint_object( __errno_location SRCS - errno_location.cpp + __errno_location.cpp HDRS + __errno_location.h llvmlibc_errno.h ) diff --git a/libc/src/errno/llvmlibc_errno.h b/libc/src/errno/__errno_location.h copy from libc/src/errno/llvmlibc_errno.h copy to libc/src/errno/__errno_location.h --- a/libc/src/errno/llvmlibc_errno.h +++ b/libc/src/errno/__errno_location.h @@ -1,4 +1,4 @@ -//===-- Implementation header for errno -------------------------*- C++ -*-===// +//===-- Implementation header for __errno_location --------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,12 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H -#define LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H - -// Internal code should use this and not use the errno macro from the -// public header. -#define llvmlibc_errno (*__llvm_libc::__errno_location()) +#ifndef LLVM_LIBC_SRC_ERRNO_ERRNO_LOCATION_H +#define LLVM_LIBC_SRC_ERRNO_ERRNO_LOCATION_H namespace __llvm_libc { @@ -19,4 +15,4 @@ } // namespace __llvm_libc -#endif // LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H +#endif // LLVM_LIBC_SRC_ERRNO_ERRNO_LOCATION_H diff --git a/libc/src/errno/errno_location.cpp b/libc/src/errno/__errno_location.cpp rename from libc/src/errno/errno_location.cpp rename to libc/src/errno/__errno_location.cpp --- a/libc/src/errno/errno_location.cpp +++ b/libc/src/errno/__errno_location.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/errno/llvmlibc_errno.h" +#include "src/errno/__errno_location.h" #include "src/__support/common.h" diff --git a/libc/src/errno/llvmlibc_errno.h b/libc/src/errno/llvmlibc_errno.h --- a/libc/src/errno/llvmlibc_errno.h +++ b/libc/src/errno/llvmlibc_errno.h @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include "src/errno/__errno_location.h" + #ifndef LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H #define LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H @@ -13,10 +15,4 @@ // public header. #define llvmlibc_errno (*__llvm_libc::__errno_location()) -namespace __llvm_libc { - -int *__errno_location(); - -} // namespace __llvm_libc - #endif // LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H