[libc-commits] [libc] [llvm] [libc] Decouple LIBC_ASSERT failure handling and raise SIGABRT in full-build mode (PR #239277)
Aman Maurya via libc-commits
libc-commits at lists.llvm.org
Wed Nov 11 12:10:45 PST 2026
https://github.com/amanmaurya92 updated https://github.com/llvm/llvm-project/pull/239277
>From a3602734d0cad4d4c089133c4f9ab8066672b20e Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Thu, 5 Nov 2026 21:13:03 +0530
Subject: [PATCH 1/9] [libc] Decouple LIBC_ASSERT failure handling and raise
SIGABRT in full-build mode
Decouple LIBC_ASSERT and LIBC_REQUIRE assertion failure handling in full-build mode by forward-declaring __assert_fail in libc_assert.h instead of inlining write_to_stderr and calling internal::exit(0xFF).
This resolves the long-standing FIXME in libc_assert.h:
- Eliminates circular dependencies between __support, stdlib (abort), and signal (RawRwLock / SigAbortGuard) at the header level.
- Calls __assert_fail which triggers abort_utils::abort(), raising SIGABRT in full-build mode and bringing LLVM libc in line with LSB requirements and debugger stop-on-signal expectations.
- Adds an atomic re-entrancy guard in __assert_fail to prevent infinite recursion if an assertion failure occurs inside abort or locking routines.
- Links __assert_fail into hermetic unit test support targets.
- Updates unique_ptr_test to expect SIGABRT across both overlay and full-build configurations.
---
libc/src/__support/libc_assert.h | 22 +++++++++----------
libc/src/assert/generic/CMakeLists.txt | 1 +
libc/src/assert/generic/__assert_fail.cpp | 7 ++++++
libc/test/UnitTest/CMakeLists.txt | 8 +++++++
.../src/__support/CPP/unique_ptr_test.cpp | 6 -----
.../llvm-project-overlay/libc/BUILD.bazel | 1 -
6 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/libc/src/__support/libc_assert.h b/libc/src/__support/libc_assert.h
index 81135fe1b3d501..d4cd63d7303ba5 100644
--- a/libc/src/__support/libc_assert.h
+++ b/libc/src/__support/libc_assert.h
@@ -17,7 +17,6 @@
#include "src/__support/macros/properties/os.h"
#ifdef LIBC_FULL_BUILD
-#include "src/__support/OSUtil/exit.h"
#include "src/__support/OSUtil/io.h"
#include "src/__support/integer_to_string.h"
#endif
@@ -44,19 +43,18 @@
} while (false)
#endif // LIBC_TARGET_OS_IS_LINUX
#else
-// FIXME: Calling abort on assertion is actually required by standards like LSB.
-// Calling exit also confuses the debugger as exiting will not trigger
-// debugger's stop-on-signal behavior by default. Currently, adding abort will
-// result in cyclic dependency.
+namespace LIBC_NAMESPACE_DECL {
+// Forward declaration of __assert_fail to decouple assertion failure
+// handling and abort from internal header dependencies.
+[[noreturn]] void __assert_fail(const char *assertion, const char *file,
+ unsigned line, const char *function);
+} // namespace LIBC_NAMESPACE_DECL
+
#define LIBC_REQUIRE(COND, MSG) \
do { \
- if (LIBC_UNLIKELY(!(COND))) { \
- LIBC_NAMESPACE::write_to_stderr(__FILE__ ":" LLVM_LIBC_STRINGIFY( \
- __LINE__) ": Assertion failed: '" MSG "' in function: '"); \
- LIBC_NAMESPACE::write_to_stderr(__PRETTY_FUNCTION__); \
- LIBC_NAMESPACE::write_to_stderr("'\n"); \
- LIBC_NAMESPACE::internal::exit(0xFF); \
- } \
+ if (LIBC_UNLIKELY(!(COND))) \
+ LIBC_NAMESPACE::__assert_fail(MSG, __FILE__, __LINE__, \
+ __PRETTY_FUNCTION__); \
} while (false)
#endif // LIBC_FULL_BUILD
diff --git a/libc/src/assert/generic/CMakeLists.txt b/libc/src/assert/generic/CMakeLists.txt
index 95e47610576bc7..8bdf08fe75effd 100644
--- a/libc/src/assert/generic/CMakeLists.txt
+++ b/libc/src/assert/generic/CMakeLists.txt
@@ -7,6 +7,7 @@ add_entrypoint_object(
../assert.h
DEPENDS
libc.include.assert
+ libc.src.__support.CPP.atomic
libc.src.__support.OSUtil.osutil
libc.src.stdlib.abort_utils
)
diff --git a/libc/src/assert/generic/__assert_fail.cpp b/libc/src/assert/generic/__assert_fail.cpp
index c3ea0307965902..48c686a2d44ca7 100644
--- a/libc/src/assert/generic/__assert_fail.cpp
+++ b/libc/src/assert/generic/__assert_fail.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "src/assert/__assert_fail.h"
+#include "src/__support/CPP/atomic.h"
#include "src/__support/OSUtil/io.h"
#include "src/__support/libc_assert.h"
#include "src/__support/macros/config.h"
@@ -17,6 +18,12 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(void, __assert_fail,
(const char *assertion, const char *file, unsigned line,
const char *function)) {
+ // Re-entrancy guard: if an assertion fails inside the abort or lock sequence,
+ // trap immediately to prevent infinite recursion.
+ static cpp::Atomic<bool> in_assertion{false};
+ if (in_assertion.exchange(true, cpp::MemoryOrder::ACQUIRE))
+ __builtin_trap();
+
LIBC_NAMESPACE::report_assertion_failure(assertion, file, line, function);
LIBC_NAMESPACE::abort_utils::abort();
}
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index 2a135457400061..0b40928958a4c7 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -138,6 +138,11 @@ if(LIBC_TEST_SUBPROCESS_TESTS)
libc.include.llvm-libc-types.pid_t
libc.include.llvm-libc-types.struct_pollfd
)
+ if(TARGET libc.src.assert.__assert_fail)
+ list(APPEND libc_death_test_deps
+ libc.src.assert.__assert_fail
+ )
+ endif()
if(TARGET libc.src.sys.prctl.prctl)
list(APPEND libc_death_test_deps
libc.src.sys.prctl.prctl
@@ -171,6 +176,9 @@ set(libc_hermetic_test_support_deps
libc.hdr.stdint_proxy
libc.src.__support.libc_errno
)
+if(TARGET libc.src.assert.__assert_fail)
+ list(APPEND libc_hermetic_test_support_deps libc.src.assert.__assert_fail)
+endif()
if(LIBC_TARGET_OS_IS_BAREMETAL)
if(LIBC_TARGET_ARCHITECTURE_IS_ARM)
list(APPEND libc_hermetic_test_support_srcs ArmBaremetalTestUtils.cpp)
diff --git a/libc/test/src/__support/CPP/unique_ptr_test.cpp b/libc/test/src/__support/CPP/unique_ptr_test.cpp
index 7e26a8e3449b3a..07d0438bc39c59 100644
--- a/libc/test/src/__support/CPP/unique_ptr_test.cpp
+++ b/libc/test/src/__support/CPP/unique_ptr_test.cpp
@@ -260,13 +260,7 @@ TEST(LlvmLibcUniquePtrTest, BaseDerivedConversion) {
}
#ifndef NDEBUG
-// In full builds, LIBC_ASSERT exits with code 0xFF. Otherwise, it uses the
-// system assert, which raises SIGABRT.
-#if defined(LIBC_FULL_BUILD) && !defined(LIBC_COPT_USE_C_ASSERT)
-#define EXPECT_ASSERT_FAILURE(FUNC) EXPECT_EXITS(FUNC, 0xFF)
-#else
#define EXPECT_ASSERT_FAILURE(FUNC) EXPECT_DEATH(FUNC, WITH_SIGNAL(SIGABRT))
-#endif
// Test that dereferencing a null unique_ptr asserts.
TEST(LlvmLibcUniquePtrTest, NullDereferenceDeath) {
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 42e3ae6fffaf9c..a52b871270b536 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2366,7 +2366,6 @@ libc_support_library(
] + select({
":full_build": [
":__support_integer_to_string",
- ":__support_osutil_exit_hdrs",
":__support_osutil_io",
],
"//conditions:default": [],
>From ec1c262a8b7a6fff83f3402aa949f3687ab6e146 Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Thu, 5 Nov 2026 23:11:06 +0530
Subject: [PATCH 2/9] [libc] Fix CI failures for LIBC_ASSERT abort decoupling
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 3 +++
libc/src/__support/libc_assert.h | 2 +-
libc/test/UnitTest/CMakeLists.txt | 8 --------
libc/test/src/__support/CPP/unique_ptr_test.cpp | 4 ++--
4 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index f86f79af2d3bd2..bac4690777ac17 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -499,6 +499,9 @@ function(_get_libc_test_dependencies output_var user_depends startup_target_dep
if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
list(APPEND fq_deps_list libc.src.compiler.__stack_chk_fail)
endif()
+ if(libc.src.assert.__assert_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
+ list(APPEND fq_deps_list libc.src.assert.__assert_fail)
+ endif()
if(NOT is_integration_test)
list(APPEND fq_deps_list libc.test.UnitTest.HermeticTestUtils)
if(LIBC_TARGET_ARCHITECTURE_IS_AARCH64 AND NOT(LIBC_TARGET_OS_IS_BAREMETAL))
diff --git a/libc/src/__support/libc_assert.h b/libc/src/__support/libc_assert.h
index d4cd63d7303ba5..f2651990f3b685 100644
--- a/libc/src/__support/libc_assert.h
+++ b/libc/src/__support/libc_assert.h
@@ -53,7 +53,7 @@ namespace LIBC_NAMESPACE_DECL {
#define LIBC_REQUIRE(COND, MSG) \
do { \
if (LIBC_UNLIKELY(!(COND))) \
- LIBC_NAMESPACE::__assert_fail(MSG, __FILE__, __LINE__, \
+ LIBC_NAMESPACE::__assert_fail(MSG, __FILE__, __LINE__, \
__PRETTY_FUNCTION__); \
} while (false)
#endif // LIBC_FULL_BUILD
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index 0b40928958a4c7..2a135457400061 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -138,11 +138,6 @@ if(LIBC_TEST_SUBPROCESS_TESTS)
libc.include.llvm-libc-types.pid_t
libc.include.llvm-libc-types.struct_pollfd
)
- if(TARGET libc.src.assert.__assert_fail)
- list(APPEND libc_death_test_deps
- libc.src.assert.__assert_fail
- )
- endif()
if(TARGET libc.src.sys.prctl.prctl)
list(APPEND libc_death_test_deps
libc.src.sys.prctl.prctl
@@ -176,9 +171,6 @@ set(libc_hermetic_test_support_deps
libc.hdr.stdint_proxy
libc.src.__support.libc_errno
)
-if(TARGET libc.src.assert.__assert_fail)
- list(APPEND libc_hermetic_test_support_deps libc.src.assert.__assert_fail)
-endif()
if(LIBC_TARGET_OS_IS_BAREMETAL)
if(LIBC_TARGET_ARCHITECTURE_IS_ARM)
list(APPEND libc_hermetic_test_support_srcs ArmBaremetalTestUtils.cpp)
diff --git a/libc/test/src/__support/CPP/unique_ptr_test.cpp b/libc/test/src/__support/CPP/unique_ptr_test.cpp
index 07d0438bc39c59..5279baf0deb24d 100644
--- a/libc/test/src/__support/CPP/unique_ptr_test.cpp
+++ b/libc/test/src/__support/CPP/unique_ptr_test.cpp
@@ -259,7 +259,7 @@ TEST(LlvmLibcUniquePtrTest, BaseDerivedConversion) {
ASSERT_EQ(base_ptr->val, 100);
}
-#ifndef NDEBUG
+#if !defined(NDEBUG) && defined(SIGABRT)
#define EXPECT_ASSERT_FAILURE(FUNC) EXPECT_DEATH(FUNC, WITH_SIGNAL(SIGABRT))
// Test that dereferencing a null unique_ptr asserts.
@@ -274,4 +274,4 @@ TEST(LlvmLibcUniquePtrTest, NullDereferenceDeath) {
unique_ptr<int[]> arr;
EXPECT_ASSERT_FAILURE([&] { (void)arr[0]; });
}
-#endif // NDEBUG
+#endif // !defined(NDEBUG) && defined(SIGABRT)
>From b2b91f26b49b6a257061ab77aa9792b35d95216c Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Sat, 7 Nov 2026 23:32:20 +0530
Subject: [PATCH 3/9] [libc][bazel] Add __assert_fail target and dependencies
for full-build mode
---
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 14 ++++++++++++++
.../libc/test/UnitTest/BUILD.bazel | 1 +
.../libc/test/libc_test_rules.bzl | 1 +
3 files changed, 16 insertions(+)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index a52b871270b536..a3408eabe273d4 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -17177,6 +17177,20 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__assert_fail",
+ srcs = ["src/assert/generic/__assert_fail.cpp"],
+ hdrs = ["src/assert/__assert_fail.h"],
+ full_build_only = True,
+ deps = [
+ ":__support_cpp_atomic",
+ ":__support_libc_assert",
+ ":__support_macros_config",
+ ":__support_osutil_io",
+ ":stdlib_abort_utils",
+ ],
+)
+
libc_support_library(
name = "qsort_util",
hdrs = [
diff --git a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
index bc1be3481c3587..35ed4d663f657f 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
@@ -124,6 +124,7 @@ libc_test_library(
"//conditions:default": ["@platforms//:incompatible"],
}),
deps = [
+ "//libc:__assert_fail",
"//libc:__support_common",
"//libc:__support_libc_errno",
"//libc:__support_macros_config",
diff --git a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
index 54f9cdaac025dc..116ecd2a5789c4 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
+++ b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
@@ -66,6 +66,7 @@ def libc_test(
# The compiler may emit references to symbols it expects to exist,
# like `memset`. These dependencies hermetically provide them.
"//libc/test/UnitTest:HermeticTestUtils",
+ "//libc:__assert_fail",
"//libc:__stack_chk_fail", # Needed if -fstack-protector is set.
],
"//conditions:default": [],
>From 1e673edebcd7113171bcf0d188b0ae7ecb74a69a Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Mon, 9 Nov 2026 22:17:56 +0530
Subject: [PATCH 4/9] [libc] Drop reentrancy guard in __assert_fail per review
---
libc/src/assert/generic/CMakeLists.txt | 1 -
libc/src/assert/generic/__assert_fail.cpp | 7 -------
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 1 -
3 files changed, 9 deletions(-)
diff --git a/libc/src/assert/generic/CMakeLists.txt b/libc/src/assert/generic/CMakeLists.txt
index 8bdf08fe75effd..95e47610576bc7 100644
--- a/libc/src/assert/generic/CMakeLists.txt
+++ b/libc/src/assert/generic/CMakeLists.txt
@@ -7,7 +7,6 @@ add_entrypoint_object(
../assert.h
DEPENDS
libc.include.assert
- libc.src.__support.CPP.atomic
libc.src.__support.OSUtil.osutil
libc.src.stdlib.abort_utils
)
diff --git a/libc/src/assert/generic/__assert_fail.cpp b/libc/src/assert/generic/__assert_fail.cpp
index 48c686a2d44ca7..c3ea0307965902 100644
--- a/libc/src/assert/generic/__assert_fail.cpp
+++ b/libc/src/assert/generic/__assert_fail.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "src/assert/__assert_fail.h"
-#include "src/__support/CPP/atomic.h"
#include "src/__support/OSUtil/io.h"
#include "src/__support/libc_assert.h"
#include "src/__support/macros/config.h"
@@ -18,12 +17,6 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(void, __assert_fail,
(const char *assertion, const char *file, unsigned line,
const char *function)) {
- // Re-entrancy guard: if an assertion fails inside the abort or lock sequence,
- // trap immediately to prevent infinite recursion.
- static cpp::Atomic<bool> in_assertion{false};
- if (in_assertion.exchange(true, cpp::MemoryOrder::ACQUIRE))
- __builtin_trap();
-
LIBC_NAMESPACE::report_assertion_failure(assertion, file, line, function);
LIBC_NAMESPACE::abort_utils::abort();
}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index a3408eabe273d4..4adb39c25de252 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -17183,7 +17183,6 @@ libc_support_library(
hdrs = ["src/assert/__assert_fail.h"],
full_build_only = True,
deps = [
- ":__support_cpp_atomic",
":__support_libc_assert",
":__support_macros_config",
":__support_osutil_io",
>From e9ae53198dede75bde680372beb7c316eb70f5d5 Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Wed, 11 Nov 2026 05:02:20 +0530
Subject: [PATCH 5/9] [libc] Route LIBC_REQUIRE to internal::assert_fail
Move assertion failure handling logic into internal::assert_fail so that internal __support macros do not directly call public entrypoint functions, and forward __assert_fail to internal::assert_fail.
---
libc/src/__support/libc_assert.h | 12 +++++++-----
libc/src/assert/__assert_fail.h | 6 ++++++
libc/src/assert/generic/__assert_fail.cpp | 12 ++++++++++--
libc/src/assert/gpu/__assert_fail.cpp | 14 +++++++++++---
4 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/libc/src/__support/libc_assert.h b/libc/src/__support/libc_assert.h
index f2651990f3b685..8db88ee646b241 100644
--- a/libc/src/__support/libc_assert.h
+++ b/libc/src/__support/libc_assert.h
@@ -44,17 +44,19 @@
#endif // LIBC_TARGET_OS_IS_LINUX
#else
namespace LIBC_NAMESPACE_DECL {
-// Forward declaration of __assert_fail to decouple assertion failure
+namespace internal {
+// Forward declaration of internal::assert_fail to decouple assertion failure
// handling and abort from internal header dependencies.
-[[noreturn]] void __assert_fail(const char *assertion, const char *file,
- unsigned line, const char *function);
+[[noreturn]] void assert_fail(const char *assertion, const char *file,
+ unsigned line, const char *function);
+} // namespace internal
} // namespace LIBC_NAMESPACE_DECL
#define LIBC_REQUIRE(COND, MSG) \
do { \
if (LIBC_UNLIKELY(!(COND))) \
- LIBC_NAMESPACE::__assert_fail(MSG, __FILE__, __LINE__, \
- __PRETTY_FUNCTION__); \
+ LIBC_NAMESPACE::internal::assert_fail(MSG, __FILE__, __LINE__, \
+ __PRETTY_FUNCTION__); \
} while (false)
#endif // LIBC_FULL_BUILD
diff --git a/libc/src/assert/__assert_fail.h b/libc/src/assert/__assert_fail.h
index bbc0aa8e2bf236..d7c21810b8e2ca 100644
--- a/libc/src/assert/__assert_fail.h
+++ b/libc/src/assert/__assert_fail.h
@@ -13,6 +13,12 @@
#include <stddef.h>
namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+[[noreturn]] void assert_fail(const char *assertion, const char *file,
+ unsigned line, const char *function);
+
+} // namespace internal
[[noreturn]] void __assert_fail(const char *assertion, const char *file,
unsigned line, const char *function);
diff --git a/libc/src/assert/generic/__assert_fail.cpp b/libc/src/assert/generic/__assert_fail.cpp
index c3ea0307965902..3a94f8342d1e0e 100644
--- a/libc/src/assert/generic/__assert_fail.cpp
+++ b/libc/src/assert/generic/__assert_fail.cpp
@@ -13,12 +13,20 @@
#include "src/stdlib/abort_utils.h"
namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+[[noreturn]] void assert_fail(const char *assertion, const char *file,
+ unsigned line, const char *function) {
+ LIBC_NAMESPACE::report_assertion_failure(assertion, file, line, function);
+ LIBC_NAMESPACE::abort_utils::abort();
+}
+
+} // namespace internal
LLVM_LIBC_FUNCTION(void, __assert_fail,
(const char *assertion, const char *file, unsigned line,
const char *function)) {
- LIBC_NAMESPACE::report_assertion_failure(assertion, file, line, function);
- LIBC_NAMESPACE::abort_utils::abort();
+ internal::assert_fail(assertion, file, line, function);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/assert/gpu/__assert_fail.cpp b/libc/src/assert/gpu/__assert_fail.cpp
index 2580f29fd13b59..119682747d266c 100644
--- a/libc/src/assert/gpu/__assert_fail.cpp
+++ b/libc/src/assert/gpu/__assert_fail.cpp
@@ -16,13 +16,13 @@
#include "src/stdlib/abort_utils.h"
namespace LIBC_NAMESPACE_DECL {
+namespace internal {
// A single-use lock to allow only a single thread to print the assertion.
static cpp::Atomic<uint32_t> lock = 0;
-LLVM_LIBC_FUNCTION(void, __assert_fail,
- (const char *assertion, const char *file, unsigned line,
- const char *function)) {
+[[noreturn]] void assert_fail(const char *assertion, const char *file,
+ unsigned line, const char *function) {
uint64_t mask = gpu::get_lane_mask();
// We only want a single work group or warp to handle the assertion. Each
// group attempts to claim the lock, if it is already claimed we simply exit.
@@ -39,4 +39,12 @@ LLVM_LIBC_FUNCTION(void, __assert_fail,
LIBC_NAMESPACE::abort_utils::abort();
}
+} // namespace internal
+
+LLVM_LIBC_FUNCTION(void, __assert_fail,
+ (const char *assertion, const char *file, unsigned line,
+ const char *function)) {
+ internal::assert_fail(assertion, file, line, function);
+}
+
} // namespace LIBC_NAMESPACE_DECL
>From ef4b9dccabfdc7e6fe62913b0ae7e98f397945e6 Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Wed, 11 Nov 2026 10:41:26 +0530
Subject: [PATCH 6/9] [libc] Update death tests to expect signal abort and fix
formatting
---
libc/src/__support/libc_assert.h | 2 +-
libc/test/src/__support/checked_ptr_test.cpp | 4 ----
libc/test/src/__support/freelist_heap_death_test.cpp | 6 +++---
3 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/libc/src/__support/libc_assert.h b/libc/src/__support/libc_assert.h
index 8db88ee646b241..ed06b74d1ee9d1 100644
--- a/libc/src/__support/libc_assert.h
+++ b/libc/src/__support/libc_assert.h
@@ -55,7 +55,7 @@ namespace internal {
#define LIBC_REQUIRE(COND, MSG) \
do { \
if (LIBC_UNLIKELY(!(COND))) \
- LIBC_NAMESPACE::internal::assert_fail(MSG, __FILE__, __LINE__, \
+ LIBC_NAMESPACE::internal::assert_fail(MSG, __FILE__, __LINE__, \
__PRETTY_FUNCTION__); \
} while (false)
#endif // LIBC_FULL_BUILD
diff --git a/libc/test/src/__support/checked_ptr_test.cpp b/libc/test/src/__support/checked_ptr_test.cpp
index 700dc090dce93e..4b95a762de5d70 100644
--- a/libc/test/src/__support/checked_ptr_test.cpp
+++ b/libc/test/src/__support/checked_ptr_test.cpp
@@ -227,11 +227,7 @@ TEST(LlvmLibcCheckedPtrTest, TakeUnique) {
#if !defined(NDEBUG) && LIBC_TEST_SUBPROCESS_TESTS
-#if defined(LIBC_FULL_BUILD) && !defined(LIBC_COPT_USE_C_ASSERT)
-#define EXPECT_ASSERT_FAILS(stmt) EXPECT_EXITS(stmt, 255)
-#else
#define EXPECT_ASSERT_FAILS(stmt) EXPECT_DEATH(stmt, WITH_SIGNAL(-1))
-#endif
TEST(LlvmLibcCheckedPtrDeathTest, UncheckedDestructionDies) {
EXPECT_ASSERT_FAILS([] {
diff --git a/libc/test/src/__support/freelist_heap_death_test.cpp b/libc/test/src/__support/freelist_heap_death_test.cpp
index 0ae663ba496412..74ede415b85367 100644
--- a/libc/test/src/__support/freelist_heap_death_test.cpp
+++ b/libc/test/src/__support/freelist_heap_death_test.cpp
@@ -27,12 +27,12 @@ TEST(LlvmLibcFreeListHeapDeathTest, DoubleFreeDeath) {
allocator.free(ptr);
#if defined(ENABLE_SUBPROCESS_TESTS) && \
LIBC_COPT_HARDENING_MODE > LIBC_HARDENING_MODE_FAST
- EXPECT_EXITS(
+ EXPECT_DEATH(
[&] {
allocator.free(ptr);
allocator.integrity_check();
},
- 255);
+ WITH_SIGNAL(-1));
#endif
}
@@ -45,6 +45,6 @@ TEST(LlvmLibcFreeListHeapDeathTest, UseAfterFreeDeath) {
#if defined(ENABLE_SUBPROCESS_TESTS) && \
LIBC_COPT_HARDENING_MODE > LIBC_HARDENING_MODE_FAST
new (ptr) uintptr_t{0xDEADBEEF};
- EXPECT_EXITS([&] { allocator.integrity_check(); }, 255);
+ EXPECT_DEATH([&] { allocator.integrity_check(); }, WITH_SIGNAL(-1));
#endif
}
>From 44ee8a2e1059e4233b2dacbfce349ccabf67c3b5 Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Wed, 11 Nov 2026 19:00:54 +0530
Subject: [PATCH 7/9] [libc] Move internal::assert_fail into OSUtil and split
libc_assert targets
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 3 -
libc/src/__support/CMakeLists.txt | 58 +++++++-----
libc/src/__support/OSUtil/CMakeLists.txt | 29 ++++++
libc/src/__support/OSUtil/assert_fail.h | 23 +++++
libc/src/__support/OSUtil/assert_fail_utils.h | 37 ++++++++
.../__support/OSUtil/baremetal/CMakeLists.txt | 12 +++
.../OSUtil/baremetal/assert_fail.cpp | 24 +++++
.../__support/OSUtil/darwin/CMakeLists.txt | 11 +++
.../__support/OSUtil/darwin/assert_fail.cpp | 24 +++++
.../__support/OSUtil/freebsd/CMakeLists.txt | 11 +++
.../__support/OSUtil/freebsd/assert_fail.cpp | 24 +++++
libc/src/__support/OSUtil/gpu/CMakeLists.txt | 14 +++
.../OSUtil/gpu/assert_fail.cpp} | 16 +---
.../src/__support/OSUtil/linux/CMakeLists.txt | 12 +++
.../__support/OSUtil/linux/assert_fail.cpp | 24 +++++
libc/src/__support/OSUtil/uefi/CMakeLists.txt | 11 +++
.../src/__support/OSUtil/uefi/assert_fail.cpp | 24 +++++
.../__support/OSUtil/windows/CMakeLists.txt | 11 +++
.../__support/OSUtil/windows/assert_fail.cpp | 24 +++++
libc/src/__support/libc_assert.h | 32 +------
libc/src/assert/__assert_fail.h | 6 --
libc/src/assert/generic/CMakeLists.txt | 5 +-
libc/src/assert/generic/__assert_fail.cpp | 13 +--
libc/src/assert/gpu/CMakeLists.txt | 14 ---
libc/test/src/__support/CPP/CMakeLists.txt | 1 -
.../src/__support/CPP/unique_ptr_test.cpp | 13 ++-
libc/test/src/__support/checked_ptr_test.cpp | 90 +++++++++++--------
.../llvm-project-overlay/libc/BUILD.bazel | 79 +++++++++++-----
.../libc/test/UnitTest/BUILD.bazel | 1 -
.../libc/test/libc_test_rules.bzl | 1 -
30 files changed, 476 insertions(+), 171 deletions(-)
create mode 100644 libc/src/__support/OSUtil/assert_fail.h
create mode 100644 libc/src/__support/OSUtil/assert_fail_utils.h
create mode 100644 libc/src/__support/OSUtil/baremetal/assert_fail.cpp
create mode 100644 libc/src/__support/OSUtil/darwin/assert_fail.cpp
create mode 100644 libc/src/__support/OSUtil/freebsd/assert_fail.cpp
rename libc/src/{assert/gpu/__assert_fail.cpp => __support/OSUtil/gpu/assert_fail.cpp} (74%)
create mode 100644 libc/src/__support/OSUtil/linux/assert_fail.cpp
create mode 100644 libc/src/__support/OSUtil/uefi/assert_fail.cpp
create mode 100644 libc/src/__support/OSUtil/windows/assert_fail.cpp
delete mode 100644 libc/src/assert/gpu/CMakeLists.txt
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index bac4690777ac17..f86f79af2d3bd2 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -499,9 +499,6 @@ function(_get_libc_test_dependencies output_var user_depends startup_target_dep
if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
list(APPEND fq_deps_list libc.src.compiler.__stack_chk_fail)
endif()
- if(libc.src.assert.__assert_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
- list(APPEND fq_deps_list libc.src.assert.__assert_fail)
- endif()
if(NOT is_integration_test)
list(APPEND fq_deps_list libc.test.UnitTest.HermeticTestUtils)
if(LIBC_TARGET_ARCHITECTURE_IS_AARCH64 AND NOT(LIBC_TARGET_OS_IS_BAREMETAL))
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index a68f5e6b09d672..6363d0b091a079 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -445,27 +445,6 @@ add_header_library(
libc.src.__support.macros.properties.types
)
-if(LIBC_COPT_USE_C_ASSERT OR NOT LLVM_LIBC_FULL_BUILD)
- add_header_library(
- libc_assert
- HDRS
- libc_assert.h
- DEPENDS
- libc.src.__support.macros.hardening
- )
-else()
- add_header_library(
- libc_assert
- HDRS
- libc_assert.h
- DEPENDS
- .integer_to_string
- libc.src.__support.OSUtil.osutil
- libc.src.__support.macros.optimization
- libc.src.__support.macros.hardening
- )
-endif()
-
add_header_library(
hash
HDRS
@@ -515,6 +494,43 @@ add_header_library(
add_subdirectory(FPUtil)
add_subdirectory(OSUtil)
+
+set(libc_assert_hdrs_deps
+ libc.src.__support.macros.attributes
+ libc.src.__support.macros.config
+ libc.src.__support.macros.hardening
+ libc.src.__support.macros.macro-utils
+ libc.src.__support.macros.optimization
+ libc.src.__support.macros.properties.os
+)
+set(libc_assert_deps .libc_assert_hdrs)
+if(LLVM_LIBC_FULL_BUILD)
+ list(APPEND libc_assert_hdrs_deps
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ )
+ if(TARGET libc.src.__support.OSUtil.assert_fail)
+ list(APPEND libc_assert_deps
+ libc.src.__support.OSUtil.assert_fail
+ )
+ endif()
+endif()
+
+add_header_library(
+ libc_assert_hdrs
+ HDRS
+ libc_assert.h
+ DEPENDS
+ ${libc_assert_hdrs_deps}
+)
+
+add_header_library(
+ libc_assert
+ HDRS
+ libc_assert.h
+ DEPENDS
+ ${libc_assert_deps}
+)
+
add_subdirectory(StringUtil)
add_subdirectory(GPU)
add_subdirectory(RPC)
diff --git a/libc/src/__support/OSUtil/CMakeLists.txt b/libc/src/__support/OSUtil/CMakeLists.txt
index da5158a850bef0..da4fe1d3189ef7 100644
--- a/libc/src/__support/OSUtil/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/CMakeLists.txt
@@ -1,3 +1,21 @@
+add_header_library(
+ assert_fail_hdrs
+ HDRS
+ assert_fail.h
+ DEPENDS
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ assert_fail_utils
+ HDRS
+ assert_fail_utils.h
+ DEPENDS
+ libc.src.__support.integer_to_string
+ libc.src.__support.macros.attributes
+ libc.src.__support.macros.config
+)
+
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
return()
endif()
@@ -14,6 +32,17 @@ if(TARGET ${target_os_util})
)
endif()
+set(target_assert_fail libc.src.__support.OSUtil.${LIBC_TARGET_OS}.assert_fail)
+if(TARGET ${target_assert_fail})
+ add_object_library(
+ assert_fail
+ ALIAS
+ ${target_assert_fail}
+ DEPENDS
+ ${target_assert_fail}
+ )
+endif()
+
set(target_path libc.src.__support.OSUtil.${LIBC_TARGET_OS}.path)
if(TARGET ${target_path})
add_header_library(
diff --git a/libc/src/__support/OSUtil/assert_fail.h b/libc/src/__support/OSUtil/assert_fail.h
new file mode 100644
index 00000000000000..d80cef5aaead26
--- /dev/null
+++ b/libc/src/__support/OSUtil/assert_fail.h
@@ -0,0 +1,23 @@
+//===-- 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___SUPPORT_OSUTIL_ASSERT_FAIL_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_ASSERT_FAIL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+[[noreturn]] void assert_fail(const char *assertion, const char *file,
+ unsigned line, const char *function);
+
+} // namespace internal
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_ASSERT_FAIL_H
diff --git a/libc/src/__support/OSUtil/assert_fail_utils.h b/libc/src/__support/OSUtil/assert_fail_utils.h
new file mode 100644
index 00000000000000..254478e2a1ab86
--- /dev/null
+++ b/libc/src/__support/OSUtil/assert_fail_utils.h
@@ -0,0 +1,37 @@
+//===-- Assertion failure reporting helper ----------------------*- 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___SUPPORT_OSUTIL_ASSERT_FAIL_UTILS_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_ASSERT_FAIL_UTILS_H
+
+#include "src/__support/OSUtil/io.h"
+#include "src/__support/integer_to_string.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+LIBC_INLINE void report_assertion_failure(const char *assertion,
+ const char *filename, unsigned line,
+ const char *funcname) {
+ const IntegerToString<unsigned> line_buffer(line);
+ write_to_stderr(filename);
+ write_to_stderr(":");
+ write_to_stderr(line_buffer.view());
+ write_to_stderr(": Assertion failed: '");
+ write_to_stderr(assertion);
+ write_to_stderr("' in function: '");
+ write_to_stderr(funcname);
+ write_to_stderr("'\n");
+}
+
+} // namespace internal
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_ASSERT_FAIL_UTILS_H
diff --git a/libc/src/__support/OSUtil/baremetal/CMakeLists.txt b/libc/src/__support/OSUtil/baremetal/CMakeLists.txt
index 8f9200ad0bd96e..df12cff7cce9b2 100644
--- a/libc/src/__support/OSUtil/baremetal/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/baremetal/CMakeLists.txt
@@ -9,3 +9,15 @@ add_object_library(
libc.src.__support.common
libc.src.__support.CPP.string_view
)
+
+add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .baremetal_util
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+ libc.src.stdlib.abort_utils
+)
diff --git a/libc/src/__support/OSUtil/baremetal/assert_fail.cpp b/libc/src/__support/OSUtil/baremetal/assert_fail.cpp
new file mode 100644
index 00000000000000..da29b2b4159a25
--- /dev/null
+++ b/libc/src/__support/OSUtil/baremetal/assert_fail.cpp
@@ -0,0 +1,24 @@
+//===-- Baremetal implementation of internal::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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/OSUtil/assert_fail.h"
+#include "src/__support/OSUtil/assert_fail_utils.h"
+#include "src/__support/macros/config.h"
+#include "src/stdlib/abort_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+[[noreturn]] void assert_fail(const char *assertion, const char *file,
+ unsigned line, const char *function) {
+ report_assertion_failure(assertion, file, line, function);
+ LIBC_NAMESPACE::abort_utils::abort();
+}
+
+} // namespace internal
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/OSUtil/darwin/CMakeLists.txt b/libc/src/__support/OSUtil/darwin/CMakeLists.txt
index 40aa7daab07503..b8f45569d62b07 100644
--- a/libc/src/__support/OSUtil/darwin/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/darwin/CMakeLists.txt
@@ -18,3 +18,14 @@ add_object_library(
libc.src.__support.CPP.string_view
libc.include.sys_syscall
)
+
+add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .darwin_util
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/OSUtil/darwin/assert_fail.cpp b/libc/src/__support/OSUtil/darwin/assert_fail.cpp
new file mode 100644
index 00000000000000..bd7da39b3f96c2
--- /dev/null
+++ b/libc/src/__support/OSUtil/darwin/assert_fail.cpp
@@ -0,0 +1,24 @@
+//===-- Darwin implementation of internal::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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/OSUtil/assert_fail.h"
+#include "src/__support/OSUtil/assert_fail_utils.h"
+#include "src/__support/OSUtil/exit.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+[[noreturn]] void assert_fail(const char *assertion, const char *file,
+ unsigned line, const char *function) {
+ report_assertion_failure(assertion, file, line, function);
+ internal::exit(0xFF);
+}
+
+} // namespace internal
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/OSUtil/freebsd/CMakeLists.txt b/libc/src/__support/OSUtil/freebsd/CMakeLists.txt
index a635feb37b1206..0315c721655fea 100644
--- a/libc/src/__support/OSUtil/freebsd/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/freebsd/CMakeLists.txt
@@ -16,3 +16,14 @@ add_object_library(
libc.src.__support.OSUtil.freebsd.syscall_wrappers.write
libc.src.__support.macros.config
)
+
+add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .freebsd_util
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/OSUtil/freebsd/assert_fail.cpp b/libc/src/__support/OSUtil/freebsd/assert_fail.cpp
new file mode 100644
index 00000000000000..de37a3dd757971
--- /dev/null
+++ b/libc/src/__support/OSUtil/freebsd/assert_fail.cpp
@@ -0,0 +1,24 @@
+//===-- FreeBSD implementation of internal::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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/OSUtil/assert_fail.h"
+#include "src/__support/OSUtil/assert_fail_utils.h"
+#include "src/__support/OSUtil/exit.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+[[noreturn]] void assert_fail(const char *assertion, const char *file,
+ unsigned line, const char *function) {
+ report_assertion_failure(assertion, file, line, function);
+ internal::exit(0xFF);
+}
+
+} // namespace internal
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/OSUtil/gpu/CMakeLists.txt b/libc/src/__support/OSUtil/gpu/CMakeLists.txt
index 6cb3aa30f249ef..d64c57b15f3599 100644
--- a/libc/src/__support/OSUtil/gpu/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/gpu/CMakeLists.txt
@@ -11,3 +11,17 @@ add_object_library(
libc.src.__support.RPC.rpc_client
libc.src.string.memory_utils.inline_memcpy
)
+
+add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .gpu_util
+ libc.src.__support.CPP.atomic
+ libc.src.__support.GPU.utils
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+ libc.src.stdlib.abort_utils
+)
diff --git a/libc/src/assert/gpu/__assert_fail.cpp b/libc/src/__support/OSUtil/gpu/assert_fail.cpp
similarity index 74%
rename from libc/src/assert/gpu/__assert_fail.cpp
rename to libc/src/__support/OSUtil/gpu/assert_fail.cpp
index 119682747d266c..5e794c399871f6 100644
--- a/libc/src/assert/gpu/__assert_fail.cpp
+++ b/libc/src/__support/OSUtil/gpu/assert_fail.cpp
@@ -1,4 +1,4 @@
-//===-- GPU definition of a libc internal assert macro ----------*- C++ -*-===//
+//===-- GPU implementation of internal::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.
@@ -6,12 +6,11 @@
//
//===----------------------------------------------------------------------===//
-#include "src/assert/__assert_fail.h"
+#include "src/__support/OSUtil/assert_fail.h"
#include "src/__support/CPP/atomic.h"
#include "src/__support/GPU/utils.h"
-#include "src/__support/common.h"
-#include "src/__support/libc_assert.h"
+#include "src/__support/OSUtil/assert_fail_utils.h"
#include "src/__support/macros/config.h"
#include "src/stdlib/abort_utils.h"
@@ -34,17 +33,10 @@ static cpp::Atomic<uint32_t> lock = 0;
// Only a single line should be printed if an assertion is hit.
if (gpu::is_first_lane(mask))
- LIBC_NAMESPACE::report_assertion_failure(assertion, file, line, function);
+ report_assertion_failure(assertion, file, line, function);
gpu::sync_lane(mask);
LIBC_NAMESPACE::abort_utils::abort();
}
} // namespace internal
-
-LLVM_LIBC_FUNCTION(void, __assert_fail,
- (const char *assertion, const char *file, unsigned line,
- const char *function)) {
- internal::assert_fail(assertion, file, line, function);
-}
-
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/OSUtil/linux/CMakeLists.txt b/libc/src/__support/OSUtil/linux/CMakeLists.txt
index 93d24f80ecda8a..c176816e5119ce 100644
--- a/libc/src/__support/OSUtil/linux/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/CMakeLists.txt
@@ -21,6 +21,18 @@ add_object_library(
libc.src.__support.OSUtil.linux.syscall_wrappers.exit_group
)
+add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .linux_util
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+ libc.src.stdlib.abort_utils
+)
+
add_header_library(
auxv
HDRS
diff --git a/libc/src/__support/OSUtil/linux/assert_fail.cpp b/libc/src/__support/OSUtil/linux/assert_fail.cpp
new file mode 100644
index 00000000000000..2dbc555ad77042
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/assert_fail.cpp
@@ -0,0 +1,24 @@
+//===-- Linux implementation of internal::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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/OSUtil/assert_fail.h"
+#include "src/__support/OSUtil/assert_fail_utils.h"
+#include "src/__support/macros/config.h"
+#include "src/stdlib/abort_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+[[noreturn]] void assert_fail(const char *assertion, const char *file,
+ unsigned line, const char *function) {
+ report_assertion_failure(assertion, file, line, function);
+ LIBC_NAMESPACE::abort_utils::abort();
+}
+
+} // namespace internal
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/OSUtil/uefi/CMakeLists.txt b/libc/src/__support/OSUtil/uefi/CMakeLists.txt
index b8b785a6a0c283..18dded974e6c04 100644
--- a/libc/src/__support/OSUtil/uefi/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/uefi/CMakeLists.txt
@@ -11,3 +11,14 @@ add_object_library(
libc.src.__support.common
libc.src.__support.CPP.string_view
)
+
+add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .uefi_util
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/OSUtil/uefi/assert_fail.cpp b/libc/src/__support/OSUtil/uefi/assert_fail.cpp
new file mode 100644
index 00000000000000..0a5877678639b8
--- /dev/null
+++ b/libc/src/__support/OSUtil/uefi/assert_fail.cpp
@@ -0,0 +1,24 @@
+//===-- UEFI implementation of internal::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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/OSUtil/assert_fail.h"
+#include "src/__support/OSUtil/assert_fail_utils.h"
+#include "src/__support/OSUtil/exit.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+[[noreturn]] void assert_fail(const char *assertion, const char *file,
+ unsigned line, const char *function) {
+ report_assertion_failure(assertion, file, line, function);
+ internal::exit(0xFF);
+}
+
+} // namespace internal
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/OSUtil/windows/CMakeLists.txt b/libc/src/__support/OSUtil/windows/CMakeLists.txt
index be316d77f5d06a..e7e52337d2e0ef 100644
--- a/libc/src/__support/OSUtil/windows/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/windows/CMakeLists.txt
@@ -8,3 +8,14 @@ add_object_library(
DEPENDS
libc.src.__support.macros.config
)
+
+add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .windows_util
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/OSUtil/windows/assert_fail.cpp b/libc/src/__support/OSUtil/windows/assert_fail.cpp
new file mode 100644
index 00000000000000..b8c6aea1b3963d
--- /dev/null
+++ b/libc/src/__support/OSUtil/windows/assert_fail.cpp
@@ -0,0 +1,24 @@
+//===-- Windows implementation of internal::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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/OSUtil/assert_fail.h"
+#include "src/__support/OSUtil/assert_fail_utils.h"
+#include "src/__support/OSUtil/exit.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+[[noreturn]] void assert_fail(const char *assertion, const char *file,
+ unsigned line, const char *function) {
+ report_assertion_failure(assertion, file, line, function);
+ internal::exit(0xFF);
+}
+
+} // namespace internal
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/libc_assert.h b/libc/src/__support/libc_assert.h
index ed06b74d1ee9d1..0f1f7e6792d9e8 100644
--- a/libc/src/__support/libc_assert.h
+++ b/libc/src/__support/libc_assert.h
@@ -17,8 +17,7 @@
#include "src/__support/macros/properties/os.h"
#ifdef LIBC_FULL_BUILD
-#include "src/__support/OSUtil/io.h"
-#include "src/__support/integer_to_string.h"
+#include "src/__support/OSUtil/assert_fail.h"
#endif
//===----------------------------------------------------------------------===//
@@ -43,15 +42,6 @@
} while (false)
#endif // LIBC_TARGET_OS_IS_LINUX
#else
-namespace LIBC_NAMESPACE_DECL {
-namespace internal {
-// Forward declaration of internal::assert_fail to decouple assertion failure
-// handling and abort from internal header dependencies.
-[[noreturn]] void assert_fail(const char *assertion, const char *file,
- unsigned line, const char *function);
-} // namespace internal
-} // namespace LIBC_NAMESPACE_DECL
-
#define LIBC_REQUIRE(COND, MSG) \
do { \
if (LIBC_UNLIKELY(!(COND))) \
@@ -73,26 +63,6 @@ namespace internal {
#endif // LIBC_ASSERT
#else // Not LIBC_COPT_USE_C_ASSERT
-namespace LIBC_NAMESPACE_DECL {
-
-// This is intended to be removed in a future patch to use a similar design to
-// below, but it's necessary for the external assert.
-LIBC_INLINE void report_assertion_failure(const char *assertion,
- const char *filename, unsigned line,
- const char *funcname) {
- const IntegerToString<unsigned> line_buffer(line);
- write_to_stderr(filename);
- write_to_stderr(":");
- write_to_stderr(line_buffer.view());
- write_to_stderr(": Assertion failed: '");
- write_to_stderr(assertion);
- write_to_stderr("' in function: '");
- write_to_stderr(funcname);
- write_to_stderr("'\n");
-}
-
-} // namespace LIBC_NAMESPACE_DECL
-
#ifdef LIBC_ASSERT
#error "Unexpected: LIBC_ASSERT macro already defined"
#endif
diff --git a/libc/src/assert/__assert_fail.h b/libc/src/assert/__assert_fail.h
index d7c21810b8e2ca..bbc0aa8e2bf236 100644
--- a/libc/src/assert/__assert_fail.h
+++ b/libc/src/assert/__assert_fail.h
@@ -13,12 +13,6 @@
#include <stddef.h>
namespace LIBC_NAMESPACE_DECL {
-namespace internal {
-
-[[noreturn]] void assert_fail(const char *assertion, const char *file,
- unsigned line, const char *function);
-
-} // namespace internal
[[noreturn]] void __assert_fail(const char *assertion, const char *file,
unsigned line, const char *function);
diff --git a/libc/src/assert/generic/CMakeLists.txt b/libc/src/assert/generic/CMakeLists.txt
index 95e47610576bc7..b235b3ed15a4c6 100644
--- a/libc/src/assert/generic/CMakeLists.txt
+++ b/libc/src/assert/generic/CMakeLists.txt
@@ -7,6 +7,7 @@ add_entrypoint_object(
../assert.h
DEPENDS
libc.include.assert
- libc.src.__support.OSUtil.osutil
- libc.src.stdlib.abort_utils
+ libc.src.__support.OSUtil.assert_fail
+ libc.src.__support.common
+ libc.src.__support.macros.config
)
diff --git a/libc/src/assert/generic/__assert_fail.cpp b/libc/src/assert/generic/__assert_fail.cpp
index 3a94f8342d1e0e..9dfe1adb222d17 100644
--- a/libc/src/assert/generic/__assert_fail.cpp
+++ b/libc/src/assert/generic/__assert_fail.cpp
@@ -7,21 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/assert/__assert_fail.h"
-#include "src/__support/OSUtil/io.h"
-#include "src/__support/libc_assert.h"
+#include "src/__support/OSUtil/assert_fail.h"
#include "src/__support/macros/config.h"
-#include "src/stdlib/abort_utils.h"
namespace LIBC_NAMESPACE_DECL {
-namespace internal {
-
-[[noreturn]] void assert_fail(const char *assertion, const char *file,
- unsigned line, const char *function) {
- LIBC_NAMESPACE::report_assertion_failure(assertion, file, line, function);
- LIBC_NAMESPACE::abort_utils::abort();
-}
-
-} // namespace internal
LLVM_LIBC_FUNCTION(void, __assert_fail,
(const char *assertion, const char *file, unsigned line,
diff --git a/libc/src/assert/gpu/CMakeLists.txt b/libc/src/assert/gpu/CMakeLists.txt
deleted file mode 100644
index 7b683ae44fb423..00000000000000
--- a/libc/src/assert/gpu/CMakeLists.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-add_entrypoint_object(
- __assert_fail
- SRCS
- __assert_fail.cpp
- HDRS
- ../__assert_fail.h
- ../assert.h
- DEPENDS
- libc.include.assert
- libc.src.__support.OSUtil.osutil
- libc.src.__support.GPU.utils
- libc.src.__support.CPP.atomic
- libc.src.stdlib.abort_utils
-)
diff --git a/libc/test/src/__support/CPP/CMakeLists.txt b/libc/test/src/__support/CPP/CMakeLists.txt
index 5116f559e71c0a..5b0f0678c16ac9 100644
--- a/libc/test/src/__support/CPP/CMakeLists.txt
+++ b/libc/test/src/__support/CPP/CMakeLists.txt
@@ -174,7 +174,6 @@ add_libc_test(
SRCS
unique_ptr_test.cpp
DEPENDS
- libc.hdr.signal_macros
libc.src.__support.CPP.nullptr_t
libc.src.__support.CPP.unique_ptr
libc.src.__support.CPP.utility
diff --git a/libc/test/src/__support/CPP/unique_ptr_test.cpp b/libc/test/src/__support/CPP/unique_ptr_test.cpp
index 5279baf0deb24d..476cd494663beb 100644
--- a/libc/test/src/__support/CPP/unique_ptr_test.cpp
+++ b/libc/test/src/__support/CPP/unique_ptr_test.cpp
@@ -11,7 +11,6 @@
///
//===----------------------------------------------------------------------===//
-#include "hdr/signal_macros.h"
#include "src/__support/CPP/cstddef/nullptr_t.h"
#include "src/__support/CPP/unique_ptr.h"
#include "src/__support/CPP/utility.h"
@@ -259,19 +258,17 @@ TEST(LlvmLibcUniquePtrTest, BaseDerivedConversion) {
ASSERT_EQ(base_ptr->val, 100);
}
-#if !defined(NDEBUG) && defined(SIGABRT)
-#define EXPECT_ASSERT_FAILURE(FUNC) EXPECT_DEATH(FUNC, WITH_SIGNAL(SIGABRT))
-
+#ifndef NDEBUG
// Test that dereferencing a null unique_ptr asserts.
TEST(LlvmLibcUniquePtrTest, NullDereferenceDeath) {
struct Foo {
int val;
};
unique_ptr<Foo> ptr;
- EXPECT_ASSERT_FAILURE([&] { (void)*ptr; });
- EXPECT_ASSERT_FAILURE([&] { (void)ptr->val; });
+ EXPECT_DEATH([&] { (void)*ptr; }, WITH_SIGNAL(-1));
+ EXPECT_DEATH([&] { (void)ptr->val; }, WITH_SIGNAL(-1));
unique_ptr<int[]> arr;
- EXPECT_ASSERT_FAILURE([&] { (void)arr[0]; });
+ EXPECT_DEATH([&] { (void)arr[0]; }, WITH_SIGNAL(-1));
}
-#endif // !defined(NDEBUG) && defined(SIGABRT)
+#endif // !NDEBUG
diff --git a/libc/test/src/__support/checked_ptr_test.cpp b/libc/test/src/__support/checked_ptr_test.cpp
index 4b95a762de5d70..3e2aae53579914 100644
--- a/libc/test/src/__support/checked_ptr_test.cpp
+++ b/libc/test/src/__support/checked_ptr_test.cpp
@@ -227,67 +227,79 @@ TEST(LlvmLibcCheckedPtrTest, TakeUnique) {
#if !defined(NDEBUG) && LIBC_TEST_SUBPROCESS_TESTS
-#define EXPECT_ASSERT_FAILS(stmt) EXPECT_DEATH(stmt, WITH_SIGNAL(-1))
-
TEST(LlvmLibcCheckedPtrDeathTest, UncheckedDestructionDies) {
- EXPECT_ASSERT_FAILS([] {
- auto ptr = make_unique<int>(42);
- (void)ptr;
- });
+ EXPECT_DEATH(
+ [] {
+ auto ptr = make_unique<int>(42);
+ (void)ptr;
+ },
+ WITH_SIGNAL(-1));
}
TEST(LlvmLibcCheckedPtrDeathTest, MoveFromCheckedRequiresRecheckOrDies) {
- EXPECT_ASSERT_FAILS([] {
- auto ptr1 = make_unique<int>(42);
- (void)static_cast<bool>(ptr1);
- CheckedPtr<int> ptr2(move(ptr1));
- (void)*ptr2;
- });
+ EXPECT_DEATH(
+ [] {
+ auto ptr1 = make_unique<int>(42);
+ (void)static_cast<bool>(ptr1);
+ CheckedPtr<int> ptr2(move(ptr1));
+ (void)*ptr2;
+ },
+ WITH_SIGNAL(-1));
}
// In the tests below, the pointer is checked after the operation under test, so
// that its destruction cannot be the thing that triggers the assertion.
TEST(LlvmLibcCheckedPtrDeathTest, UncheckedDereferenceDies) {
- EXPECT_ASSERT_FAILS([] {
- auto ptr = make_unique<int>(42);
- (void)*ptr;
- (void)static_cast<bool>(ptr);
- });
+ EXPECT_DEATH(
+ [] {
+ auto ptr = make_unique<int>(42);
+ (void)*ptr;
+ (void)static_cast<bool>(ptr);
+ },
+ WITH_SIGNAL(-1));
}
TEST(LlvmLibcCheckedPtrDeathTest, UncheckedArrowDies) {
- EXPECT_ASSERT_FAILS([] {
- auto ptr = make_unique<Foo>(42);
- (void)ptr->val;
- (void)static_cast<bool>(ptr);
- });
+ EXPECT_DEATH(
+ [] {
+ auto ptr = make_unique<Foo>(42);
+ (void)ptr->val;
+ (void)static_cast<bool>(ptr);
+ },
+ WITH_SIGNAL(-1));
}
TEST(LlvmLibcCheckedPtrDeathTest, UncheckedArraySubscriptDies) {
- EXPECT_ASSERT_FAILS([] {
- auto ptr = make_unique<int[]>(3);
- (void)ptr[0];
- (void)static_cast<bool>(ptr);
- });
+ EXPECT_DEATH(
+ [] {
+ auto ptr = make_unique<int[]>(3);
+ (void)ptr[0];
+ (void)static_cast<bool>(ptr);
+ },
+ WITH_SIGNAL(-1));
}
TEST(LlvmLibcCheckedPtrDeathTest, OverwritingUncheckedViaMoveAssignmentDies) {
- EXPECT_ASSERT_FAILS([] {
- auto ptr1 = make_unique<int>(1);
- auto ptr2 = make_unique<int>(2);
- (void)static_cast<bool>(ptr2);
- ptr1 = move(ptr2);
- (void)static_cast<bool>(ptr1);
- });
+ EXPECT_DEATH(
+ [] {
+ auto ptr1 = make_unique<int>(1);
+ auto ptr2 = make_unique<int>(2);
+ (void)static_cast<bool>(ptr2);
+ ptr1 = move(ptr2);
+ (void)static_cast<bool>(ptr1);
+ },
+ WITH_SIGNAL(-1));
}
TEST(LlvmLibcCheckedPtrDeathTest, UncheckedTakeUniqueDies) {
- EXPECT_ASSERT_FAILS([] {
- auto ptr = make_unique<int>(42);
- (void)ptr.take_unique();
- (void)static_cast<bool>(ptr);
- });
+ EXPECT_DEATH(
+ [] {
+ auto ptr = make_unique<int>(42);
+ (void)ptr.take_unique();
+ (void)static_cast<bool>(ptr);
+ },
+ WITH_SIGNAL(-1));
}
#endif // !defined(NDEBUG) && LIBC_TEST_SUBPROCESS_TESTS
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 4adb39c25de252..71053a45011e99 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2352,11 +2352,28 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_libc_assert_hdrs",
+ hdrs = ["src/__support/libc_assert.h"],
+ deps = [
+ ":__support_macros_attributes",
+ ":__support_macros_config",
+ ":__support_macros_hardening",
+ ":__support_macros_macro_utils",
+ ":__support_macros_optimization",
+ ":__support_macros_properties_os",
+ ] + select({
+ ":full_build": [
+ ":__support_osutil_assert_fail_hdrs",
+ ],
+ "//conditions:default": [],
+ }),
+)
+
libc_support_library(
name = "__support_libc_assert",
hdrs = ["src/__support/libc_assert.h"],
deps = [
- ":__support_common",
":__support_macros_attributes",
":__support_macros_config",
":__support_macros_hardening",
@@ -2365,8 +2382,7 @@ libc_support_library(
":__support_macros_properties_os",
] + select({
":full_build": [
- ":__support_integer_to_string",
- ":__support_osutil_io",
+ ":__support_osutil_assert_fail",
],
"//conditions:default": [],
}),
@@ -4916,6 +4932,42 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_osutil_assert_fail_hdrs",
+ hdrs = ["src/__support/OSUtil/assert_fail.h"],
+ deps = [
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_osutil_assert_fail_utils",
+ hdrs = ["src/__support/OSUtil/assert_fail_utils.h"],
+ deps = [
+ ":__support_integer_to_string",
+ ":__support_macros_attributes",
+ ":__support_macros_config",
+ ":__support_osutil_io",
+ ],
+)
+
+libc_support_library(
+ name = "__support_osutil_assert_fail",
+ srcs = ["src/__support/OSUtil/linux/assert_fail.cpp"],
+ hdrs = ["src/__support/OSUtil/assert_fail.h"],
+ full_build_only = True,
+ target_compatible_with = select({
+ "@platforms//os:linux": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ deps = [
+ ":__support_macros_config",
+ ":__support_osutil_assert_fail_hdrs",
+ ":__support_osutil_assert_fail_utils",
+ ":stdlib_abort_utils",
+ ],
+)
+
libc_support_library(
name = "__support_osutil_linux_stat_kernel_statx_types",
hdrs = ["src/__support/OSUtil/linux/stat/kernel_statx_types.h"],
@@ -5142,7 +5194,7 @@ libc_support_library(
deps = [
":__support_cpp_atomic",
":__support_cpp_optional",
- ":__support_libc_assert",
+ ":__support_libc_assert_hdrs",
":__support_macros_config",
":__support_macros_optimization",
":__support_threads_identifier",
@@ -5163,7 +5215,7 @@ libc_support_library(
deps = [
":__support_common",
":__support_cpp_optional",
- ":__support_libc_assert",
+ ":__support_libc_assert_hdrs",
":__support_macros_attributes",
":__support_macros_config",
":__support_macros_optimization",
@@ -5187,7 +5239,7 @@ libc_support_library(
":__support_cpp_atomic",
":__support_cpp_limits",
":__support_cpp_optional",
- ":__support_libc_assert",
+ ":__support_libc_assert_hdrs",
":__support_macros_attributes",
":__support_macros_config",
":__support_macros_optimization",
@@ -5409,7 +5461,7 @@ libc_support_library(
":__support_common",
":__support_cpp_expected",
":__support_error_or",
- ":__support_libc_assert",
+ ":__support_libc_assert_hdrs",
":__support_macros_config",
":hdr_time_macros",
":types_clockid_t",
@@ -17177,19 +17229,6 @@ libc_support_library(
],
)
-libc_support_library(
- name = "__assert_fail",
- srcs = ["src/assert/generic/__assert_fail.cpp"],
- hdrs = ["src/assert/__assert_fail.h"],
- full_build_only = True,
- deps = [
- ":__support_libc_assert",
- ":__support_macros_config",
- ":__support_osutil_io",
- ":stdlib_abort_utils",
- ],
-)
-
libc_support_library(
name = "qsort_util",
hdrs = [
diff --git a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
index 35ed4d663f657f..bc1be3481c3587 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
@@ -124,7 +124,6 @@ libc_test_library(
"//conditions:default": ["@platforms//:incompatible"],
}),
deps = [
- "//libc:__assert_fail",
"//libc:__support_common",
"//libc:__support_libc_errno",
"//libc:__support_macros_config",
diff --git a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
index 116ecd2a5789c4..54f9cdaac025dc 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
+++ b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl
@@ -66,7 +66,6 @@ def libc_test(
# The compiler may emit references to symbols it expects to exist,
# like `memset`. These dependencies hermetically provide them.
"//libc/test/UnitTest:HermeticTestUtils",
- "//libc:__assert_fail",
"//libc:__stack_chk_fail", # Needed if -fstack-protector is set.
],
"//conditions:default": [],
>From 9f4c53445db6f6c6d2a688957c70809305f507d2 Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Thu, 12 Nov 2026 00:43:59 +0530
Subject: [PATCH 8/9] [libc] Fix fullbuild, overlay, Bazel, and test-discovery
CI failures
---
libc/src/__support/CMakeLists.txt | 2 +-
.../__support/OSUtil/baremetal/CMakeLists.txt | 24 ++++++++--------
.../__support/OSUtil/darwin/CMakeLists.txt | 22 ++++++++-------
.../__support/OSUtil/freebsd/CMakeLists.txt | 22 ++++++++-------
libc/src/__support/OSUtil/gpu/CMakeLists.txt | 28 ++++++++++---------
.../src/__support/OSUtil/linux/CMakeLists.txt | 24 ++++++++--------
libc/src/__support/OSUtil/uefi/CMakeLists.txt | 22 ++++++++-------
.../__support/OSUtil/windows/CMakeLists.txt | 22 ++++++++-------
libc/src/assert/generic/__assert_fail.cpp | 1 +
.../llvm-project-overlay/libc/BUILD.bazel | 2 ++
10 files changed, 93 insertions(+), 76 deletions(-)
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 6363d0b091a079..e0389738c21149 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -499,7 +499,7 @@ set(libc_assert_hdrs_deps
libc.src.__support.macros.attributes
libc.src.__support.macros.config
libc.src.__support.macros.hardening
- libc.src.__support.macros.macro-utils
+ libc.src.__support.macros.macro_utils
libc.src.__support.macros.optimization
libc.src.__support.macros.properties.os
)
diff --git a/libc/src/__support/OSUtil/baremetal/CMakeLists.txt b/libc/src/__support/OSUtil/baremetal/CMakeLists.txt
index df12cff7cce9b2..3ab3a01121596a 100644
--- a/libc/src/__support/OSUtil/baremetal/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/baremetal/CMakeLists.txt
@@ -10,14 +10,16 @@ add_object_library(
libc.src.__support.CPP.string_view
)
-add_object_library(
- assert_fail
- SRCS
- assert_fail.cpp
- DEPENDS
- .baremetal_util
- libc.src.__support.OSUtil.assert_fail_hdrs
- libc.src.__support.OSUtil.assert_fail_utils
- libc.src.__support.macros.config
- libc.src.stdlib.abort_utils
-)
+if(LLVM_LIBC_FULL_BUILD)
+ add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .baremetal_util
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+ libc.src.stdlib.abort_utils
+ )
+endif()
diff --git a/libc/src/__support/OSUtil/darwin/CMakeLists.txt b/libc/src/__support/OSUtil/darwin/CMakeLists.txt
index b8f45569d62b07..0e9d4f849359c0 100644
--- a/libc/src/__support/OSUtil/darwin/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/darwin/CMakeLists.txt
@@ -19,13 +19,15 @@ add_object_library(
libc.include.sys_syscall
)
-add_object_library(
- assert_fail
- SRCS
- assert_fail.cpp
- DEPENDS
- .darwin_util
- libc.src.__support.OSUtil.assert_fail_hdrs
- libc.src.__support.OSUtil.assert_fail_utils
- libc.src.__support.macros.config
-)
+if(LLVM_LIBC_FULL_BUILD)
+ add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .darwin_util
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+ )
+endif()
diff --git a/libc/src/__support/OSUtil/freebsd/CMakeLists.txt b/libc/src/__support/OSUtil/freebsd/CMakeLists.txt
index 0315c721655fea..f32d495c4d4538 100644
--- a/libc/src/__support/OSUtil/freebsd/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/freebsd/CMakeLists.txt
@@ -17,13 +17,15 @@ add_object_library(
libc.src.__support.macros.config
)
-add_object_library(
- assert_fail
- SRCS
- assert_fail.cpp
- DEPENDS
- .freebsd_util
- libc.src.__support.OSUtil.assert_fail_hdrs
- libc.src.__support.OSUtil.assert_fail_utils
- libc.src.__support.macros.config
-)
+if(LLVM_LIBC_FULL_BUILD)
+ add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .freebsd_util
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+ )
+endif()
diff --git a/libc/src/__support/OSUtil/gpu/CMakeLists.txt b/libc/src/__support/OSUtil/gpu/CMakeLists.txt
index d64c57b15f3599..b87b909eff8cab 100644
--- a/libc/src/__support/OSUtil/gpu/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/gpu/CMakeLists.txt
@@ -12,16 +12,18 @@ add_object_library(
libc.src.string.memory_utils.inline_memcpy
)
-add_object_library(
- assert_fail
- SRCS
- assert_fail.cpp
- DEPENDS
- .gpu_util
- libc.src.__support.CPP.atomic
- libc.src.__support.GPU.utils
- libc.src.__support.OSUtil.assert_fail_hdrs
- libc.src.__support.OSUtil.assert_fail_utils
- libc.src.__support.macros.config
- libc.src.stdlib.abort_utils
-)
+if(LLVM_LIBC_FULL_BUILD)
+ add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .gpu_util
+ libc.src.__support.CPP.atomic
+ libc.src.__support.GPU.utils
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+ libc.src.stdlib.abort_utils
+ )
+endif()
diff --git a/libc/src/__support/OSUtil/linux/CMakeLists.txt b/libc/src/__support/OSUtil/linux/CMakeLists.txt
index c176816e5119ce..928c3c694b7dd6 100644
--- a/libc/src/__support/OSUtil/linux/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/CMakeLists.txt
@@ -21,17 +21,19 @@ add_object_library(
libc.src.__support.OSUtil.linux.syscall_wrappers.exit_group
)
-add_object_library(
- assert_fail
- SRCS
- assert_fail.cpp
- DEPENDS
- .linux_util
- libc.src.__support.OSUtil.assert_fail_hdrs
- libc.src.__support.OSUtil.assert_fail_utils
- libc.src.__support.macros.config
- libc.src.stdlib.abort_utils
-)
+if(LLVM_LIBC_FULL_BUILD)
+ add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .linux_util
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+ libc.src.stdlib.abort_utils
+ )
+endif()
add_header_library(
auxv
diff --git a/libc/src/__support/OSUtil/uefi/CMakeLists.txt b/libc/src/__support/OSUtil/uefi/CMakeLists.txt
index 18dded974e6c04..627c7d25041466 100644
--- a/libc/src/__support/OSUtil/uefi/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/uefi/CMakeLists.txt
@@ -12,13 +12,15 @@ add_object_library(
libc.src.__support.CPP.string_view
)
-add_object_library(
- assert_fail
- SRCS
- assert_fail.cpp
- DEPENDS
- .uefi_util
- libc.src.__support.OSUtil.assert_fail_hdrs
- libc.src.__support.OSUtil.assert_fail_utils
- libc.src.__support.macros.config
-)
+if(LLVM_LIBC_FULL_BUILD)
+ add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .uefi_util
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+ )
+endif()
diff --git a/libc/src/__support/OSUtil/windows/CMakeLists.txt b/libc/src/__support/OSUtil/windows/CMakeLists.txt
index e7e52337d2e0ef..83d6f534181d55 100644
--- a/libc/src/__support/OSUtil/windows/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/windows/CMakeLists.txt
@@ -9,13 +9,15 @@ add_object_library(
libc.src.__support.macros.config
)
-add_object_library(
- assert_fail
- SRCS
- assert_fail.cpp
- DEPENDS
- .windows_util
- libc.src.__support.OSUtil.assert_fail_hdrs
- libc.src.__support.OSUtil.assert_fail_utils
- libc.src.__support.macros.config
-)
+if(LLVM_LIBC_FULL_BUILD)
+ add_object_library(
+ assert_fail
+ SRCS
+ assert_fail.cpp
+ DEPENDS
+ .windows_util
+ libc.src.__support.OSUtil.assert_fail_hdrs
+ libc.src.__support.OSUtil.assert_fail_utils
+ libc.src.__support.macros.config
+ )
+endif()
diff --git a/libc/src/assert/generic/__assert_fail.cpp b/libc/src/assert/generic/__assert_fail.cpp
index 9dfe1adb222d17..a3278db2771b92 100644
--- a/libc/src/assert/generic/__assert_fail.cpp
+++ b/libc/src/assert/generic/__assert_fail.cpp
@@ -8,6 +8,7 @@
#include "src/assert/__assert_fail.h"
#include "src/__support/OSUtil/assert_fail.h"
+#include "src/__support/common.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 71053a45011e99..b4dc4f5cc561b5 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -5223,6 +5223,7 @@ libc_support_library(
":__support_threads_linux_futex_utils",
":__support_threads_sleep",
":__support_time",
+ ":__support_time_clock_conversion",
":hdr_errno_macros",
],
)
@@ -5246,6 +5247,7 @@ libc_support_library(
":__support_threads_raw_mutex",
":__support_threads_sleep",
":__support_time",
+ ":__support_time_clock_conversion",
":hdr_errno_macros",
],
)
>From ce2c6036c003c2b9d32b5b4017c8841fc809e69e Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Thu, 12 Nov 2026 01:39:52 +0530
Subject: [PATCH 9/9] [libc] Inline EXPECT_ASSERT_FAILS in checked_ptr_test and
use assert_hdrs in fp_bits
---
libc/test/src/__support/checked_ptr_test.cpp | 24 +++++++++++--------
.../llvm-project-overlay/libc/BUILD.bazel | 2 +-
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/libc/test/src/__support/checked_ptr_test.cpp b/libc/test/src/__support/checked_ptr_test.cpp
index b6ecf59b6d260c..77de009f2cab2d 100644
--- a/libc/test/src/__support/checked_ptr_test.cpp
+++ b/libc/test/src/__support/checked_ptr_test.cpp
@@ -387,19 +387,23 @@ TEST(LlvmLibcCheckedPtrDeathTest, UncheckedTakeUniqueDies) {
}
TEST(LlvmLibcCheckedPtrDeathTest, UncheckedGetDies) {
- EXPECT_ASSERT_FAILS([] {
- auto ptr = make_unique<int>(42);
- (void)ptr.get();
- (void)static_cast<bool>(ptr);
- });
+ EXPECT_DEATH(
+ [] {
+ auto ptr = make_unique<int>(42);
+ (void)ptr.get();
+ (void)static_cast<bool>(ptr);
+ },
+ WITH_SIGNAL(-1));
}
TEST(LlvmLibcCheckedPtrDeathTest, UncheckedReleaseDies) {
- EXPECT_ASSERT_FAILS([] {
- auto ptr = make_unique<int>(42);
- unique_ptr<int> owner(ptr.release());
- (void)static_cast<bool>(ptr);
- });
+ EXPECT_DEATH(
+ [] {
+ auto ptr = make_unique<int>(42);
+ unique_ptr<int> owner(ptr.release());
+ (void)static_cast<bool>(ptr);
+ },
+ WITH_SIGNAL(-1));
}
#endif // !defined(NDEBUG) && LIBC_TEST_SUBPROCESS_TESTS
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index bcbd00dbabf30c..4d3514adf713e2 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3999,7 +3999,7 @@ libc_support_library(
":__support_common",
":__support_cpp_bit",
":__support_cpp_type_traits",
- ":__support_libc_assert",
+ ":__support_libc_assert_hdrs",
":__support_macros_attributes",
":__support_macros_config",
":__support_macros_properties_types",
More information about the libc-commits
mailing list