Skip to content

Commit 1262745

Browse files
committed
[CMake][NFC] Refactor iOS simulator/device test configuration generation code for ASan.
Summary: The previous code hard-coded platform names but compiler-rt's CMake build system actually already knows which Apple platforms ASan supports. This change uses this information to enumerate the different Apple platforms. rdar://problem/58798733 Reviewers: kubamracek, yln Subscribers: mgorny, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D73232
1 parent 29c7e6c commit 1262745

File tree

2 files changed

+44
-45
lines changed

2 files changed

+44
-45
lines changed

compiler-rt/cmake/config-ix.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ function(get_test_cflags_for_apple_platform platform arch cflags_out)
224224
set(${cflags_out} "${test_cflags_str}" PARENT_SCOPE)
225225
endfunction()
226226

227+
function(get_capitalized_apple_platform platform platform_capitalized)
228+
# TODO(dliew): Remove uses of this function. It exists to preserve needlessly complex
229+
# directory naming conventions used by the Sanitizer lit test suites.
230+
is_valid_apple_platform("${platform}" is_valid_platform)
231+
if (NOT is_valid_platform)
232+
message(FATAL_ERROR "\"${platform}\" is not a valid apple platform")
233+
endif()
234+
string(TOUPPER "${platform}" platform_upper)
235+
string(REGEX REPLACE "OSSIM$" "OSSim" platform_upper_capitalized "${platform_upper}")
236+
set(${platform_capitalized} "${platform_upper_capitalized}" PARENT_SCOPE)
237+
endfunction()
238+
227239
function(is_valid_apple_platform platform is_valid_out)
228240
set(is_valid FALSE)
229241
if ("${platform}" STREQUAL "")

compiler-rt/test/asan/CMakeLists.txt

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -82,56 +82,43 @@ endforeach()
8282
# variable to select which iOS device or simulator to use, e.g.:
8383
# SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
8484
if(APPLE)
85-
# FIXME(dliew): This logic should be refactored to the way UBSan Darwin
86-
# testing is done.
8785
set(EXCLUDE_FROM_ALL ON)
88-
8986
set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
9087
set(ASAN_TEST_DYNAMIC True)
88+
set(ASAN_APPLE_PLATFORMS ${SANITIZER_COMMON_SUPPORTED_OS})
9189

92-
list_intersect(ASAN_TEST_IOSSIM_ARCHS ASAN_SUPPORTED_ARCH DARWIN_iossim_ARCHS)
93-
foreach(arch ${ASAN_TEST_IOSSIM_ARCHS})
94-
set(ASAN_TEST_APPLE_PLATFORM "iossim")
95-
set(ASAN_TEST_TARGET_ARCH ${arch})
96-
get_test_cflags_for_apple_platform(
97-
"${ASAN_TEST_APPLE_PLATFORM}"
98-
"${ASAN_TEST_TARGET_ARCH}"
99-
ASAN_TEST_TARGET_CFLAGS
100-
)
101-
set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${ASAN_TEST_APPLE_PLATFORM}")
102-
get_bits_for_arch(${arch} ASAN_TEST_BITS)
103-
string(TOUPPER ${arch} ARCH_UPPER_CASE)
104-
set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config")
105-
configure_lit_site_cfg(
106-
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
107-
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
108-
)
109-
add_lit_testsuite(check-asan-iossim-${arch} "AddressSanitizer iOS Simulator ${arch} tests"
110-
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
111-
DEPENDS ${ASAN_TEST_DEPS})
112-
endforeach()
113-
114-
list_intersect(ASAN_TEST_IOS_ARCHS ASAN_SUPPORTED_ARCH DARWIN_ios_ARCHS)
115-
foreach (arch ${ASAN_TEST_IOS_ARCHS})
116-
set(ASAN_TEST_APPLE_PLATFORM "ios")
117-
set(ASAN_TEST_TARGET_ARCH ${arch})
118-
get_test_cflags_for_apple_platform(
119-
"${ASAN_TEST_APPLE_PLATFORM}"
120-
"${arch}"
121-
ASAN_TEST_TARGET_CFLAGS)
122-
set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${ASAN_TEST_APPLE_PLATFORM}")
123-
get_bits_for_arch(${arch} ASAN_TEST_BITS)
124-
string(TOUPPER ${arch} ARCH_UPPER_CASE)
125-
set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config")
126-
configure_lit_site_cfg(
127-
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
128-
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
129-
)
130-
add_lit_testsuite(check-asan-ios-${arch} "AddressSanitizer iOS ${arch} tests"
131-
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
132-
DEPENDS ${ASAN_TEST_DEPS})
90+
foreach(platform ${ASAN_APPLE_PLATFORMS})
91+
if ("${platform}" STREQUAL "osx")
92+
# Skip macOS because it's handled by the code above that builds tests for the host machine.
93+
continue()
94+
endif()
95+
list_intersect(
96+
ASAN_TEST_${platform}_ARCHS
97+
ASAN_SUPPORTED_ARCH
98+
DARWIN_${platform}_ARCHS
99+
)
100+
foreach(arch ${ASAN_TEST_${platform}_ARCHS})
101+
get_test_cflags_for_apple_platform(
102+
"${platform}"
103+
"${arch}"
104+
ASAN_TEST_TARGET_CFLAGS
105+
)
106+
string(TOUPPER "${arch}" ARCH_UPPER_CASE)
107+
get_capitalized_apple_platform("${platform}" PLATFORM_CAPITALIZED)
108+
set(CONFIG_NAME "${PLATFORM_CAPITALIZED}${ARCH_UPPER_CASE}Config")
109+
set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${platform}")
110+
set(ASAN_TEST_APPLE_PLATFORM "${platform}")
111+
set(ASAN_TEST_TARGET_ARCH "${arch}")
112+
get_bits_for_arch(${arch} ASAN_TEST_BITS)
113+
configure_lit_site_cfg(
114+
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
115+
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
116+
)
117+
add_lit_testsuite(check-asan-${platform}-${arch} "AddressSanitizer ${platform} ${arch} tests"
118+
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
119+
DEPENDS ${ASAN_TEST_DEPS})
120+
endforeach()
133121
endforeach()
134-
135122
set(EXCLUDE_FROM_ALL OFF)
136123
endif()
137124

0 commit comments

Comments
 (0)