Skip to content

Commit 9b13d1f

Browse files
[stdlib] Fix cc mismatch violation on swift_isClassType
_isClassType is mainly called by compiler-generated code, but it's also called by stdlib. The call-site of stdlib used @_silgen_name to link the function, so it's called through swiftcc. However its cc is defined as C-cc, so caller and callee used different cc. This patch adds C-compatible decl of swift_isClassType in shims so that it can be called by stdlib with C-cc. This change doesn't break ABI because `_isClassType` in stdlib was defined as internal API.
1 parent 9c8cfb3 commit 9b13d1f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

stdlib/public/SwiftShims/RuntimeShims.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "SwiftStddef.h"
2222
#include "SwiftStdint.h"
23+
#include "SwiftStdbool.h"
2324
#include "Visibility.h"
2425

2526
#ifdef __cplusplus
@@ -61,6 +62,12 @@ int _swift_stdlib_putc_stderr(int C);
6162
SWIFT_RUNTIME_STDLIB_API
6263
__swift_size_t _swift_stdlib_getHardwareConcurrency(void);
6364

65+
#ifdef __swift__
66+
/// Called by ReflectionMirror in stdlib through C-calling-convention
67+
SWIFT_RUNTIME_STDLIB_API
68+
__swift_bool swift_isClassType(const void *type);
69+
#endif
70+
6471
/// Manually allocated memory is at least 16-byte aligned in Swift.
6572
///
6673
/// When swift_slowAlloc is called with "default" alignment (alignMask ==

stdlib/public/core/ReflectionMirror.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212

1313
import SwiftShims
1414

15-
@_silgen_name("swift_isClassType")
16-
internal func _isClassType(_: Any.Type) -> Bool
15+
internal func _isClassType(_ type: Any.Type) -> Bool {
16+
// a thick metatype is represented with a pointer metadata structure,
17+
// so this unsafeBitCast is a safe operation here.
18+
return swift_isClassType(unsafeBitCast(type, to: UnsafeRawPointer.self))
19+
}
1720

1821
@_silgen_name("swift_getMetadataKind")
1922
internal func _metadataKind(_: Any.Type) -> UInt

0 commit comments

Comments
 (0)