[libc] Switch to using the generic `<gpuintrin.h>` implementations (#121810)
[llvm-project.git] / compiler-rt / test / ubsan / CMakeLists.txt
blob9b7fbe3c8f926047e56cee2dffefc484a089b37e
1 set(UBSAN_LIT_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
3 set(UBSAN_TESTSUITES)
4 set(UBSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
6 macro(add_ubsan_testsuite test_mode sanitizer arch lld thinlto)
7   set(UBSAN_LIT_TEST_MODE "${test_mode}")
8   set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE})
9   if (${lld})
10     set(CONFIG_NAME ${CONFIG_NAME}-lld)
11     if ("lld" IN_LIST LLVM_ENABLE_PROJECTS)
12       list(APPEND UBSAN_TEST_DEPS lld)
13     endif()
14   endif()
15   if (${thinlto})
16     set(CONFIG_NAME ${CONFIG_NAME}-thinlto)
17     list(APPEND UBSAN_TEST_DEPS LTO)
18   endif()
19   set(UBSAN_TEST_USE_LLD ${lld})
20   set(UBSAN_TEST_USE_THINLTO ${thinlto})
21   set(CONFIG_NAME ${CONFIG_NAME}-${arch})
22   configure_lit_site_cfg(
23     ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
24     ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
25   list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
26   list(APPEND UBSAN_TEST_DEPS ${sanitizer})
27 endmacro()
29 macro(add_ubsan_testsuites test_mode sanitizer arch)
30   add_ubsan_testsuite(${test_mode} ${sanitizer} ${arch} False False)
32   if(COMPILER_RT_HAS_LLD AND arch STREQUAL "x86_64" AND NOT (APPLE OR WIN32))
33     add_ubsan_testsuite(${test_mode} ${sanitizer} ${arch} True False)
34   endif()
35 endmacro()
37 set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_ARCH})
38 if(APPLE)
39   darwin_filter_host_archs(UBSAN_SUPPORTED_ARCH UBSAN_TEST_ARCH)
40 endif()
42 foreach(arch ${UBSAN_TEST_ARCH})
43   set(UBSAN_TEST_TARGET_ARCH ${arch})
44   if (APPLE)
45     set(UBSAN_TEST_APPLE_PLATFORM "osx")
46     set(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_osx_MIN_VER_FLAG}")
47   endif()
48   get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
49   add_ubsan_testsuites("Standalone" ubsan ${arch})
51   if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
52     # TODO(wwchrome): Re-enable ubsan for asan win 64-bit when ready.
53     # Disable ubsan with AddressSanitizer tests for Windows 64-bit,
54     # 64-bit Solaris/x86 and 64-bit SPARC.
55     if((NOT (OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)) AND
56        (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)) AND
57        (NOT ${arch} MATCHES sparcv9))
58       add_ubsan_testsuites("AddressSanitizer" asan ${arch})
59     endif()
60   endif()
61   if(COMPILER_RT_HAS_MSAN AND ";${MSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
62     add_ubsan_testsuites("MemorySanitizer" msan ${arch})
63   endif()
64   if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};" AND NOT ANDROID)
65     add_ubsan_testsuites("ThreadSanitizer" tsan ${arch})
66   endif()
67 endforeach()
69 macro(add_ubsan_device_testsuite test_mode sanitizer platform arch)
70   # Note we expect the caller to have already set UBSAN_TEST_TARGET_CFLAGS
71   set(UBSAN_LIT_TEST_MODE "${test_mode}")
72   set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${platform}-${arch})
73   set(UBSAN_TEST_TARGET_ARCH ${arch})
74   set(UBSAN_TEST_USE_LLD "False")
75   set(UBSAN_TEST_USE_THINLTO "False")
76   if (APPLE)
77     set(UBSAN_TEST_APPLE_PLATFORM "${platform}")
78     set(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_${platform}_MIN_VER_FLAG}")
79   else()
80     unset(UBSAN_TEST_APPLE_PLATFORM)
81     unset(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG)
82   endif()
83   configure_lit_site_cfg(
84     ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
85     ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
86   #list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
87   list(APPEND UBSAN_TEST_DEPS ${sanitizer})
88   add_lit_testsuite(check-ubsan-${test_mode}-${platform}-${arch}
89     "UBSan ${CONFIG_NAME} tests"
90     ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
91     EXCLUDE_FROM_CHECK_ALL
92     DEPENDS ${UBSAN_TEST_DEPS})
93 endmacro()
95 if(APPLE)
96   foreach(arch ${UBSAN_TEST_ARCH})
97     set(UBSAN_TEST_TARGET_ARCH ${arch})
98     get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
99     set(UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS} -lc++abi")
100   endforeach()
102   # Device and simulator test suites.
103   # These are not added into "check-all", in order to run these tests, use
104   # "check-asan-iossim-x86_64" and similar. They also require that an extra env
105   # variable to select which iOS device or simulator to use, e.g.:
106   # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
107   set(UBSAN_APPLE_PLATFORMS ${UBSAN_SUPPORTED_OS})
108   foreach(platform ${UBSAN_APPLE_PLATFORMS})
109     list_intersect(
110       UBSAN_TEST_${platform}_ARCHS
111       UBSAN_SUPPORTED_ARCH
112       DARWIN_${platform}_ARCHS
113       )
114     foreach(arch ${UBSAN_TEST_${platform}_ARCHS})
115       get_test_cflags_for_apple_platform(
116         "${platform}"
117         "${arch}"
118         UBSAN_TEST_TARGET_CFLAGS
119       )
120       add_ubsan_device_testsuite("Standalone" ubsan ${platform} ${arch})
122       if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
123         add_ubsan_device_testsuite("AddressSanitizer" asan ${platform} ${arch})
124       endif()
126       if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
127         add_ubsan_device_testsuite("ThreadSanitizer" tsan ${platform} ${arch})
128       endif()
129     endforeach()
130   endforeach()
131 endif()
133 add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests"
134   ${UBSAN_TESTSUITES}
135   DEPENDS ${UBSAN_TEST_DEPS})