Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++abi] Fix test failures with GCC 14 #95759

Merged
merged 1 commit into from
Jun 30, 2024

Conversation

philnik777
Copy link
Contributor

This adds a new __cxa_call_terminate, which GCC 14 generates calls to now. Clang had __clang_call_terminate for the same use-case for a long time. It also fixes a test that is enabled now, since GCC has the __has_feature FTM now.

@philnik777 philnik777 requested a review from a team as a code owner June 17, 2024 09:29
@llvmbot llvmbot added the libc++abi libc++abi C++ Runtime Library. Not libc++. label Jun 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 17, 2024

@llvm/pr-subscribers-libcxx

@llvm/pr-subscribers-libcxxabi

Author: Nikolas Klauser (philnik777)

Changes

This adds a new __cxa_call_terminate, which GCC 14 generates calls to now. Clang had __clang_call_terminate for the same use-case for a long time. It also fixes a test that is enabled now, since GCC has the __has_feature FTM now.


Full diff: https://github.com/llvm/llvm-project/pull/95759.diff

3 Files Affected:

  • (modified) libcxxabi/include/cxxabi.h (+3)
  • (modified) libcxxabi/src/cxa_exception.cpp (+5)
  • (modified) libcxxabi/test/catch_const_pointer_nullptr.pass.cpp (+4-21)
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index 0e3969084e04f..9628ca737e6e1 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -77,6 +77,9 @@ extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup();
 #endif
 extern _LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type();
 
+// GNU extension
+extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_call_terminate(void*) throw();
+
 // 2.5.4 Rethrowing Exceptions
 extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_rethrow();
 
diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp
index ff69a4c65e465..014e6e8ac8420 100644
--- a/libcxxabi/src/cxa_exception.cpp
+++ b/libcxxabi/src/cxa_exception.cpp
@@ -589,6 +589,11 @@ void __cxa_end_catch() {
     }
 }
 
+void __cxa_call_terminate(void* unwind_arg) throw() {
+    __cxa_begin_catch(unwind_arg);
+    std::terminate();
+}
+
 // Note:  exception_header may be masquerading as a __cxa_dependent_exception
 //        and that's ok.  exceptionType is there too.
 //        However watch out for foreign exceptions.  Return null for them.
diff --git a/libcxxabi/test/catch_const_pointer_nullptr.pass.cpp b/libcxxabi/test/catch_const_pointer_nullptr.pass.cpp
index a0d1f36f050f0..a66e6c9e53075 100644
--- a/libcxxabi/test/catch_const_pointer_nullptr.pass.cpp
+++ b/libcxxabi/test/catch_const_pointer_nullptr.pass.cpp
@@ -8,16 +8,11 @@
 
 // UNSUPPORTED: no-exceptions
 
-#include <cassert>
-
-// Clang emits  warnings about exceptions of type 'Child' being caught by
-// an earlier handler of type 'Base'. Congrats clang, you've just
-// diagnosed the behavior under test.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wexceptions"
-#endif
+// Clang and GCC emit warnings about exceptions of type 'Child' being caught by
+// an earlier handler of type 'Base'.
+// ADDITIONAL_COMPILE_FLAGS: -Wno-exceptions
 
-#if __has_feature(cxx_nullptr)
+#include <cassert>
 
 struct A {};
 
@@ -124,18 +119,6 @@ void test6()
     }
 }
 
-
-#else
-
-void test1() {}
-void test2() {}
-void test3() {}
-void test4() {}
-void test5() {}
-void test6() {}
-
-#endif
-
 int main(int, char**) {
     test1();
     test2();

Copy link

github-actions bot commented Jun 17, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with comments.

libcxxabi/include/cxxabi.h Show resolved Hide resolved
libcxxabi/include/cxxabi.h Show resolved Hide resolved
libcxxabi/src/cxa_exception.cpp Show resolved Hide resolved
libcxxabi/include/cxxabi.h Show resolved Hide resolved
@philnik777 philnik777 force-pushed the libcxxabi_fix_gcc14 branch 3 times, most recently from b15f9bf to f5ccdfd Compare June 28, 2024 08:06
@philnik777 philnik777 requested a review from a team as a code owner June 28, 2024 08:06
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jun 28, 2024
@philnik777 philnik777 force-pushed the libcxxabi_fix_gcc14 branch from f5ccdfd to 75a10e5 Compare June 29, 2024 14:51
@philnik777 philnik777 force-pushed the libcxxabi_fix_gcc14 branch from 75a10e5 to fd1e0d5 Compare June 30, 2024 08:11
@philnik777 philnik777 merged commit 0c9f537 into llvm:main Jun 30, 2024
52 of 54 checks passed
@philnik777 philnik777 deleted the libcxxabi_fix_gcc14 branch June 30, 2024 10:09
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
This adds a new `__cxa_call_terminate`, which GCC 14 generates calls to
now. Clang had `__clang_call_terminate` for the same use-case for a long
time. It also fixes a test that is enabled now, since GCC has the
`__has_feature` FTM now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++abi libc++abi C++ Runtime Library. Not libc++. libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants