Skip to content

Commit b15f9bf

Browse files
committed
[libc++abi] Fix test failures with GCC 14
1 parent 7f1a744 commit b15f9bf

File tree

5 files changed

+49
-21
lines changed

5 files changed

+49
-21
lines changed

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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
// We're testing the diagnosed behaviour here.
10+
// ADDITIONAL_COMPILE_FLAGS: -Wno-exceptions
11+
12+
#include <cassert>
13+
#include <cstdlib>
14+
#include <exception>
15+
16+
#include "test_macros.h"
17+
18+
void func() TEST_NOEXCEPT {
19+
try {
20+
throw 1;
21+
} catch (float) {
22+
}
23+
}
24+
25+
[[noreturn]] void terminate_handler() {
26+
assert(std::current_exception() != nullptr);
27+
std::exit(0);
28+
}
29+
30+
int main(int, char**) {
31+
std::set_terminate(terminate_handler);
32+
func();
33+
assert(false);
34+
}

0 commit comments

Comments
 (0)