Skip to content

Commit dff5680

Browse files
philnik777lravenclaw
authored andcommitted
[libc++abi] Fix test failures with GCC 14 (llvm#95759)
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.
1 parent c7ceaad commit dff5680

9 files changed

+57
-21
lines changed

libcxx/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@
327327
{'is_defined': False, 'name': '___cxa_bad_cast', 'type': 'U'}
328328
{'is_defined': False, 'name': '___cxa_bad_typeid', 'type': 'U'}
329329
{'is_defined': False, 'name': '___cxa_begin_catch', 'type': 'U'}
330+
{'is_defined': False, 'name': '___cxa_call_terminate', 'type': 'U'}
330331
{'is_defined': False, 'name': '___cxa_call_unexpected', 'type': 'U'}
331332
{'is_defined': False, 'name': '___cxa_current_exception_type', 'type': 'U'}
332333
{'is_defined': False, 'name': '___cxa_current_primary_exception', 'type': 'U'}
@@ -2593,6 +2594,7 @@
25932594
{'is_defined': True, 'name': '___cxa_bad_cast', 'type': 'I'}
25942595
{'is_defined': True, 'name': '___cxa_bad_typeid', 'type': 'I'}
25952596
{'is_defined': True, 'name': '___cxa_begin_catch', 'type': 'I'}
2597+
{'is_defined': True, 'name': '___cxa_call_terminate', 'type': 'I'}
25962598
{'is_defined': True, 'name': '___cxa_call_unexpected', 'type': 'I'}
25972599
{'is_defined': True, 'name': '___cxa_current_exception_type', 'type': 'I'}
25982600
{'is_defined': True, 'name': '___cxa_current_primary_exception', 'type': 'I'}

libcxx/lib/abi/i686-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,7 @@
23012301
{'is_defined': True, 'name': '__cxa_bad_cast', 'type': 'FUNC'}
23022302
{'is_defined': True, 'name': '__cxa_bad_typeid', 'type': 'FUNC'}
23032303
{'is_defined': True, 'name': '__cxa_begin_catch', 'type': 'FUNC'}
2304+
{'is_defined': True, 'name': '__cxa_call_terminate', 'type': 'FUNC'}
23042305
{'is_defined': True, 'name': '__cxa_call_unexpected', 'type': 'FUNC'}
23052306
{'is_defined': True, 'name': '__cxa_current_exception_type', 'type': 'FUNC'}
23062307
{'is_defined': True, 'name': '__cxa_current_primary_exception', 'type': 'FUNC'}

libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@
327327
{'is_defined': False, 'name': '___cxa_bad_cast', 'type': 'U'}
328328
{'is_defined': False, 'name': '___cxa_bad_typeid', 'type': 'U'}
329329
{'is_defined': False, 'name': '___cxa_begin_catch', 'type': 'U'}
330+
{'is_defined': False, 'name': '___cxa_call_terminate', 'type': 'U'}
330331
{'is_defined': False, 'name': '___cxa_call_unexpected', 'type': 'U'}
331332
{'is_defined': False, 'name': '___cxa_current_exception_type', 'type': 'U'}
332333
{'is_defined': False, 'name': '___cxa_current_primary_exception', 'type': 'U'}
@@ -2627,6 +2628,7 @@
26272628
{'is_defined': True, 'name': '___cxa_bad_cast', 'type': 'I'}
26282629
{'is_defined': True, 'name': '___cxa_bad_typeid', 'type': 'I'}
26292630
{'is_defined': True, 'name': '___cxa_begin_catch', 'type': 'I'}
2631+
{'is_defined': True, 'name': '___cxa_call_terminate', 'type': 'I'}
26302632
{'is_defined': True, 'name': '___cxa_call_unexpected', 'type': 'I'}
26312633
{'is_defined': True, 'name': '___cxa_current_exception_type', 'type': 'I'}
26322634
{'is_defined': True, 'name': '___cxa_current_primary_exception', 'type': 'I'}

libcxx/lib/abi/x86_64-linux-android21.libcxxabi.v1.stable.exceptions.nonew.abilist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,6 +2295,7 @@
22952295
{'is_defined': True, 'name': '__cxa_bad_cast', 'type': 'FUNC'}
22962296
{'is_defined': True, 'name': '__cxa_bad_typeid', 'type': 'FUNC'}
22972297
{'is_defined': True, 'name': '__cxa_begin_catch', 'type': 'FUNC'}
2298+
{'is_defined': True, 'name': '__cxa_call_terminate', 'type': 'FUNC'}
22982299
{'is_defined': True, 'name': '__cxa_call_unexpected', 'type': 'FUNC'}
22992300
{'is_defined': True, 'name': '__cxa_current_exception_type', 'type': 'FUNC'}
23002301
{'is_defined': True, 'name': '__cxa_current_primary_exception', 'type': 'FUNC'}

libcxxabi/include/cxxabi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup();
7777
#endif
7878
extern _LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type();
7979

80+
// GNU extension
81+
// Calls `terminate` with the current exception being caught. This function is used by GCC when a `noexcept` function
82+
// throws an exception inside a try/catch block and doesn't catch it.
83+
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_call_terminate(void*) throw();
84+
8085
// 2.5.4 Rethrowing Exceptions
8186
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_rethrow();
8287

libcxxabi/lib/itanium-exceptions.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ___cxa_begin_catch
55
___cxa_call_unexpected
66
___cxa_current_exception_type
77
___cxa_end_catch
8+
___cxa_call_terminate
89
___cxa_free_dependent_exception
910
___cxa_free_exception
1011
___cxa_get_exception_ptr

libcxxabi/src/cxa_exception.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,11 @@ void __cxa_end_catch() {
589589
}
590590
}
591591

