Merge pull request #390 from dingobye/redundant_access_modifier

Fix redundant access-level modifiers.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e895217..0c6b3af 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
 
 cmake_minimum_required(VERSION 3.4.3)
 
-list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
 
 project(dispatch
         VERSION 1.3
@@ -134,12 +134,12 @@
 
 find_package(BlocksRuntime QUIET)
 if(NOT BlocksRuntime_FOUND)
-  set(BlocksRuntime_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src/BlocksRuntime)
+  set(BlocksRuntime_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/BlocksRuntime)
 
   add_library(BlocksRuntime
               STATIC
-                ${CMAKE_SOURCE_DIR}/src/BlocksRuntime/data.c
-                ${CMAKE_SOURCE_DIR}/src/BlocksRuntime/runtime.c)
+                ${PROJECT_SOURCE_DIR}/src/BlocksRuntime/data.c
+                ${PROJECT_SOURCE_DIR}/src/BlocksRuntime/runtime.c)
   set_target_properties(BlocksRuntime
                         PROPERTIES
                           POSITION_INDEPENDENT_CODE TRUE)
@@ -152,12 +152,12 @@
   add_library(BlocksRuntime::BlocksRuntime ALIAS BlocksRuntime)
 
   install(FILES
-            ${CMAKE_SOURCE_DIR}/src/BlocksRuntime/Block.h
+            ${PROJECT_SOURCE_DIR}/src/BlocksRuntime/Block.h
           DESTINATION
             "${INSTALL_BLOCK_HEADERS_DIR}")
   if(INSTALL_PRIVATE_HEADERS)
     install(FILES
-              ${CMAKE_SOURCE_DIR}/src/BlocksRuntime/Block_private.h
+              ${PROJECT_SOURCE_DIR}/src/BlocksRuntime/Block_private.h
             DESTINATION
               "${INSTALL_BLOCK_HEADERS_DIR}")
   endif()
@@ -300,35 +300,35 @@
 
 if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
   add_custom_command(OUTPUT
-                       "${CMAKE_SOURCE_DIR}/dispatch/module.modulemap"
-                       "${CMAKE_SOURCE_DIR}/private/module.modulemap"
+                       "${PROJECT_SOURCE_DIR}/dispatch/module.modulemap"
+                       "${PROJECT_SOURCE_DIR}/private/module.modulemap"
                      COMMAND
-                       ${CMAKE_COMMAND} -E create_symlink "${CMAKE_SOURCE_DIR}/dispatch/darwin/module.modulemap" "${CMAKE_SOURCE_DIR}/dispatch/module.modulemap"
+                       ${CMAKE_COMMAND} -E create_symlink "${PROJECT_SOURCE_DIR}/dispatch/darwin/module.modulemap" "${PROJECT_SOURCE_DIR}/dispatch/module.modulemap"
                      COMMAND
-                       ${CMAKE_COMMAND} -E create_symlink "${CMAKE_SOURCE_DIR}/private/darwin/module.modulemap" "${CMAKE_SOURCE_DIR}/private/module.modulemap")
+                       ${CMAKE_COMMAND} -E create_symlink "${PROJECT_SOURCE_DIR}/private/darwin/module.modulemap" "${PROJECT_SOURCE_DIR}/private/module.modulemap")
 elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
   add_custom_command(OUTPUT
-                       "${CMAKE_SOURCE_DIR}/dispatch/module.modulemap"
-                       "${CMAKE_SOURCE_DIR}/private/module.modulemap"
+                       "${PROJECT_SOURCE_DIR}/dispatch/module.modulemap"
+                       "${PROJECT_SOURCE_DIR}/private/module.modulemap"
                      COMMAND
-                       ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/dispatch/generic/module.modulemap" "${CMAKE_SOURCE_DIR}/dispatch/module.modulemap"
+                       ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/dispatch/generic/module.modulemap" "${PROJECT_SOURCE_DIR}/dispatch/module.modulemap"
                      COMMAND
-                       ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/private/generic/module.modulemap" "${CMAKE_SOURCE_DIR}/private/module.modulemap")
+                       ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/private/generic/module.modulemap" "${PROJECT_SOURCE_DIR}/private/module.modulemap")
 else()
   add_custom_command(OUTPUT
-                       "${CMAKE_SOURCE_DIR}/dispatch/module.modulemap"
-                       "${CMAKE_SOURCE_DIR}/private/module.modulemap"
+                       "${PROJECT_SOURCE_DIR}/dispatch/module.modulemap"
+                       "${PROJECT_SOURCE_DIR}/private/module.modulemap"
                      COMMAND
-                       ${CMAKE_COMMAND} -E create_symlink "${CMAKE_SOURCE_DIR}/dispatch/generic/module.modulemap" "${CMAKE_SOURCE_DIR}/dispatch/module.modulemap"
+                       ${CMAKE_COMMAND} -E create_symlink "${PROJECT_SOURCE_DIR}/dispatch/generic/module.modulemap" "${PROJECT_SOURCE_DIR}/dispatch/module.modulemap"
                      COMMAND
-                       ${CMAKE_COMMAND} -E create_symlink "${CMAKE_SOURCE_DIR}/private/generic/module.modulemap" "${CMAKE_SOURCE_DIR}/private/module.modulemap")
+                       ${CMAKE_COMMAND} -E create_symlink "${PROJECT_SOURCE_DIR}/private/generic/module.modulemap" "${PROJECT_SOURCE_DIR}/private/module.modulemap")
 endif()
 add_custom_target(module-map-symlinks
                   DEPENDS
-                     "${CMAKE_SOURCE_DIR}/dispatch/module.modulemap"
-                     "${CMAKE_SOURCE_DIR}/private/module.modulemap")
-configure_file("${CMAKE_SOURCE_DIR}/cmake/config.h.in"
-               "${CMAKE_BINARY_DIR}/config/config_ac.h")
+                     "${PROJECT_SOURCE_DIR}/dispatch/module.modulemap"
+                     "${PROJECT_SOURCE_DIR}/private/module.modulemap")
+configure_file("${PROJECT_SOURCE_DIR}/cmake/config.h.in"
+               "${PROJECT_BINARY_DIR}/config/config_ac.h")
 add_definitions(-DHAVE_CONFIG_H)
 
 if(CMAKE_SYSTEM_NAME STREQUAL Windows)
