diff options
-rw-r--r-- | compiler-rt/test/ubsan/CMakeLists.txt | 36 | ||||
-rw-r--r-- | compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp | 6 | ||||
-rw-r--r-- | compiler-rt/test/ubsan/lit.common.cfg | 4 | ||||
-rw-r--r-- | compiler-rt/test/ubsan/lit.site.cfg.in | 2 |
4 files changed, 33 insertions, 15 deletions
diff --git a/compiler-rt/test/ubsan/CMakeLists.txt b/compiler-rt/test/ubsan/CMakeLists.txt index 1c0c9290329..760ce60cc2b 100644 --- a/compiler-rt/test/ubsan/CMakeLists.txt +++ b/compiler-rt/test/ubsan/CMakeLists.txt @@ -1,18 +1,30 @@ 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) @@ -22,4 +34,4 @@ endif() 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") diff --git a/compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp b/compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp index 1f8ee02641a..a0681fc04ed 100644 --- a/compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp +++ b/compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp @@ -26,6 +26,7 @@ // FIXME: This test produces linker errors on Darwin. // XFAIL: darwin // REQUIRES: stable-runtime +#include <new> extern "C" { const char *__ubsan_default_options() { @@ -76,12 +77,15 @@ int main(int, char **argv) { (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; diff --git a/compiler-rt/test/ubsan/lit.common.cfg b/compiler-rt/test/ubsan/lit.common.cfg index d28733a61cf..5a406eed943 100644 --- a/compiler-rt/test/ubsan/lit.common.cfg +++ b/compiler-rt/test/ubsan/lit.common.cfg @@ -17,7 +17,7 @@ config.test_source_root = os.path.dirname(__file__) # 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": @@ -25,7 +25,7 @@ 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' diff --git a/compiler-rt/test/ubsan/lit.site.cfg.in b/compiler-rt/test/ubsan/lit.site.cfg.in index ef72d2bbb42..1b06881b352 100644 --- a/compiler-rt/test/ubsan/lit.site.cfg.in +++ b/compiler-rt/test/ubsan/lit.site.cfg.in @@ -3,6 +3,8 @@ lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configu # 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") |