Skip to content

Commit 0c27a4c

Browse files
committed
SwiftShims: memcmp should accept optional pointers on Darwin
Darwin defines memcmp with optional pointers. Update SwiftShims to define it to the same type to avoid deserialization failures where we get one over the other and the types don't match anymore. rdar://140596571
1 parent 11e3ea5 commit 0c27a4c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

stdlib/public/SwiftShims/swift/shims/LibcShims.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ static inline __swift_size_t _swift_stdlib_strlen_unsigned(const unsigned char *
6060
SWIFT_READONLY
6161
static inline int _swift_stdlib_memcmp(const void *s1, const void *s2,
6262
__swift_size_t n) {
63+
#if defined(__APPLE__)
64+
// Darwin defines memcmp with optional pointers, preserve the same type here.
65+
extern int memcmp(const void * _Nullable, const void * _Nullable, __swift_size_t);
6366
// FIXME: Is there a way to identify Glibc specifically?
64-
#if (defined(__gnu_linux__) || defined(__ANDROID__)) && !defined(__musl__)
67+
#elif (defined(__gnu_linux__) || defined(__ANDROID__)) && !defined(__musl__)
6568
extern int memcmp(const void * _Nonnull, const void * _Nonnull, __swift_size_t);
6669
#else
6770
extern int memcmp(const void * _Null_unspecified, const void * _Null_unspecified, __swift_size_t);

validation-test/ClangImporter/memcmp-definitions.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/// rdar://69876253
1+
/// Darwin's memcmp accepts nullable pointers, make sure the SwiftShims one
2+
/// preserves the same type.
23
// REQUIRES: VENDOR=apple
34
// RUN: %target-build-swift %s -o %t.out
45

@@ -9,4 +10,6 @@ func foo () {
910
let a = UnsafeMutableRawPointer.allocate(byteCount: 4, alignment: 4)
1011
let b = UnsafeMutableRawPointer.allocate(byteCount: 4, alignment: 4)
1112
memcmp(a, b, 4)
13+
14+
memcmp(nil, nil, 0)
1215
}

0 commit comments

Comments
 (0)