diff --git a/cmake/modules/DispatchWindowsSupport.cmake b/cmake/modules/DispatchWindowsSupport.cmake
index 67a1069..87675a7 100644
--- a/cmake/modules/DispatchWindowsSupport.cmake
+++ b/cmake/modules/DispatchWindowsSupport.cmake
@@ -64,11 +64,11 @@
   set(UCRTVersion $ENV{UCRTVersion})
 
   # TODO(compnerd) use a target to avoid re-creating this file all the time
-  configure_file("${CMAKE_SOURCE_DIR}/utils/WindowsSDKVFSOverlay.yaml.in"
-                 "${CMAKE_BINARY_DIR}/windows-sdk-vfs-overlay.yaml"
+  configure_file("${PROJECT_SOURCE_DIR}/utils/WindowsSDKVFSOverlay.yaml.in"
+                 "${PROJECT_BINARY_DIR}/windows-sdk-vfs-overlay.yaml"
                  @ONLY)
 
   set(${flags}
-      -ivfsoverlay;"${CMAKE_BINARY_DIR}/windows-sdk-vfs-overlay.yaml"
+      -ivfsoverlay;"${PROJECT_BINARY_DIR}/windows-sdk-vfs-overlay.yaml"
       PARENT_SCOPE)
 endfunction()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6b95a9b..80bbd54 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -54,12 +54,7 @@
               shims/time.h
               shims/tsd.h
               shims/yield.h)
