Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / sanitizer_common / CMakeLists.txt
blobf2df8cec3549b5d30155b6c104e73895cd39b474
1 set(SANITIZER_COMMON_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
3 set(SANITIZER_COMMON_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
5 set(SANITIZER_COMMON_TESTSUITES)
7 # FIXME(dliew): We should switch to COMPILER_RT_SANITIZERS_TO_BUILD instead of
8 # the hard coded `SUPPORTED_TOOLS_INIT` list once we know that the other
9 # sanitizers work.
10 set(SUPPORTED_TOOLS_INIT asan lsan hwasan msan tsan ubsan)
11 set(SUPPORTED_TOOLS)
12   foreach(SANITIZER_TOOL ${SUPPORTED_TOOLS_INIT})
13     string(TOUPPER ${SANITIZER_TOOL} SANITIZER_TOOL_UPPER)
14     if (COMPILER_RT_HAS_${SANITIZER_TOOL_UPPER})
15       list(APPEND SUPPORTED_TOOLS ${SANITIZER_TOOL})
16     endif()
17   endforeach()
19 # FIXME(dliew): Remove this.
20 # Temporary helper for https://reviews.llvm.org/D55740
21 message(
22   STATUS
23   "Generated Sanitizer SUPPORTED_TOOLS list on \"${CMAKE_SYSTEM_NAME}\" is"
24   " \"${SUPPORTED_TOOLS}\"")
26 # FIXME(dliew): These tests should be made to work on all platforms.
27 # Use the legacy list for now.
28 if (ANDROID OR WINDOWS)
29   set(OLD_SUPPORTED_TOOLS ${SUPPORTED_TOOLS})
30   if (ANDROID)
31     set(SUPPORTED_TOOLS asan)
32   elseif (WINDOWS)
33     set(SUPPORTED_TOOLS "")
34   else()
35     message(FATAL_ERROR "Unhandled platform")
36   endif()
37         message(
38                 AUTHOR_WARNING
39     "Replacing Sanitizer SUPPORTED_TOOLS list (${OLD_SUPPORTED_TOOLS}) with "
40     "\"${SUPPORTED_TOOLS}\"")
41   unset(OLD_SUPPORTED_TOOLS)
42 endif()
44 # FIXME(dliew): Remove this.
45 # Temporary helper for https://reviews.llvm.org/D55740
46 message(
47   STATUS
48   "sanitizer_common tests on \"${CMAKE_SYSTEM_NAME}\" will run against "
49   "\"${SUPPORTED_TOOLS}\"")
51 # Create a separate config for each tool we support.
52 foreach(tool ${SUPPORTED_TOOLS})
53   string(TOUPPER ${tool} tool_toupper)
54   if(${tool_toupper}_SUPPORTED_ARCH AND NOT COMPILER_RT_STANDALONE_BUILD)
55     list(APPEND SANITIZER_COMMON_TEST_DEPS ${tool})
56   endif()
57   set(TEST_ARCH ${${tool_toupper}_SUPPORTED_ARCH})
58   if(APPLE)
59     darwin_filter_host_archs(${tool_toupper}_SUPPORTED_ARCH TEST_ARCH)
60   endif()
61   if(${tool} STREQUAL "asan")
62     list(REMOVE_ITEM TEST_ARCH sparc sparcv9)
63   endif()
64   if(OS_NAME MATCHES "SunOS" AND ${tool} STREQUAL "asan")
65     list(REMOVE_ITEM TEST_ARCH x86_64)
66   endif()
68   # TODO(dliew): We should iterate over the different
69   # Apple platforms, not just macOS.
70   foreach(arch ${TEST_ARCH})
71     set(SANITIZER_COMMON_LIT_TEST_MODE ${tool})
72     set(SANITIZER_COMMON_TEST_TARGET_ARCH ${arch})
73     get_test_cc_for_arch(${arch} SANITIZER_COMMON_TEST_TARGET_CC SANITIZER_COMMON_TEST_TARGET_CFLAGS)
74     set(CONFIG_NAME ${tool}-${arch}-${OS_NAME})
76     # ARM on Linux might use the slow unwinder as default and the unwind table is
77     # required to get a complete stacktrace.
78     if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND NOT ANDROID)
79       list(APPEND SANITIZER_COMMON_TEST_TARGET_CFLAGS -funwind-tables)
80       if(CMAKE_SYSROOT)
81         list(APPEND SANITIZER_COMMON_TEST_TARGET_CFLAGS "--sysroot=${CMAKE_SYSROOT}")
82       endif()
83       string(REPLACE ";" " " SANITIZER_COMMON_TEST_TARGET_CFLAGS
84                              "${SANITIZER_COMMON_TEST_TARGET_CFLAGS}")
85     endif()
87     configure_lit_site_cfg(
88       ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
89       ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
90     # FIXME(dliew): LSan i386 on Darwin is completely broken right now.
91     # so don't run the tests by default.
92     if (NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin" AND
93              ${tool} STREQUAL "lsan" AND
94              ${arch} STREQUAL "i386"))
95       list(APPEND SANITIZER_COMMON_TESTSUITES
96            ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
97     endif()
98   endforeach()
99 endforeach()
101 # Unit tests.
102 if(COMPILER_RT_INCLUDE_TESTS)
103   configure_lit_site_cfg(
104     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
105     ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
106   # FIXME: support unit test in the android test runner
107   if (NOT ANDROID)
108     list(APPEND SANITIZER_COMMON_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
109     list(APPEND SANITIZER_COMMON_TEST_DEPS SanitizerUnitTests)
110   endif()
111 endif()
113 if(SANITIZER_COMMON_TESTSUITES)
114   add_lit_testsuite(check-sanitizer "Running sanitizer_common tests"
115     ${SANITIZER_COMMON_TESTSUITES}
116     DEPENDS ${SANITIZER_COMMON_TEST_DEPS})
117   set_target_properties(check-sanitizer PROPERTIES FOLDER
118                         "Compiler-RT Misc")
119 endif()