Skip to content

Commit 36f7f1b

Browse files
committed
[SwiftShims] Make the void* arguments of memcmp _Nullable on Darwin
This should correspond to the definition of memcmp in usr/include/string.h and keep it from being a source of confusion for the compiler. rdar://69876253
1 parent fae8f4a commit 36f7f1b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

stdlib/public/SwiftShims/LibcShims.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ static inline __swift_size_t _swift_stdlib_strlen_unsigned(const unsigned char *
7070
SWIFT_READONLY
7171
static inline int _swift_stdlib_memcmp(const void *s1, const void *s2,
7272
__swift_size_t n) {
73+
#if defined(__APPLE__)
74+
extern int memcmp(const void * _Nullable, const void * _Nullable, __swift_size_t);
75+
#else
7376
extern int memcmp(const void *, const void *, __swift_size_t);
77+
#endif
7478
return memcmp(s1, s2, n);
7579
}
7680

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// rdar://69876253
2+
// RUN: %target-build-swift %s -o %t.out
3+
4+
import SwiftShims
5+
import Foundation
6+
7+
func foo () {
8+
let a = UnsafeMutableRawPointer.allocate(byteCount: 4, alignment: 4)
9+
let b = UnsafeMutableRawPointer.allocate(byteCount: 4, alignment: 4)
10+
memcmp(a, b, 4)
11+
}

0 commit comments

Comments
 (0)