592+
void __cxa_call_terminate(void* unwind_arg) throw() {
593+
__cxa_begin_catch(unwind_arg);
594+
std::terminate();
595+
}
596+
592597
// Note: exception_header may be masquerading as a __cxa_dependent_exception
593598
// and that's ok. exceptionType is there too.
594599
// However watch out for foreign exceptions. Return null for them.

libcxxabi/test/catch_const_pointer_nullptr.pass.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@
88

99
// UNSUPPORTED: no-exceptions
1010

11-
#include <cassert>
12-
13-
// Clang emits warnings about exceptions of type 'Child' being caught by
14-
// an earlier handler of type 'Base'. Congrats clang, you've just
15-
// diagnosed the behavior under test.
16-
#if defined(__clang__)
17-
#pragma clang diagnostic ignored "-Wexceptions"
18-
#endif
11+
// Clang and GCC emit warnings about exceptions of type 'Child' being caught by
12+
// an earlier handler of type 'Base'.
13+
// ADDITIONAL_COMPILE_FLAGS: -Wno-exceptions
1914

20-
#if __has_feature(cxx_nullptr)
15+
#include <cassert>
2116

2217
struct A {};
2318

@@ -124,18 +119,6 @@ void test6()
124119
}
125120
}
126121

127-
128-
#else
129-
130-
void test1() {}
131-
void test2() {}
132-
void test3() {}
133-
void test4() {}
134-
void test5() {}
135-
void test6() {}
136-
137-
#endif
138-
139122
int main(int, char**) {
140123
test1();
141124
test2();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: no-exceptions
10+
11+
// We're testing the diagnosed behaviour here.
12+
// ADDITIONAL_COMPILE_FLAGS: -Wno-exceptions
13+
14+
#include <cassert>
15+
#include <cstdlib>
16+
#include <exception>
17+
18+
#include "test_macros.h"
19+
20+
void func() TEST_NOEXCEPT {
21+
try {
22+
throw 1;
23+
} catch (float) {
24+
}
25+
}
26+
27+
void terminate_handler() {
28+
assert(std::current_exception() != nullptr);
29+
std::exit(0);
30+
}
31+
32+
int main(int, char**) {
33+
std::set_terminate(terminate_handler);
34+
func();
35+
assert(false);
36+
}

0 commit comments

Comments
 (0)