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 if(NOT COMPILER_RT_STANDALONE_BUILD)
27 list(APPEND UBSAN_TEST_DEPS ${sanitizer})
31 macro(add_ubsan_testsuites test_mode sanitizer arch)
32 add_ubsan_testsuite(${test_mode} ${sanitizer} ${arch} False False)
34 if(COMPILER_RT_HAS_LLD AND arch STREQUAL "x86_64" AND NOT (APPLE OR WIN32))
35 add_ubsan_testsuite(${test_mode} ${sanitizer} ${arch} True False)
39 set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_ARCH})
41 darwin_filter_host_archs(UBSAN_SUPPORTED_ARCH UBSAN_TEST_ARCH)
44 foreach(arch ${UBSAN_TEST_ARCH})
45 set(UBSAN_TEST_TARGET_ARCH ${arch})
47 set(UBSAN_TEST_APPLE_PLATFORM "osx")
48 set(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_osx_MIN_VER_FLAG}")
50 get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
51 add_ubsan_testsuites("Standalone" ubsan ${arch})
53 if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
54 # TODO(wwchrome): Re-enable ubsan for asan win 64-bit when ready.
55 # Disable ubsan with AddressSanitizer tests for Windows 64-bit,
56 # 64-bit Solaris/x86, and SPARC.
57 if((NOT (OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)) AND
58 (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)) AND
59 (NOT ${arch} MATCHES sparc))
60 add_ubsan_testsuites("AddressSanitizer" asan ${arch})
63 if(COMPILER_RT_HAS_MSAN AND ";${MSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
64 add_ubsan_testsuites("MemorySanitizer" msan ${arch})
66 if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};" AND NOT ANDROID)
67 add_ubsan_testsuites("ThreadSanitizer" tsan ${arch})
71 macro(add_ubsan_device_testsuite test_mode sanitizer platform arch)
72 # Note we expect the caller to have already set UBSAN_TEST_TARGET_CFLAGS
73 set(UBSAN_LIT_TEST_MODE "${test_mode}")
74 set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${platform}-${arch})
75 set(UBSAN_TEST_TARGET_ARCH ${arch})
76 set(UBSAN_TEST_USE_LLD "False")
77 set(UBSAN_TEST_USE_THINLTO "False")
79 set(UBSAN_TEST_APPLE_PLATFORM "${platform}")
80 set(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_${platform}_MIN_VER_FLAG}")
82 unset(UBSAN_TEST_APPLE_PLATFORM)
83 unset(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG)
85 configure_lit_site_cfg(
86 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
87 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
88 #list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
89 list(APPEND UBSAN_TEST_DEPS ${sanitizer})
90 add_lit_testsuite(check-ubsan-${test_mode}-${platform}-${arch}
91 "UBSan ${CONFIG_NAME} tests"
92 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
93 EXCLUDE_FROM_CHECK_ALL
94 DEPENDS ${UBSAN_TEST_DEPS})
98 foreach(arch ${UBSAN_TEST_ARCH})
99 set(UBSAN_TEST_TARGET_ARCH ${arch})
100 get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
101 set(UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS} -lc++abi")
104 # Device and simulator test suites.
105 # These are not added into "check-all", in order to run these tests, use
106 # "check-asan-iossim-x86_64" and similar. They also require that an extra env
107 # variable to select which iOS device or simulator to use, e.g.:
108 # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
109 set(UBSAN_APPLE_PLATFORMS ${UBSAN_SUPPORTED_OS})
110 foreach(platform ${UBSAN_APPLE_PLATFORMS})
112 UBSAN_TEST_${platform}_ARCHS
114 DARWIN_${platform}_ARCHS
116 foreach(arch ${UBSAN_TEST_${platform}_ARCHS})
117 get_test_cflags_for_apple_platform(
120 UBSAN_TEST_TARGET_CFLAGS
122 add_ubsan_device_testsuite("Standalone" ubsan ${platform} ${arch})
124 if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
125 add_ubsan_device_testsuite("AddressSanitizer" asan ${platform} ${arch})
128 if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
129 add_ubsan_device_testsuite("ThreadSanitizer" tsan ${platform} ${arch})
135 add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests"
137 DEPENDS ${UBSAN_TEST_DEPS})
138 set_target_properties(check-ubsan PROPERTIES FOLDER "Compiler-RT Misc")