[UBSan] Run all UBSan tests in 32-bit mode as well.

We build and support UBSan on 32-bit platforms. We should run tests
there as well. Fixes PR22683.

llvm-svn: 230662
This commit is contained in:
Alexey Samsonov 2015-02-26 19:19:44 +00:00
parent b523deaa38
commit 1c915782b9
4 changed files with 33 additions and 15 deletions

View File

@ -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")

View File

@ -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;

View File

@ -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'

View File

@ -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")