[libc++][NFC] Make the exception implementation files self-contained#164377
Merged
philnik777 merged 1 commit intollvm:mainfrom Nov 11, 2025
Merged
[libc++][NFC] Make the exception implementation files self-contained#164377philnik777 merged 1 commit intollvm:mainfrom
philnik777 merged 1 commit intollvm:mainfrom
Conversation
e30d5f9 to
70fb488
Compare
Member
|
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) ChangesFull diff: https://github.com/llvm/llvm-project/pull/164377.diff 10 Files Affected:
diff --git a/libcxx/src/exception.cpp b/libcxx/src/exception.cpp
index ac6324cd9fe35..9932141006591 100644
--- a/libcxx/src/exception.cpp
+++ b/libcxx/src/exception.cpp
@@ -9,20 +9,12 @@
#define _LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION
#define _LIBCPP_DISABLE_DEPRECATION_WARNINGS
-#include <exception>
-#include <new>
-#include <typeinfo>
-
-#if defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI)
-# include <cxxabi.h>
-using namespace __cxxabiv1;
-# define HAVE_DEPENDENT_EH_ABI 1
-#endif
+#include <__config>
#if defined(_LIBCPP_ABI_MICROSOFT)
# include "support/runtime/exception_msvc.ipp"
# include "support/runtime/exception_pointer_msvc.ipp"
-#elif defined(_LIBCPPABI_VERSION)
+#elif defined(LIBCXX_BUILDING_LIBCXXABI)
# include "support/runtime/exception_libcxxabi.ipp"
# include "support/runtime/exception_pointer_cxxabi.ipp"
#elif defined(LIBCXXRT)
diff --git a/libcxx/src/support/runtime/exception_fallback.ipp b/libcxx/src/support/runtime/exception_fallback.ipp
index ba283aee22901..dca904e902da1 100644
--- a/libcxx/src/support/runtime/exception_fallback.ipp
+++ b/libcxx/src/support/runtime/exception_fallback.ipp
@@ -8,6 +8,8 @@
//===----------------------------------------------------------------------===//
#include <__verbose_abort>
+#include <exception>
+#include "include/atomic_support.h"
namespace std {
diff --git a/libcxx/src/support/runtime/exception_glibcxx.ipp b/libcxx/src/support/runtime/exception_glibcxx.ipp
index aa67cab6bc239..5eb8d87f6d4e1 100644
--- a/libcxx/src/support/runtime/exception_glibcxx.ipp
+++ b/libcxx/src/support/runtime/exception_glibcxx.ipp
@@ -11,6 +11,9 @@
# error header can only be used when targeting libstdc++ or libsupc++
#endif
+#include <exception>
+#include <new>
+
namespace std {
bad_alloc::bad_alloc() noexcept {}
diff --git a/libcxx/src/support/runtime/exception_libcxxabi.ipp b/libcxx/src/support/runtime/exception_libcxxabi.ipp
index df6bd6574bde2..c42bb237d9db8 100644
--- a/libcxx/src/support/runtime/exception_libcxxabi.ipp
+++ b/libcxx/src/support/runtime/exception_libcxxabi.ipp
@@ -7,6 +7,10 @@
//
//===----------------------------------------------------------------------===//
+#include <exception>
+
+#include <cxxabi.h>
+
#ifndef _LIBCPPABI_VERSION
# error this header can only be used with libc++abi
#endif
@@ -17,9 +21,9 @@ bool uncaught_exception() noexcept { return uncaught_exceptions() > 0; }
int uncaught_exceptions() noexcept {
#if _LIBCPPABI_VERSION > 1001
- return __cxa_uncaught_exceptions();
+ return abi::__cxa_uncaught_exceptions();
#else
- return __cxa_uncaught_exception() ? 1 : 0;
+ return abi::__cxa_uncaught_exception() ? 1 : 0;
#endif
}
diff --git a/libcxx/src/support/runtime/exception_libcxxrt.ipp b/libcxx/src/support/runtime/exception_libcxxrt.ipp
index f17fecc71e34b..6afdc006563c9 100644
--- a/libcxx/src/support/runtime/exception_libcxxrt.ipp
+++ b/libcxx/src/support/runtime/exception_libcxxrt.ipp
@@ -11,6 +11,8 @@
# error this header may only be used when targeting libcxxrt
#endif
+#include <exception>
+
namespace std {
bad_exception::~bad_exception() noexcept {}
diff --git a/libcxx/src/support/runtime/exception_msvc.ipp b/libcxx/src/support/runtime/exception_msvc.ipp
index 2ae004bb02e5d..7114d90892cc1 100644
--- a/libcxx/src/support/runtime/exception_msvc.ipp
+++ b/libcxx/src/support/runtime/exception_msvc.ipp
@@ -12,6 +12,8 @@
#endif
#include <__verbose_abort>
+#include <exception>
+#include <new>
extern "C" {
typedef void(__cdecl* terminate_handler)();
diff --git a/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp b/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp
index 8f5c2060bb06c..75cb7c9d82ccd 100644
--- a/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp
+++ b/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp
@@ -7,22 +7,21 @@
//
//===----------------------------------------------------------------------===//
-#ifndef HAVE_DEPENDENT_EH_ABI
-# error this header may only be used with libc++abi or libcxxrt
-#endif
+#include <cxxabi.h>
+#include <exception>
namespace std {
-exception_ptr::~exception_ptr() noexcept { __cxa_decrement_exception_refcount(__ptr_); }
+exception_ptr::~exception_ptr() noexcept { abi::__cxa_decrement_exception_refcount(__ptr_); }
exception_ptr::exception_ptr(const exception_ptr& other) noexcept : __ptr_(other.__ptr_) {
- __cxa_increment_exception_refcount(__ptr_);
+ abi::__cxa_increment_exception_refcount(__ptr_);
}
exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept {
if (__ptr_ != other.__ptr_) {
- __cxa_increment_exception_refcount(other.__ptr_);
- __cxa_decrement_exception_refcount(__ptr_);
+ abi::__cxa_increment_exception_refcount(other.__ptr_);
+ abi::__cxa_decrement_exception_refcount(__ptr_);
__ptr_ = other.__ptr_;
}
return *this;
@@ -31,7 +30,7 @@ exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept {
exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept {
exception_ptr ptr;
ptr.__ptr_ = __e;
- __cxa_increment_exception_refcount(ptr.__ptr_);
+ abi::__cxa_increment_exception_refcount(ptr.__ptr_);
return ptr;
}
@@ -51,12 +50,12 @@ exception_ptr current_exception() noexcept {
// this whole function would be just:
// return exception_ptr(__cxa_current_primary_exception());
exception_ptr ptr;
- ptr.__ptr_ = __cxa_current_primary_exception();
+ ptr.__ptr_ = abi::__cxa_current_primary_exception();
return ptr;
}
void rethrow_exception(exception_ptr p) {
- __cxa_rethrow_primary_exception(p.__ptr_);
+ abi::__cxa_rethrow_primary_exception(p.__ptr_);
// if p.__ptr_ is NULL, above returns so we terminate
terminate();
}
diff --git a/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp b/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp
index 174b44ce0e6f7..4b08db6f1ae6f 100644
--- a/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp
+++ b/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp
@@ -16,6 +16,8 @@
// stable ABI), and its rethrow_exception(std::__exception_ptr::exception_ptr)
// function.
+#include <exception>
+
namespace std {
namespace __exception_ptr {
diff --git a/libcxx/src/support/runtime/exception_pointer_msvc.ipp b/libcxx/src/support/runtime/exception_pointer_msvc.ipp
index 2be5136176e32..4141e0312349b 100644
--- a/libcxx/src/support/runtime/exception_pointer_msvc.ipp
+++ b/libcxx/src/support/runtime/exception_pointer_msvc.ipp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include <exception>
#include <stdio.h>
#include <stdlib.h>
diff --git a/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp b/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp
index 05a71ce34e5ac..5e55f0f6dede3 100644
--- a/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp
+++ b/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include <__verbose_abort>
+#include <exception>
namespace std {
|
ldionne
reviewed
Oct 24, 2025
ldionne
approved these changes
Nov 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.