Skip to content

Commit

Permalink
[libc++abi] Fix test failures with GCC 14
Browse files Browse the repository at this point in the history
  • Loading branch information
philnik777 committed Jun 30, 2024
1 parent 7f1a744 commit fd1e0d5
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
{'is_defined': False, 'name': '___cxa_bad_cast', 'type': 'U'}
{'is_defined': False, 'name': '___cxa_bad_typeid', 'type': 'U'}
{'is_defined': False, 'name': '___cxa_begin_catch', 'type': 'U'}
{'is_defined': False, 'name': '___cxa_call_terminate', 'type': 'U'}
{'is_defined': False, 'name': '___cxa_call_unexpected', 'type': 'U'}
{'is_defined': False, 'name': '___cxa_current_exception_type', 'type': 'U'}
{'is_defined': False, 'name': '___cxa_current_primary_exception', 'type': 'U'}
Expand Down Expand Up @@ -2593,6 +2594,7 @@
{'is_defined': True, 'name': '___cxa_bad_cast', 'type': 'I'}
{'is_defined': True, 'name': '___cxa_bad_typeid', 'type': 'I'}
{'is_defined': True, 'name': '___cxa_begin_catch', 'type': 'I'}
{'is_defined': True, 'name': '___cxa_call_terminate', 'type': 'I'}
{'is_defined': True, 'name': '___cxa_call_unexpected', 'type': 'I'}
{'is_defined': True, 'name': '___cxa_current_exception_type', 'type': 'I'}
{'is_defined': True, 'name': '___cxa_current_primary_exception', 'type': 'I'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,7 @@
{'is_defined': True, 'name': '__cxa_bad_cast', 'type': 'FUNC'}
{'is_defined': True, 'name': '__cxa_bad_typeid', 'type': 'FUNC'}
{'is_defined': True, 'name': '__cxa_begin_catch', 'type': 'FUNC'}
{'is_defined': True, 'name': '__cxa_call_terminate', 'type': 'FUNC'}
{'is_defined': True, 'name': '__cxa_call_unexpected', 'type': 'FUNC'}
{'is_defined': True, 'name': '__cxa_current_exception_type', 'type': 'FUNC'}
{'is_defined': True, 'name': '__cxa_current_primary_exception', 'type': 'FUNC'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
{'is_defined': False, 'name': '___cxa_bad_cast', 'type': 'U'}
{'is_defined': False, 'name': '___cxa_bad_typeid', 'type': 'U'}
{'is_defined': False, 'name': '___cxa_begin_catch', 'type': 'U'}
{'is_defined': False, 'name': '___cxa_call_terminate', 'type': 'U'}
{'is_defined': False, 'name': '___cxa_call_unexpected', 'type': 'U'}
{'is_defined': False, 'name': '___cxa_current_exception_type', 'type': 'U'}
{'is_defined': False, 'name': '___cxa_current_primary_exception', 'type': 'U'}
Expand Down Expand Up @@ -2627,6 +2628,7 @@
{'is_defined': True, 'name': '___cxa_bad_cast', 'type': 'I'}
{'is_defined': True, 'name': '___cxa_bad_typeid', 'type': 'I'}
{'is_defined': True, 'name': '___cxa_begin_catch', 'type': 'I'}
{'is_defined': True, 'name': '___cxa_call_terminate', 'type': 'I'}
{'is_defined': True, 'name': '___cxa_call_unexpected', 'type': 'I'}
{'is_defined': True, 'name': '___cxa_current_exception_type', 'type': 'I'}
{'is_defined': True, 'name': '___cxa_current_primary_exception', 'type': 'I'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,7 @@
{'is_defined': True, 'name': '__cxa_bad_cast', 'type': 'FUNC'}
{'is_defined': True, 'name': '__cxa_bad_typeid', 'type': 'FUNC'}
{'is_defined': True, 'name': '__cxa_begin_catch', 'type': 'FUNC'}
{'is_defined': True, 'name': '__cxa_call_terminate', 'type': 'FUNC'}
{'is_defined': True, 'name': '__cxa_call_unexpected', 'type': 'FUNC'}
{'is_defined': True, 'name': '__cxa_current_exception_type', 'type': 'FUNC'}
{'is_defined': True, 'name': '__cxa_current_primary_exception', 'type': 'FUNC'}
Expand Down
5 changes: 5 additions & 0 deletions libcxxabi/include/cxxabi.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup();
#endif
extern _LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type();

// GNU extension
// Calls `terminate` with the current exception being caught. This function is used by GCC when a `noexcept` function
// throws an exception inside a try/catch block and doesn't catch it.
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();

Expand Down
1 change: 1 addition & 0 deletions libcxxabi/lib/itanium-exceptions.exp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ___cxa_begin_catch
___cxa_call_unexpected
___cxa_current_exception_type
___cxa_end_catch
___cxa_call_terminate
___cxa_free_dependent_exception
___cxa_free_exception
___cxa_get_exception_ptr
Expand Down
5 changes: 5 additions & 0 deletions libcxxabi/src/cxa_exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 4 additions & 21 deletions libcxxabi/test/catch_const_pointer_nullptr.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};

Expand Down Expand Up @@ -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();
Expand Down
36 changes: 36 additions & 0 deletions libcxxabi/test/cxa_call_terminate.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: no-exceptions

// We're testing the diagnosed behaviour here.
// ADDITIONAL_COMPILE_FLAGS: -Wno-exceptions

#include <cassert>
#include <cstdlib>
#include <exception>

#include "test_macros.h"

void func() TEST_NOEXCEPT {
try {
throw 1;
} catch (float) {
}
}

void terminate_handler() {
assert(std::current_exception() != nullptr);
std::exit(0);
}

int main(int, char**) {
std::set_terminate(terminate_handler);
func();
assert(false);
}

0 comments on commit fd1e0d5

Please sign in to comment.