mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #78622 from rintaro/sanitizer-rdar142516855
[CMake] Globally set sanitizer options for Swift targets
This commit is contained in:
@@ -63,7 +63,6 @@ function(_add_host_swift_compile_options name)
|
||||
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-tools-directory;${tools_path};>)
|
||||
endif()
|
||||
endif()
|
||||
_add_host_variant_swift_sanitizer_flags(${name})
|
||||
|
||||
target_compile_options(${name} PRIVATE
|
||||
$<$<COMPILE_LANGUAGE:Swift>:-color-diagnostics>
|
||||
|
||||
@@ -82,36 +82,6 @@ function(_set_target_prefix_and_suffix target kind sdk)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(_add_host_variant_swift_sanitizer_flags target)
|
||||
if(LLVM_USE_SANITIZER)
|
||||
if(LLVM_USE_SANITIZER STREQUAL "Address")
|
||||
set(_Swift_SANITIZER_FLAGS "-sanitize=address" "-Xclang-linker" "-fsanitize=address")
|
||||
elseif(LLVM_USE_SANITIZER STREQUAL "HWAddress")
|
||||
# Not supported?
|
||||
elseif(LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
|
||||
# Not supported
|
||||
if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
|
||||
# Not supported
|
||||
endif()
|
||||
elseif(LLVM_USE_SANITIZER STREQUAL "Undefined")
|
||||
set(_Swift_SANITIZER_FLAGS "-sanitize=undefined" "-Xclang-linker" "-fsanitize=undefined")
|
||||
elseif(LLVM_USE_SANITIZER STREQUAL "Thread")
|
||||
set(_Swift_SANITIZER_FLAGS "-sanitize=thread" "-Xclang-linker" "-fsanitize=thread")
|
||||
elseif(LLVM_USE_SANITIZER STREQUAL "DataFlow")
|
||||
# Not supported
|
||||
elseif(LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
|
||||
LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
|
||||
set(_Swift_SANITIZER_FLAGS "-sanitize=address" "-sanitize=undefined" "-Xclang-linker" "-fsanitize=address" "-Xclang-linker" "-fsanitize=undefined")
|
||||
elseif(LLVM_USE_SANITIZER STREQUAL "Leaks")
|
||||
# Not supported
|
||||
else()
|
||||
message(SEND_ERROR "unsupported value for LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
|
||||
endif()
|
||||
|
||||
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:${_Swift_SANITIZER_FLAGS}>)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(swift_get_host_triple out_var)
|
||||
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
|
||||
set(DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}")
|
||||
@@ -145,8 +115,6 @@ function(_add_host_variant_c_compile_link_flags name)
|
||||
|
||||
if (CMAKE_Swift_COMPILER)
|
||||
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-target;${SWIFT_HOST_TRIPLE}>)
|
||||
|
||||
_add_host_variant_swift_sanitizer_flags(${name})
|
||||
endif()
|
||||
|
||||
set(_sysroot
|
||||
|
||||
@@ -377,3 +377,35 @@ function(swift_common_llvm_config target)
|
||||
llvm_config("${target}" ${ARGN})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Set sanitizer options to all Swift compiler flags. Similar options are added to C/CXX compiler in 'HandleLLVMOptions'
|
||||
macro(swift_common_sanitizer_config)
|
||||
if(LLVM_USE_SANITIZER)
|
||||
if(LLVM_USE_SANITIZER STREQUAL "Address")
|
||||
set(_Swift_SANITIZER_FLAGS "-sanitize=address -Xclang-linker -fsanitize=address")
|
||||
elseif(LLVM_USE_SANITIZER STREQUAL "HWAddress")
|
||||
# Not supported?
|
||||
elseif(LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
|
||||
# Not supported
|
||||
if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
|
||||
# Not supported
|
||||
endif()
|
||||
elseif(LLVM_USE_SANITIZER STREQUAL "Undefined")
|
||||
set(_Swift_SANITIZER_FLAGS "-sanitize=undefined -Xclang-linker -fsanitize=undefined")
|
||||
elseif(LLVM_USE_SANITIZER STREQUAL "Thread")
|
||||
set(_Swift_SANITIZER_FLAGS "-sanitize=thread -Xclang-linker -fsanitize=thread")
|
||||
elseif(LLVM_USE_SANITIZER STREQUAL "DataFlow")
|
||||
# Not supported
|
||||
elseif(LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
|
||||
LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
|
||||
set(_Swift_SANITIZER_FLAGS "-sanitize=address -sanitize=undefined -Xclang-linker -fsanitize=address -Xclang-linker -fsanitize=undefined")
|
||||
elseif(LLVM_USE_SANITIZER STREQUAL "Leaks")
|
||||
# Not supported
|
||||
else()
|
||||
message(SEND_ERROR "unsupported value for LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
|
||||
endif()
|
||||
|
||||
set(CMAKE_Swift_FLAGS "${CMAKE_Swift_FLAGS} ${_Swift_SANITIZER_FLAGS}")
|
||||
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
Reference in New Issue
Block a user