-if(UNIX)
-  target_sources(dispatch
-                 PRIVATE
-                   shims/generic_unix_stubs.c
-                   shims/generic_unix_stubs.h)
-elseif(WIN32)
+if(WIN32)
   target_sources(dispatch
                  PRIVATE
                    shims/generic_sys_queue.h
@@ -84,7 +79,7 @@
 endif()
 if(ENABLE_SWIFT)
   set(swift_optimization_flags)
-  if(CMAKE_BUILD_TYPE MATCHES Release)
+  if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
     set(swift_optimization_flags -O)
   endif()
   add_swift_library(swiftDispatch
@@ -110,17 +105,22 @@
                       ${CMAKE_C_COMPILER_TARGET}
                     CFLAGS
                       -fblocks
-                      -fmodule-map-file=${CMAKE_SOURCE_DIR}/dispatch/module.modulemap
+                      -fmodule-map-file=${PROJECT_SOURCE_DIR}/dispatch/module.modulemap
                     SWIFT_FLAGS
-                      -I ${CMAKE_SOURCE_DIR}
+                      -I ${PROJECT_SOURCE_DIR}
                       -I/usr/include
                       ${swift_optimization_flags}
                     DEPENDS
-                      ${CMAKE_SOURCE_DIR}/dispatch/module.modulemap)
+                      ${PROJECT_SOURCE_DIR}/dispatch/module.modulemap)
   target_sources(dispatch
                  PRIVATE
                    swift/DispatchStubs.cc
                    ${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o)
+  if(CMAKE_BUILD_TYPE MATCHES Debug)
+    target_link_libraries(dispatch
+                          PRIVATE
+                            swiftSwiftOnoneSupport)
+  endif()
 endif()
 if(ENABLE_DTRACE)
   dtrace_usdt_probe(${CMAKE_CURRENT_SOURCE_DIR}/provider.d
@@ -132,11 +132,11 @@
 endif()
 target_include_directories(dispatch
                            PRIVATE
-                             ${CMAKE_BINARY_DIR}
-                             ${CMAKE_SOURCE_DIR}
+                             ${PROJECT_BINARY_DIR}
+                             ${PROJECT_SOURCE_DIR}
                              ${CMAKE_CURRENT_SOURCE_DIR}
                              ${CMAKE_CURRENT_BINARY_DIR}
-                             ${CMAKE_SOURCE_DIR}/private)
+                             ${PROJECT_SOURCE_DIR}/private)
 target_include_directories(dispatch
                            SYSTEM BEFORE PRIVATE
                              "${BlocksRuntime_INCLUDE_DIR}")
@@ -191,6 +191,9 @@
 if(BSD_OVERLAY_FOUND)
   target_link_libraries(dispatch PRIVATE ${BSD_OVERLAY_LDFLAGS})
 endif()
+if(LibRT_FOUND)
+  target_link_libraries(dispatch PRIVATE RT::rt)
+endif()
 target_link_libraries(dispatch
                       PRIVATE
                         Threads::Threads
@@ -209,7 +212,7 @@
                  "-Xlinker -compatibility_version -Xlinker 1"
                  "-Xlinker -current_version -Xlinker ${VERSION}"
                  "-Xlinker -dead_strip"
-                 "-Xlinker -alias_list -Xlinker ${CMAKE_SOURCE_DIR}/xcodeconfig/libdispatch.aliases")
+                 "-Xlinker -alias_list -Xlinker ${PROJECT_SOURCE_DIR}/xcodeconfig/libdispatch.aliases")
 endif()
 dispatch_set_linker(dispatch)
 
diff --git a/src/shims.h b/src/shims.h
index 32d2c85..85f4026 100644
--- a/src/shims.h
+++ b/src/shims.h
@@ -33,14 +33,16 @@
 #if defined(_WIN32)
 #include "shims/generic_win_stubs.h"
 #include "shims/generic_sys_queue.h"
-#elif defined(__unix__)
-#include "shims/generic_unix_stubs.h"
 #endif
 
 #ifdef __ANDROID__
 #include "shims/android_stubs.h"
 #endif
 
+#if !HAVE_MACH
+#include "shims/mach.h"
+#endif
+
 #include "shims/hw_config.h"
 #include "shims/priority.h"
 
@@ -79,6 +81,12 @@
 
 #endif // HAVE_STRLCPY
 
+#ifndef TAILQ_FOREACH_SAFE
+#define TAILQ_FOREACH_SAFE(var, head, field, temp)                         \
+	for ((var) = TAILQ_FIRST((head));                                      \
+		(var) && ((temp) = TAILQ_NEXT((var), field), 1); (var) = (temp))
+#endif
+
 #if PTHREAD_WORKQUEUE_SPI_VERSION < 20140716
 static inline int
 _pthread_workqueue_override_start_direct(mach_port_t thread,
diff --git a/src/shims/generic_sys_queue.h b/src/shims/generic_sys_queue.h
index 250abbf..1d9a18d 100644
--- a/src/shims/generic_sys_queue.h
+++ b/src/shims/generic_sys_queue.h
@@ -62,11 +62,6 @@
 	(var) != NULL; \
 	(var) = TAILQ_NEXT(var, field))
 
