From 36f7f1bc87e0e828380f4dbd34669a298c31e0b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferrie=CC=80re?= Date: Tue, 30 Mar 2021 16:33:50 -0700 Subject: [PATCH 1/2] [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 --- stdlib/public/SwiftShims/LibcShims.h | 4 ++++ .../ClangImporter/memcmp-definitions.swift | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 validation-test/ClangImporter/memcmp-definitions.swift diff --git a/stdlib/public/SwiftShims/LibcShims.h b/stdlib/public/SwiftShims/LibcShims.h index 724a3f65414bf..6a59461a41b87 100644 --- a/stdlib/public/SwiftShims/LibcShims.h +++ b/stdlib/public/SwiftShims/LibcShims.h @@ -70,7 +70,11 @@ static inline __swift_size_t _swift_stdlib_strlen_unsigned(const unsigned char * SWIFT_READONLY static inline int _swift_stdlib_memcmp(const void *s1, const void *s2, __swift_size_t n) { +#if defined(__APPLE__) + extern int memcmp(const void * _Nullable, const void * _Nullable, __swift_size_t); +#else extern int memcmp(const void *, const void *, __swift_size_t); +#endif return memcmp(s1, s2, n); } diff --git a/validation-test/ClangImporter/memcmp-definitions.swift b/validation-test/ClangImporter/memcmp-definitions.swift new file mode 100644 index 0000000000000..b16ebe19e853b --- /dev/null +++ b/validation-test/ClangImporter/memcmp-definitions.swift @@ -0,0 +1,11 @@ +/// rdar://69876253 +// RUN: %target-build-swift %s -o %t.out + +import SwiftShims +import Foundation + +func foo () { + let a = UnsafeMutableRawPointer.allocate(byteCount: 4, alignment: 4) + let b = UnsafeMutableRawPointer.allocate(byteCount: 4, alignment: 4) + memcmp(a, b, 4) +} From c6acc9432893c875c6fc51f0a8fcbcd69c04fd30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferrie=CC=80re?= Date: Fri, 2 Apr 2021 12:49:39 -0700 Subject: [PATCH 2/2] [Tests] memcmp-definitions should run only on Apple plaftorms --- validation-test/ClangImporter/memcmp-definitions.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/validation-test/ClangImporter/memcmp-definitions.swift b/validation-test/ClangImporter/memcmp-definitions.swift index b16ebe19e853b..2d0c0df212442 100644 --- a/validation-test/ClangImporter/memcmp-definitions.swift +++ b/validation-test/ClangImporter/memcmp-definitions.swift @@ -1,4 +1,5 @@ /// rdar://69876253 +// REQUIRES: VENDOR=apple // RUN: %target-build-swift %s -o %t.out import SwiftShims