1set(UBSAN_LIT_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
2
3set(UBSAN_TESTSUITES)
4foreach(arch ${UBSAN_SUPPORTED_ARCH})
5  set(UBSAN_TEST_TARGET_ARCH ${arch})
6  if(${arch} MATCHES "arm|aarch64")
7    # This is only true if we're cross-compiling.
8    set(UBSAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
9  else()
10    get_target_flags_for_arch(${arch} UBSAN_TEST_TARGET_CFLAGS)
11  endif()
12  set(UBSAN_LIT_TEST_MODE "Standalone")
13  set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${arch})
14  configure_lit_site_cfg(
15    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
16    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
17  list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
18
19  if(COMPILER_RT_HAS_ASAN)
20    set(UBSAN_LIT_TEST_MODE "AddressSanitizer")
21    set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${arch})
22    configure_lit_site_cfg(
23       ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
24       ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
25    list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
26  endif()
27endforeach()
28
29set(UBSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
30if(NOT COMPILER_RT_STANDALONE_BUILD)
31  list(APPEND UBSAN_TEST_DEPS ubsan asan)
32endif()
33
34add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests"
35  ${UBSAN_TESTSUITES}
36  DEPENDS ${UBSAN_TEST_DEPS})
37set_target_properties(check-ubsan PROPERTIES FOLDER "UBSan tests")
38