diff --git a/compiler-rt/test/msan/CMakeLists.txt b/compiler-rt/test/msan/CMakeLists.txt --- a/compiler-rt/test/msan/CMakeLists.txt +++ b/compiler-rt/test/msan/CMakeLists.txt @@ -8,7 +8,7 @@ darwin_filter_host_archs(MSAN_SUPPORTED_ARCH MSAN_TEST_ARCH) endif() -macro(add_msan_testsuite arch lld thinlto) +macro(add_msan_testsuite arch lld thinlto eager) set(MSAN_TEST_TARGET_ARCH ${arch}) get_test_cc_for_arch(${arch} MSAN_TEST_TARGET_CC MSAN_TEST_TARGET_CFLAGS) @@ -24,8 +24,12 @@ list(APPEND MSAN_TEST_DEPS lld) endif() endif() + if (${eager}) + set(CONFIG_NAME "eager-${CONFIG_NAME}") + endif() set(MSAN_TEST_USE_THINLTO ${thinlto}) set(MSAN_TEST_USE_LLD ${lld}) + set(MSAN_TEST_EAGER_CHECK ${eager}) configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in @@ -34,10 +38,11 @@ endmacro() foreach(arch ${MSAN_TEST_ARCH}) - add_msan_testsuite(${arch} False False) + add_msan_testsuite(${arch} False False False) + add_msan_testsuite(${arch} False False True) if(COMPILER_RT_HAS_LLD AND arch STREQUAL "x86_64" AND NOT (APPLE OR WIN32)) - add_msan_testsuite(${arch} True False) + add_msan_testsuite(${arch} True False False) endif() endforeach() diff --git a/compiler-rt/test/msan/chained_origin.cpp b/compiler-rt/test/msan/chained_origin.cpp --- a/compiler-rt/test/msan/chained_origin.cpp +++ b/compiler-rt/test/msan/chained_origin.cpp @@ -20,12 +20,12 @@ volatile int x, y; __attribute__((noinline)) -void fn_g(int a) { +void fn_g(volatile int &a) { x = a; } __attribute__((noinline)) -void fn_f(int a) { +void fn_f(volatile int &a) { fn_g(a); } diff --git a/compiler-rt/test/msan/chained_origin_empty_stack.cpp b/compiler-rt/test/msan/chained_origin_empty_stack.cpp --- a/compiler-rt/test/msan/chained_origin_empty_stack.cpp +++ b/compiler-rt/test/msan/chained_origin_empty_stack.cpp @@ -18,12 +18,12 @@ volatile int x; __attribute__((noinline)) -void fn_g(int a) { +void fn_g(volatile int &a) { x = a; } __attribute__((noinline)) -void fn_f(int a) { +void fn_f(volatile int &a) { fn_g(a); } diff --git a/compiler-rt/test/msan/chained_origin_memcpy.cpp b/compiler-rt/test/msan/chained_origin_memcpy.cpp --- a/compiler-rt/test/msan/chained_origin_memcpy.cpp +++ b/compiler-rt/test/msan/chained_origin_memcpy.cpp @@ -23,12 +23,12 @@ volatile int idx = 30; __attribute__((noinline)) -void fn_g(int a, int b) { +void fn_g(volatile int &a, volatile int &b) { xx[idx] = a; xx[idx + 10] = b; } __attribute__((noinline)) -void fn_f(int a, int b) { +void fn_f(volatile int &a, volatile int &b) { fn_g(a, b); } diff --git a/compiler-rt/test/msan/cxa_atexit.cpp b/compiler-rt/test/msan/cxa_atexit.cpp --- a/compiler-rt/test/msan/cxa_atexit.cpp +++ b/compiler-rt/test/msan/cxa_atexit.cpp @@ -1,4 +1,5 @@ // RUN: %clangxx_msan -O0 %s -o %t && %run %t %p +// REQUIRES: !msan_eager_checks // PR17377: C++ module destructors get stale argument shadow. diff --git a/compiler-rt/test/msan/insertvalue_origin.cpp b/compiler-rt/test/msan/insertvalue_origin.cpp --- a/compiler-rt/test/msan/insertvalue_origin.cpp +++ b/compiler-rt/test/msan/insertvalue_origin.cpp @@ -13,7 +13,7 @@ int y; }; -mypair my_make_pair(int64_t x, int y) { +mypair my_make_pair(const int64_t &x, const int &y) { mypair p; p.x = x; p.y = y; diff --git a/compiler-rt/test/msan/lit.site.cfg.py.in b/compiler-rt/test/msan/lit.site.cfg.py.in --- a/compiler-rt/test/msan/lit.site.cfg.py.in +++ b/compiler-rt/test/msan/lit.site.cfg.py.in @@ -7,6 +7,10 @@ config.use_lld = @MSAN_TEST_USE_LLD@ config.use_thinlto = @MSAN_TEST_USE_THINLTO@ +if @MSAN_TEST_EAGER_CHECK@: + config.target_cflags += " -mllvm -msan-eager-checks -DTEST_MSAN_EAGER_CHECKS" + config.available_features.add('msan_eager_checks') + # Load common config for all compiler-rt lit tests. lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") diff --git a/compiler-rt/test/msan/no_sanitize_memory_prop.cpp b/compiler-rt/test/msan/no_sanitize_memory_prop.cpp --- a/compiler-rt/test/msan/no_sanitize_memory_prop.cpp +++ b/compiler-rt/test/msan/no_sanitize_memory_prop.cpp @@ -11,7 +11,7 @@ __attribute__((noinline)) __attribute__((weak)) __attribute__((no_sanitize_memory)) -int f(int x) { +int f(int &x) { return x; } diff --git a/compiler-rt/test/msan/param_tls_limit.cpp b/compiler-rt/test/msan/param_tls_limit.cpp --- a/compiler-rt/test/msan/param_tls_limit.cpp +++ b/compiler-rt/test/msan/param_tls_limit.cpp @@ -4,6 +4,7 @@ // RUN: %clangxx_msan -O0 %s -o %t && %run %t // RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -o %t && %run %t // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O0 %s -o %t && %run %t +// REQUIRES: !msan_eager_checks // // AArch64 fails with: // void f801(S<801>): Assertion `__msan_test_shadow(&s, sizeof(s)) == -1' failed diff --git a/compiler-rt/test/msan/qsort.cpp b/compiler-rt/test/msan/qsort.cpp --- a/compiler-rt/test/msan/qsort.cpp +++ b/compiler-rt/test/msan/qsort.cpp @@ -19,8 +19,10 @@ void poison_stack_and_param() { char x[10000]; +#ifndef TEST_MSAN_EAGER_CHECKS int y; dummy(y, y, y, y, y); +#endif } __attribute__((always_inline)) int cmp(long a, long b) { diff --git a/compiler-rt/test/msan/signal_stress_test.cpp b/compiler-rt/test/msan/signal_stress_test.cpp --- a/compiler-rt/test/msan/signal_stress_test.cpp +++ b/compiler-rt/test/msan/signal_stress_test.cpp @@ -4,6 +4,7 @@ // Reported deadly signal due to stack-overflow // XFAIL: netbsd +// XFAIL: msan_eager_checks #include #include diff --git a/compiler-rt/test/msan/stack-origin2.cpp b/compiler-rt/test/msan/stack-origin2.cpp --- a/compiler-rt/test/msan/stack-origin2.cpp +++ b/compiler-rt/test/msan/stack-origin2.cpp @@ -18,6 +18,8 @@ // RUN: %clangxx_msan -fsanitize-memory-track-origins -O3 %s -o %t && not %run %t >%t.out 2>&1 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out +// REQUIRES: !msan_eager_checks + #include extern "C" diff --git a/compiler-rt/test/msan/unpoison_param.cpp b/compiler-rt/test/msan/unpoison_param.cpp --- a/compiler-rt/test/msan/unpoison_param.cpp +++ b/compiler-rt/test/msan/unpoison_param.cpp @@ -5,6 +5,7 @@ // RUN: %clangxx_msan -fno-sanitize=memory -c %s -o %t-main.o // RUN: %clangxx_msan %t-main.o %s -o %t // RUN: %run %t +// REQUIRES: !msan_eager_checks #include #include diff --git a/compiler-rt/test/msan/vararg.cpp b/compiler-rt/test/msan/vararg.cpp --- a/compiler-rt/test/msan/vararg.cpp +++ b/compiler-rt/test/msan/vararg.cpp @@ -1,16 +1,24 @@ -// RUN: %clangxx_msan -fsanitize-memory-track-origins=0 -O3 %s -o %t && \ +// RUN: %clangxx_msan -fsanitize-memory-track-origins=0 -DEXPECT_PASS -O3 %s -o %t && \ +// RUN: not %run %t va_arg_tls >%t.out 2>&1 +// RUN: not [ -s %t.out ] + +// RUN: %clangxx_msan -fsanitize-memory-track-origins=0 -DEXPECT_PASS -O3 %s -o %t && \ +// RUN: not %run %t overflow >%t.out 2>&1 +// RUN: not [ -s %t.out ] + +// RUN: %clangxx_msan -fsanitize-memory-track-origins=0 -DEXPECT_FAIL -O3 %s -o %t && \ // RUN: not %run %t va_arg_tls >%t.out 2>&1 // RUN: FileCheck %s --check-prefix=CHECK < %t.out -// RUN: %clangxx_msan -fsanitize-memory-track-origins=0 -O3 %s -o %t && \ +// RUN: %clangxx_msan -fsanitize-memory-track-origins=0 -DEXPECT_FAIL -O3 %s -o %t && \ // RUN: not %run %t overflow >%t.out 2>&1 // RUN: FileCheck %s --check-prefix=CHECK < %t.out -// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O3 %s -o %t && \ +// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -DEXPECT_FAIL -O3 %s -o %t && \ // RUN: not %run %t va_arg_tls >%t.out 2>&1 // RUN: FileCheck %s --check-prefixes=CHECK,CHECK-ORIGIN < %t.out -// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O3 %s -o %t && \ +// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -DEXPECT_FAIL -O3 %s -o %t && \ // RUN: not %run %t overflow >%t.out 2>&1 // RUN: FileCheck %s --check-prefixes=CHECK,CHECK-ORIGIN < %t.out @@ -24,6 +32,22 @@ #include #include +#include + +__attribute__((noinline)) +void dummy(long a, long b, long c, long d, long e) { + __asm__ __volatile__ (""::"r"(a), "r"(b), "r"(c), "r"(d), "r"(e)); +} + +__attribute__((noinline)) +void poison_stack_and_param() { + char x[10000]; +#ifndef TEST_MSAN_EAGER_CHECKS + int y; + dummy(y, y, y, y, y); +#endif +} + __attribute__((noinline)) int sum(int n, ...) { va_list args; @@ -39,15 +63,28 @@ } int main(int argc, char *argv[]) { +#if defined(EXPECT_FAIL) volatile int uninit; + #define PRE_RUN for (int i = 0; i < 6; i++) __msan_unpoison_param(i) + // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value + // CHECK-ORIGIN: Uninitialized value was created by an allocation of 'uninit' in the stack frame of function 'main' +#elif defined(EXPECT_PASS) + volatile int uninit = 0; + #define PRE_RUN poison_stack_and_param() +#else + #error Bad configuration +#endif + volatile int a = 1, b = 2; if (argc == 2) { // Shadow/origin will be passed via va_arg_tls/va_arg_origin_tls. if (strcmp(argv[1], "va_arg_tls") == 0) { + PRE_RUN; return sum(3, uninit, a, b); } // Shadow/origin of |uninit| will be passed via overflow area. if (strcmp(argv[1], "overflow") == 0) { + PRE_RUN; return sum(7, a, a, a, a, a, a, uninit ); @@ -55,6 +92,3 @@ } return 0; } - -// CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value -// CHECK-ORIGIN: Uninitialized value was created by an allocation of 'uninit' in the stack frame of function 'main' diff --git a/compiler-rt/test/msan/vector_cvt.cpp b/compiler-rt/test/msan/vector_cvt.cpp --- a/compiler-rt/test/msan/vector_cvt.cpp +++ b/compiler-rt/test/msan/vector_cvt.cpp @@ -4,7 +4,7 @@ #include -int to_int(double v) { +int to_int(double &v) { __m128d t = _mm_set_sd(v); int x = _mm_cvtsd_si32(t); return x;