Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / CMakeLists.txt
blobd8c779c4ad6c5bf4a5d6fa381ba72c572826d616
1 set(ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
3 set(ASAN_TESTSUITES)
4 set(ASAN_DYNAMIC_TESTSUITES)
6 # Before Windows 8 (CMAKE_SYSTEM_VERSION 6.2), reserving large regions of shadow
7 # memory allocated physical memory for page tables, which made it very
8 # unreliable. Remove the asan tests from check-all in this configuration.
9 set(SHADOW_MAPPING_UNRELIABLE FALSE)
10 if(OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND
11     CMAKE_SYSTEM_VERSION LESS 6.2)
12   set(SHADOW_MAPPING_UNRELIABLE TRUE)
13   message(WARNING "Disabling ASan tests because they are unreliable on Windows 7 and earlier")
14 endif()
16 macro(get_bits_for_arch arch bits)
17   if (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|arm64|mips64|mips64el|s390x|sparcv9|riscv64|loongarch64")
18     set(${bits} 64)
19   elseif (${arch} MATCHES "i386|arm|mips|mipsel|sparc")
20     set(${bits} 32)
21   else()
22     message(FATAL_ERROR "Unknown target architecture: ${arch}")
23   endif()
24 endmacro()
26 set(ASAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
27 list(APPEND ASAN_TEST_DEPS asan)
28 if(NOT COMPILER_RT_STANDALONE_BUILD)
29   if(NOT APPLE AND COMPILER_RT_HAS_LLD AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
30     list(APPEND ASAN_TEST_DEPS lld)
31   endif()
32 endif()
33 set(ASAN_DYNAMIC_TEST_DEPS ${ASAN_TEST_DEPS})
35 set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
36 if(APPLE)
37   darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
38 endif()
39 list(REMOVE_ITEM ASAN_TEST_ARCH sparc sparcv9)
40 if(OS_NAME MATCHES "SunOS")
41   list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
42 endif()
44 foreach(arch ${ASAN_TEST_ARCH})
45   set(ASAN_TEST_TARGET_ARCH ${arch})
46   set(ASAN_TEST_APPLE_PLATFORM "osx")
47   set(ASAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_osx_MIN_VER_FLAG}")
48   string(TOLOWER "-${arch}-${OS_NAME}" ASAN_TEST_CONFIG_SUFFIX)
49   get_bits_for_arch(${arch} ASAN_TEST_BITS)
50   get_test_cc_for_arch(${arch} ASAN_TEST_TARGET_CC ASAN_TEST_TARGET_CFLAGS)
51   if(ANDROID OR APPLE)
52     set(ASAN_TEST_DYNAMIC True)
53   else()
54     set(ASAN_TEST_DYNAMIC False)
55   endif()
56   string(TOUPPER ${arch} ARCH_UPPER_CASE)
57   set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
58   if(NOT MINGW)
59     # MinGW environments don't provide a statically linked CRT, so only the
60     # dynamic asan test configuration can be expected to work.
61     configure_lit_site_cfg(
62       ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
63       ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
64       )
65     list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
66   endif()
68   if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
69     string(TOLOWER "-${arch}-${OS_NAME}-dynamic" ASAN_TEST_CONFIG_SUFFIX)
70     set(ASAN_TEST_DYNAMIC True)
71     set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig)
72     configure_lit_site_cfg(
73       ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
74       ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
75     list(APPEND ASAN_DYNAMIC_TESTSUITES
76       ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
77   endif()
79   # ARM on Linux may include thumb code, where fast unwinding does not work.
80   # Enable unwind tables so that we do not end up falling back to it in tests.
81   if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND NOT ANDROID AND ${arch} MATCHES "arm")
82     set(ASAN_TEST_TARGET_CFLAGS "${ASAN_TEST_TARGET_CFLAGS} -funwind-tables")
83   endif()
84 endforeach()
86 # iOS and iOS simulator test suites
87 # These are not added into "check-all", in order to run these tests, use
88 # "check-asan-iossim-x86_64" and similar. They also require that an extra env
89 # variable to select which iOS device or simulator to use, e.g.:
90 # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
91 if(APPLE)
92   set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
93   set(ASAN_TEST_DYNAMIC True)
94   set(ASAN_APPLE_PLATFORMS ${SANITIZER_COMMON_SUPPORTED_OS})
96   foreach(platform ${ASAN_APPLE_PLATFORMS})
97     if ("${platform}" STREQUAL "osx")
98       # Skip macOS because it's handled by the code above that builds tests for the host machine.
99       continue()
100     endif()
101     list_intersect(
102       ASAN_TEST_${platform}_ARCHS
103       ASAN_SUPPORTED_ARCH
104       DARWIN_${platform}_ARCHS
105     )
106     foreach(arch ${ASAN_TEST_${platform}_ARCHS})
107       get_test_cflags_for_apple_platform(
108         "${platform}"
109         "${arch}"
110         ASAN_TEST_TARGET_CFLAGS
111         )
112       string(TOUPPER "${arch}" ARCH_UPPER_CASE)
113       get_capitalized_apple_platform("${platform}" PLATFORM_CAPITALIZED)
114       set(CONFIG_NAME "${PLATFORM_CAPITALIZED}${ARCH_UPPER_CASE}Config")
115       set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${platform}")
116       set(ASAN_TEST_APPLE_PLATFORM "${platform}")
117       set(ASAN_TEST_TARGET_ARCH "${arch}")
118       set(ASAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_${platform}_MIN_VER_FLAG}")
119       get_bits_for_arch(${arch} ASAN_TEST_BITS)
120       configure_lit_site_cfg(
121         ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
122         ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
123         )
124       add_lit_testsuite(check-asan-${platform}-${arch} "AddressSanitizer ${platform} ${arch} tests"
125         ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
126         EXCLUDE_FROM_CHECK_ALL
127         DEPENDS ${ASAN_TEST_DEPS})
128     endforeach()
129   endforeach()
130 endif()
132 # Add unit tests.
133 if(COMPILER_RT_INCLUDE_TESTS)
134   foreach(arch ${ASAN_TEST_ARCH})
135     string(TOUPPER ${arch} ARCH_UPPER_CASE)
136     set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
137     set(CONFIG_NAME_DYNAMIC ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig)
139     if(NOT MINGW)
140       # MinGW environments don't provide a statically linked CRT, so only the
141       # dynamic asan test configuration can be expected to work.
142       set(ASAN_TEST_DYNAMIC False)
143       configure_lit_site_cfg(
144         ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
145         ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py)
146     endif()
147     if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
148       set(ASAN_TEST_DYNAMIC True)
149       configure_lit_site_cfg(
150         ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
151         ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME_DYNAMIC}/lit.site.cfg.py)
152     endif()
153     # FIXME: support unit test in the android test runner
154     if (NOT ANDROID)
155       if (NOT MINGW)
156         list(APPEND ASAN_TEST_DEPS AsanUnitTests)
157         list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME})
158       endif()
159       if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
160         list(APPEND ASAN_DYNAMIC_TEST_DEPS AsanDynamicUnitTests)
161         list(APPEND ASAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME_DYNAMIC})
162       endif()
163     endif()
164   endforeach()
165 endif()
167 if (SHADOW_MAPPING_UNRELIABLE)
168   set(exclude_from_check_all.g "EXCLUDE_FROM_CHECK_ALL")
169 else()
170   set(exclude_from_check_all.g "")
171 endif()
173 add_lit_testsuite(check-asan "Running the AddressSanitizer tests"
174   ${ASAN_TESTSUITES}
175   ${exclude_from_check_all}
176   DEPENDS ${ASAN_TEST_DEPS})
177 set_target_properties(check-asan PROPERTIES FOLDER "Compiler-RT Misc")
179 if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
180   add_lit_testsuite(check-asan-dynamic
181                     "Running the AddressSanitizer tests with dynamic runtime"
182                     ${ASAN_DYNAMIC_TESTSUITES}
183                     ${exclude_from_check_all.g}
184                     DEPENDS ${ASAN_DYNAMIC_TEST_DEPS})
185   set_target_properties(check-asan-dynamic
186                         PROPERTIES FOLDER "Compiler-RT Misc")
187 endif()