1 set(UBSAN_LIT_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
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})
10 set(CONFIG_NAME ${CONFIG_NAME}-lld)
11 if ("lld" IN_LIST LLVM_ENABLE_PROJECTS)
12 list(APPEND UBSAN_TEST_DEPS lld)
16 set(CONFIG_NAME ${CONFIG_NAME}-thinlto)
17 list(APPEND UBSAN_TEST_DEPS LTO)
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})
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)
37 set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_ARCH})
39 darwin_filter_host_archs(UBSAN_SUPPORTED_ARCH UBSAN_TEST_ARCH)
42 foreach(arch ${UBSAN_TEST_ARCH})
43 set(UBSAN_TEST_TARGET_ARCH ${arch})
45 set(UBSAN_TEST_APPLE_PLATFORM "osx")
46 set(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_osx_MIN_VER_FLAG}")
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})
61 if(COMPILER_RT_HAS_MSAN AND ";${MSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
62 add_ubsan_testsuites("MemorySanitizer" msan ${arch})
64 if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};" AND NOT ANDROID)
65 add_ubsan_testsuites("ThreadSanitizer" tsan ${arch})
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")
77 set(UBSAN_TEST_APPLE_PLATFORM "${platform}")
78 set(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_${platform}_MIN_VER_FLAG}")
80 unset(UBSAN_TEST_APPLE_PLATFORM)
81 unset(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG)
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})
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")
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})
110 UBSAN_TEST_${platform}_ARCHS
112 DARWIN_${platform}_ARCHS
114 foreach(arch ${UBSAN_TEST_${platform}_ARCHS})
115 get_test_cflags_for_apple_platform(
118 UBSAN_TEST_TARGET_CFLAGS
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})
126 if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
127 add_ubsan_device_testsuite("ThreadSanitizer" tsan ${platform} ${arch})
133 add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests"
135 DEPENDS ${UBSAN_TEST_DEPS})