set(UBSAN_LIT_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
-set(UBSAN_LIT_TEST_MODE "Standalone")
-configure_lit_site_cfg(
- ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
- ${CMAKE_CURRENT_BINARY_DIR}/UbsanConfig/lit.site.cfg)
-set(UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/UbsanConfig)
-
-if(COMPILER_RT_HAS_ASAN)
- set(UBSAN_LIT_TEST_MODE "AddressSanitizer")
+set(UBSAN_TESTSUITES)
+foreach(arch ${UBSAN_SUPPORTED_ARCH})
+ set(UBSAN_TEST_TARGET_ARCH ${arch})
+ if(${arch} MATCHES "arm|aarch64")
+ # This is only true if we're cross-compiling.
+ set(UBSAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
+ else()
+ get_target_flags_for_arch(${arch} UBSAN_TEST_TARGET_CFLAGS)
+ endif()
+ set(UBSAN_LIT_TEST_MODE "Standalone")
+ set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${arch})
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
- ${CMAKE_CURRENT_BINARY_DIR}/AsanConfig/lit.site.cfg)
- list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/AsanConfig)
-endif()
+ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
+ list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+
+ if(COMPILER_RT_HAS_ASAN)
+ set(UBSAN_LIT_TEST_MODE "AddressSanitizer")
+ set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${arch})
+ configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
+ list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+ endif()
+endforeach()
set(UBSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
if(NOT COMPILER_RT_STANDALONE_BUILD)
add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests"
${UBSAN_TESTSUITES}
DEPENDS ${UBSAN_TEST_DEPS})
-set_target_properties(check-ubsan PROPERTIES FOLDER "UBSan unittests")
+set_target_properties(check-ubsan PROPERTIES FOLDER "UBSan tests")
// FIXME: This test produces linker errors on Darwin.
// XFAIL: darwin
// REQUIRES: stable-runtime
+#include <new>
extern "C" {
const char *__ubsan_default_options() {
(void)((T&)u).S::v();
char Buffer[sizeof(U)] = {};
+ char TStorage[sizeof(T)];
switch (argv[1][1]) {
case '0':
p = reinterpret_cast<T*>(Buffer);
break;
case 'S':
- p = reinterpret_cast<T*>(new S);
+ // Make sure p points to the memory chunk of sufficient size to prevent ASan
+ // reports about out-of-bounds access.
+ p = reinterpret_cast<T*>(new(TStorage) S);
break;
case 'T':
p = new T;
# Choose between standalone and UBSan+ASan modes.
ubsan_lit_test_mode = get_required_attr(config, 'ubsan_lit_test_mode')
if ubsan_lit_test_mode == "Standalone":
- config.name = 'UndefinedBehaviorSanitizer-Standalone'
+ config.name = 'UBSan-Standalone-' + config.target_arch
config.available_features.add("ubsan-standalone")
clang_ubsan_cflags = []
elif ubsan_lit_test_mode == "AddressSanitizer":
# ubsan-asan doesn't yet work on Darwin,
# see http://llvm.org/bugs/show_bug.cgi?id=21112.
config.unsupported = True
- config.name = 'UndefinedBehaviorSanitizer-AddressSanitizer'
+ config.name = 'UBSan-ASan-' + config.target_arch
config.available_features.add("ubsan-asan")
clang_ubsan_cflags = ["-fsanitize=address"]
config.environment['ASAN_OPTIONS'] = 'detect_leaks=0'
# Tool-specific config options.
config.ubsan_lit_test_mode = "@UBSAN_LIT_TEST_MODE@"
+config.target_cflags = "@UBSAN_TEST_TARGET_CFLAGS@"
+config.target_arch = "@UBSAN_TEST_TARGET_ARCH@"
# Load tool-specific config that would do the real work.
lit_config.load_config(config, "@UBSAN_LIT_TESTS_DIR@/lit.common.cfg")