Skip to content

Commit cc9a567

Browse files
committed
stdlib: use the destructor CC adjustment thunk
Use the wrapper for the CC adjustment as on Windows x86, the destructor needs to be `__stdcall`. This would fail otherwise with the following: ``` D:\a\1\s\swift\stdlib\public\stubs\ThreadLocalStorage.cpp(86,18): error: no matching function for call to '_stdlib_thread_key_create' int result = SWIFT_THREAD_KEY_CREATE(&key, [](void *pointer) { ^~~~~~~~~~~~~~~~~~~~~~~ D:\a\1\s\swift\stdlib\public\stubs/../runtime/ThreadLocalStorage.h(96,35): note: expanded from macro 'SWIFT_THREAD_KEY_CREATE' ^~~~~~~~~~~~~~~~~~~~~~~~~ D:\a\1\s\swift\include\swift/Basic/Lazy.h(42,27): note: expanded from macro 'SWIFT_ONCE_F' ::std::call_once(TOKEN, FUNC, CONTEXT) ^~~~ D:\a\1\s\swift\stdlib\public\stubs\ThreadLocalStorage.cpp(43,1): note: candidate function not viable: no known conversion from '(lambda at D:\a\1\s\swift\stdlib\public\stubs\ThreadLocalStorage.cpp:85:3)' to '__swift_thread_key_destructor _Nullable' (aka 'void (*)(void *) __attribute__((stdcall))') for 2nd argument _stdlib_thread_key_create(__swift_thread_key_t * _Nonnull key, ^ ```
1 parent 6562fa4 commit cc9a567

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

stdlib/public/stubs/ThreadLocalStorage.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ void _stdlib_destroyTLS(void *);
2323
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API
2424
void *_stdlib_createTLS(void);
2525

26-
#if defined(_WIN32) && !defined(__CYGWIN__)
27-
28-
typedef
29-
#if defined(_M_IX86)
30-
__stdcall
31-
#endif
32-
void (*__swift_thread_key_destructor)(void *);
33-
3426
static void
3527
#if defined(_M_IX86)
3628
__stdcall
@@ -39,6 +31,14 @@ destroyTLS_CCAdjustmentThunk(void *ptr) {
3931
_stdlib_destroyTLS(ptr);
4032
}
4133

34+
#if defined(_WIN32) && !defined(__CYGWIN__)
35+
36+
typedef
37+
#if defined(_M_IX86)
38+
__stdcall
39+
#endif
40+
void (*__swift_thread_key_destructor)(void *);
41+
4242
static inline int
4343
_stdlib_thread_key_create(__swift_thread_key_t * _Nonnull key,
4444
__swift_thread_key_destructor _Nullable destructor) {
@@ -83,9 +83,7 @@ _swift_stdlib_threadLocalStorageGet(void) {
8383
static __swift_thread_key_t key;
8484

8585
SWIFT_ONCE_F(token, [](void *) {
86-
int result = SWIFT_THREAD_KEY_CREATE(&key, [](void *pointer) {
87-
_stdlib_destroyTLS(pointer);
88-
});
86+
int result = SWIFT_THREAD_KEY_CREATE(&key, destroyTLS_CCAdjustmentThunk);
8987
if (result != 0)
9088
swift::fatalError(0, "couldn't create pthread key for stdlib TLS: %s\n",
9189
std::strerror(result));

0 commit comments

Comments
 (0)