-#define TAILQ_FOREACH_SAFE(var, list, field, temp) \
-	for ((var) = TAILQ_FIRST(list); \
-	((var) != NULL) && (temp = TAILQ_NEXT(var, field), 1); \
-	(var) = (temp))
-
 #define TAILQ_REMOVE(list, elem, field) do { \
 		if (TAILQ_NEXT(elem, field) != NULL) { \
 			TAILQ_NEXT(elem, field)->field.te_prev = (elem)->field.te_prev; \
diff --git a/src/shims/generic_unix_stubs.c b/src/shims/generic_unix_stubs.c
deleted file mode 100644
index 9197664..0000000
--- a/src/shims/generic_unix_stubs.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * This source file is part of the Swift.org open source project
- *
- * Copyright (c) 2015 Apple Inc. and the Swift project authors
- *
- * Licensed under Apache License v2.0 with Runtime Library Exception
- *
- * See https://swift.org/LICENSE.txt for license information
- * See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
- *
- */
-
-/*
- * This file contains stubbed out functions we are using during
- * the initial linux port.  When the port is complete, this file
- * should be empty (and thus removed).
- */
-
-#include <stdint.h>
-#if defined(__ANDROID__) || defined(__FreeBSD__)
-#include <sys/syscall.h>
-#else
-#include <syscall.h>
-#endif /* __ANDROID__ || __FreeBSD__ */
-
-#if __has_include(<config/config_ac.h>)
-#include <config/config_ac.h>
-#else
-#include <config/config.h>
-#endif
-
-#include "pthread.h"
-#include "os/generic_unix_base.h"
-#include "internal.h"
-
-
-#undef LINUX_PORT_ERROR
-#define LINUX_PORT_ERROR()  do { printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",__FILE__,__LINE__,__FUNCTION__); abort(); } while (0)
-
-
-/*
- * Stubbed out static data
- */
-
-pthread_key_t dispatch_voucher_key;
-pthread_key_t dispatch_pthread_root_queue_observer_hooks_key;
-
-unsigned short dispatch_timer__program_semaphore;
-unsigned short dispatch_timer__wake_semaphore;
-unsigned short dispatch_timer__fire_semaphore;
-unsigned short dispatch_timer__configure_semaphore;
-unsigned short dispatch_queue__pop_semaphore;
-unsigned short dispatch_callout__entry_semaphore;
-unsigned short dispatch_callout__return_semaphore;
-unsigned short dispatch_queue__push_semaphore;
-void (*_dispatch_block_special_invoke)(void*);
-struct dispatch_queue_attr_s _dispatch_queue_attr_concurrent;
diff --git a/src/shims/generic_unix_stubs.h b/src/shims/generic_unix_stubs.h
deleted file mode 100644
index aca569f..0000000
--- a/src/shims/generic_unix_stubs.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * This source file is part of the Swift.org open source project
- *
- * Copyright (c) 2015 Apple Inc. and the Swift project authors
- *
- * Licensed under Apache License v2.0 with Runtime Library Exception
- *
- * See https://swift.org/LICENSE.txt for license information
- * See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
- *
- */
-
-// forward declarations for functions we are stubbing out
-// in the intial linux port.
-
-#ifndef __DISPATCH__STUBS__INTERNAL
-#define __DISPATCH__STUBS__INTERNAL
-
-#ifndef TAILQ_FOREACH_SAFE
-#define TAILQ_FOREACH_SAFE(var, head, field, temp)                         \
-	for ((var) = TAILQ_FIRST((head));                                      \
-		(var) && ((temp) = TAILQ_NEXT((var), field), 1); (var) = (temp))
-#endif
-
-/*
- * Stub out defines for some mach types and related macros
- */
-
-typedef uint32_t mach_port_t;
-
-#define  MACH_PORT_NULL (0)
-#define  MACH_PORT_DEAD (-1)
-
-typedef uint32_t mach_error_t;
-
-typedef uint32_t mach_msg_return_t;
-
-typedef uint32_t mach_msg_bits_t;
-
-typedef void *dispatch_mach_msg_t;
-
-typedef uint64_t firehose_activity_id_t;
-
-typedef void *mach_msg_header_t;
-
-// Print a warning when an unported code path executes.
-#define LINUX_PORT_ERROR()  do { \
-		printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",\
-		__FILE__,__LINE__,__FUNCTION__); } while (0)
-
-/*
- * Stub out defines for other missing types
- */
-
-// SIZE_T_MAX should not be hardcoded like this here.
-#ifndef SIZE_T_MAX
-#define SIZE_T_MAX (~(size_t)0)
-#endif
-
-#endif
diff --git a/src/shims/generic_win_stubs.h b/src/shims/generic_win_stubs.h
index 0680112..c983cdc 100644
--- a/src/shims/generic_win_stubs.h
+++ b/src/shims/generic_win_stubs.h
@@ -11,25 +11,9 @@
 #include <process.h>
 
 /*
- * Stub out defines for some mach types and related macros
+ * Stub out defines for missing types
  */
 
-typedef uint32_t mach_port_t;
-
-#define MACH_PORT_NULL (0)
-
-typedef uint32_t mach_msg_bits_t;
-typedef void *mach_msg_header_t;
-
-/*
- * Stub out defines for other missing types
- */
-
-// SIZE_T_MAX should not be hardcoded like this here.
-#ifndef SIZE_T_MAX
-#define SIZE_T_MAX (~(size_t)0)
-#endif
-
 typedef __typeof__(_Generic((__SIZE_TYPE__)0,                                  \
 			    unsigned long long int : (long long int)0,         \
 			    unsigned long int : (long int)0,                   \
diff --git a/src/shims/mach.h b/src/shims/mach.h
new file mode 100644
index 0000000..759f5f3
--- /dev/null
+++ b/src/shims/mach.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_START@
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_END@
+ */
+
+#ifndef __DISPATCH_SHIMS_MACH__
+#define __DISPATCH_SHIMS_MACH__
+
+/*
+ * Stub out defines for some mach types and related macros
+ */
+
+typedef uint32_t mach_port_t;
+
+#define  MACH_PORT_NULL (0)
+#define  MACH_PORT_DEAD (-1)
+
+typedef uint32_t mach_error_t;
+
+typedef uint32_t mach_msg_return_t;
+
+typedef uint32_t mach_msg_bits_t;
+
+typedef void *dispatch_mach_msg_t;
+
+typedef uint64_t firehose_activity_id_t;
+
+typedef void *mach_msg_header_t;
+
+#endif
diff --git a/src/swift/Queue.swift b/src/swift/Queue.swift
index 1a72db3..377e27f 100644
--- a/src/swift/Queue.swift
+++ b/src/swift/Queue.swift
@@ -51,19 +51,27 @@
 
 	public enum GlobalQueuePriority {
 		@available(macOS, deprecated: 10.10, message: "Use qos attributes instead")
-		@available(*, deprecated: 8.0, message: "Use qos attributes instead")
+		@available(iOS, deprecated: 8.0, message: "Use qos attributes instead")
+		@available(tvOS, deprecated, message: "Use qos attributes instead")
+		@available(watchOS, deprecated, message: "Use qos attributes instead")
 		case high
 
 		@available(macOS, deprecated: 10.10, message: "Use qos attributes instead")
-		@available(*, deprecated: 8.0, message: "Use qos attributes instead")
+		@available(iOS, deprecated: 8.0, message: "Use qos attributes instead")
+		@available(tvOS, deprecated, message: "Use qos attributes instead")
+		@available(watchOS, deprecated, message: "Use qos attributes instead")
 		case `default`
 
 		@available(macOS, deprecated: 10.10, message: "Use qos attributes instead")
-		@available(*, deprecated: 8.0, message: "Use qos attributes instead")
+		@available(iOS, deprecated: 8.0, message: "Use qos attributes instead")
+		@available(tvOS, deprecated, message: "Use qos attributes instead")
+		@available(watchOS, deprecated, message: "Use qos attributes instead")
 		case low
 
 		@available(macOS, deprecated: 10.10, message: "Use qos attributes instead")
-		@available(*, deprecated: 8.0, message: "Use qos attributes instead")
+		@available(iOS, deprecated: 8.0, message: "Use qos attributes instead")
+		@available(tvOS, deprecated, message: "Use qos attributes instead")
+		@available(watchOS, deprecated, message: "Use qos attributes instead")
 		case background
 
 		internal var _translatedValue: Int {
@@ -113,7 +121,9 @@
 	}
 
 	@available(macOS, deprecated: 10.10, message: "")
-	@available(*, deprecated: 8.0, message: "")
+	@available(iOS, deprecated: 8.0, message: "")
+	@available(tvOS, deprecated, message: "")
+	@available(watchOS, deprecated, message: "")
 	public class func global(priority: GlobalQueuePriority) -> DispatchQueue {
 		return DispatchQueue(queue: CDispatch.dispatch_get_global_queue(Int(priority._translatedValue), 0))
 	}
diff --git a/src/swift/Time.swift b/src/swift/Time.swift
index 6e0315e..b30e1f1 100644
--- a/src/swift/Time.swift
+++ b/src/swift/Time.swift
@@ -170,7 +170,6 @@
 	case milliseconds(Int)
 	case microseconds(Int)
 	case nanoseconds(Int)
-	@_downgrade_exhaustivity_check
 	case never
 
 	internal var rawValue: Int64 {
diff --git a/src/transform.c b/src/transform.c
index 7f2c556..45d5669 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -662,7 +662,7 @@
 	dest_size = howmany(total, 5);
 	// <rdar://problem/25676583>
 	// os_mul_overflow(dest_size, 8, &dest_size)
-	if (dest_size > SIZE_T_MAX / 8) {
+	if (dest_size > SIZE_MAX / 8) {
 		return NULL;
 	}
 	dest_size *= 8;
@@ -897,7 +897,7 @@
 	dest_size = howmany(total, 3);
 	// <rdar://problem/25676583>
 	// os_mul_overflow(dest_size, 4, &dest_size)
-	if (dest_size > SIZE_T_MAX / 4) {
+	if (dest_size > SIZE_MAX / 4) {
 		return NULL;
 	}
 	dest_size *= 4;
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 13d8944..3d0ccdd 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,14 +1,14 @@
 
 if(CMAKE_SYSTEM_NAME STREQUAL Windows)
     execute_process(COMMAND
-                      "${CMAKE_COMMAND}" -E copy "${CMAKE_SOURCE_DIR}/private"
+                      "${CMAKE_COMMAND}" -E copy "${PROJECT_SOURCE_DIR}/private"
                       "${CMAKE_CURRENT_BINARY_DIR}/dispatch")
     execute_process(COMMAND
                       "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/leaks-wrapper.sh"
                       "${CMAKE_CURRENT_BINARY_DIR}/leaks-wrapper")
 else()
     execute_process(COMMAND
-                      "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_SOURCE_DIR}/private"
+                      "${CMAKE_COMMAND}" -E create_symlink "${PROJECT_SOURCE_DIR}/private"
                       "${CMAKE_CURRENT_BINARY_DIR}/dispatch")
     execute_process(COMMAND
                       "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/leaks-wrapper.sh"
@@ -27,7 +27,7 @@
                            PRIVATE
                              ${CMAKE_CURRENT_BINARY_DIR}
                              ${CMAKE_CURRENT_SOURCE_DIR}
-                             ${CMAKE_SOURCE_DIR})
+                             ${PROJECT_SOURCE_DIR})
 if(BSD_OVERLAY_FOUND)
   target_compile_options(bsdtests
                          PRIVATE
@@ -41,7 +41,7 @@
                            PRIVATE
                              ${CMAKE_CURRENT_BINARY_DIR}
                              ${CMAKE_CURRENT_SOURCE_DIR}
-                             ${CMAKE_SOURCE_DIR})
+                             ${PROJECT_SOURCE_DIR})
 if(BSD_OVERLAY_FOUND)
   target_compile_options(bsdtestharness
                          PRIVATE
@@ -78,7 +78,7 @@
                              PRIVATE
                                ${CMAKE_CURRENT_BINARY_DIR}
                                ${CMAKE_CURRENT_SOURCE_DIR}
-                               ${CMAKE_SOURCE_DIR})
+                               ${PROJECT_SOURCE_DIR})
   if(ENABLE_SWIFT)
     # For testing in swift.org CI system; make deadlines lenient by default
     # to reduce probability of test failures due to machine load.