Skip to content

Commit aeb4907

Browse files
committed
[libcxxabi] Use the right calling convention for exception destructors on i386 Windows
On Windows on i386, C++ member functions use a different calling convention (`__thiscall`) than the default one for regular functions (`__cdecl`). (On Windows on architectures other than i386, both calling convention attributes are no-ops.) This matches how libstdc++ declares these types. This fixes the std/thread/futures/futures.{shared,unique}_future/dtor.pass.cpp tests on i386 mingw. Differential Revision: https://reviews.llvm.org/D124990
1 parent 448eabd commit aeb4907

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

libcxxabi/include/__cxxabi_config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,10 @@
9797
# define _LIBCXXABI_NO_EXCEPTIONS
9898
#endif
9999

100+
#if defined(_WIN32)
101+
#define _LIBCXXABI_DTOR_FUNC __thiscall
102+
#else
103+
#define _LIBCXXABI_DTOR_FUNC
104+
#endif
105+
100106
#endif // ____CXXABI_CONFIG_H

libcxxabi/include/cxxabi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ __cxa_free_exception(void *thrown_exception) throw();
4747
// 2.4.3 Throwing the Exception Object
4848
extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
4949
__cxa_throw(void *thrown_exception, std::type_info *tinfo,
50-
void (*dest)(void *));
50+
void (_LIBCXXABI_DTOR_FUNC *dest)(void *));
5151

5252
// 2.5.3 Exception Handlers
5353
extern _LIBCXXABI_FUNC_VIS void *

libcxxabi/src/cxa_exception.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ will call terminate, assuming that there was no handler for the
254254
exception.
255255
*/
256256
void
257-
__cxa_throw(void *thrown_object, std::type_info *tinfo, void (*dest)(void *)) {
257+
__cxa_throw(void *thrown_object, std::type_info *tinfo, void (_LIBCXXABI_DTOR_FUNC *dest)(void *)) {
258258
__cxa_eh_globals *globals = __cxa_get_globals();
259259
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
260260

libcxxabi/src/cxa_exception.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
4343

4444
// Manage the exception object itself.
4545
std::type_info *exceptionType;
46-
void (*exceptionDestructor)(void *);
46+
void (_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
4747
std::unexpected_handler unexpectedHandler;
4848
std::terminate_handler terminateHandler;
4949

@@ -81,7 +81,7 @@ struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
8181
#endif
8282

8383
std::type_info *exceptionType;
84-
void (*exceptionDestructor)(void *);
84+
void (_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
8585
std::unexpected_handler unexpectedHandler;
8686
std::terminate_handler terminateHandler;
8787

0 commit comments

Comments
 (0)