diff options
Diffstat (limited to 'test/ubsan')
-rw-r--r-- | test/ubsan/CMakeLists.txt | 7 | ||||
-rw-r--r-- | test/ubsan/TestCases/Float/cast-overflow.cpp | 28 | ||||
-rw-r--r-- | test/ubsan/TestCases/Integer/summary.cpp | 7 | ||||
-rw-r--r-- | test/ubsan/TestCases/Integer/suppressions.cpp | 41 | ||||
-rw-r--r-- | test/ubsan/TestCases/Misc/Linux/ubsan_options.cc | 2 | ||||
-rw-r--r-- | test/ubsan/TestCases/Misc/bool.cpp | 7 | ||||
-rw-r--r-- | test/ubsan/TestCases/Misc/coverage-levels.cc (renamed from test/ubsan/TestCases/Misc/Linux/coverage-levels.cc) | 16 | ||||
-rw-r--r-- | test/ubsan/TestCases/Misc/log-path_test.cc | 7 | ||||
-rw-r--r-- | test/ubsan/TestCases/Misc/missing_return.cpp | 2 | ||||
-rw-r--r-- | test/ubsan/TestCases/Misc/nonnull-arg.cpp | 11 | ||||
-rw-r--r-- | test/ubsan/TestCases/TypeCheck/Function/function.cpp | 2 | ||||
-rw-r--r-- | test/ubsan/TestCases/TypeCheck/misaligned.cpp | 6 | ||||
-rw-r--r-- | test/ubsan/TestCases/TypeCheck/vptr.cpp | 33 | ||||
-rw-r--r-- | test/ubsan/lit.common.cfg | 19 |
14 files changed, 134 insertions, 54 deletions
diff --git a/test/ubsan/CMakeLists.txt b/test/ubsan/CMakeLists.txt index cd197c7aed46..0938ea2b1c0f 100644 --- a/test/ubsan/CMakeLists.txt +++ b/test/ubsan/CMakeLists.txt @@ -15,7 +15,12 @@ macro(add_ubsan_testsuite test_mode sanitizer arch) endif() endmacro() -foreach(arch ${UBSAN_SUPPORTED_ARCH}) +set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_ARCH}) +if(APPLE) + darwin_filter_host_archs(UBSAN_SUPPORTED_ARCH UBSAN_TEST_ARCH) +endif() + +foreach(arch ${UBSAN_TEST_ARCH}) set(UBSAN_TEST_TARGET_ARCH ${arch}) if(${arch} MATCHES "arm|aarch64") # This is only true if we're cross-compiling. diff --git a/test/ubsan/TestCases/Float/cast-overflow.cpp b/test/ubsan/TestCases/Float/cast-overflow.cpp index eda087442450..1551bf593df1 100644 --- a/test/ubsan/TestCases/Float/cast-overflow.cpp +++ b/test/ubsan/TestCases/Float/cast-overflow.cpp @@ -1,6 +1,6 @@ -// RUN: %clangxx -fsanitize=float-cast-overflow -g %s -o %t +// RUN: %clangxx -fsanitize=float-cast-overflow %s -o %t // RUN: %run %t _ -// RUN: env UBSAN_OPTIONS=print_summary=1 %run %t 0 2>&1 | FileCheck %s --check-prefix=CHECK-0 +// RUN: %env_ubsan_opts=print_summary=1:report_error_type=1 %run %t 0 2>&1 | FileCheck %s --check-prefix=CHECK-0 // RUN: %run %t 1 2>&1 | FileCheck %s --check-prefix=CHECK-1 // RUN: %run %t 2 2>&1 | FileCheck %s --check-prefix=CHECK-2 // RUN: %run %t 3 2>&1 | FileCheck %s --check-prefix=CHECK-3 @@ -86,47 +86,49 @@ int main(int argc, char **argv) { case '0': { // Note that values between 0x7ffffe00 and 0x80000000 may or may not // successfully round-trip, depending on the rounding mode. - // CHECK-0: runtime error: value 2.14748{{.*}} is outside the range of representable values of type 'int' + // CHECK-0: {{.*}}cast-overflow.cpp:[[@LINE+1]]:27: runtime error: value 2.14748{{.*}} is outside the range of representable values of type 'int' static int test_int = MaxFloatRepresentableAsInt + 0x80; - // CHECK-0: SUMMARY: {{.*}}Sanitizer: undefined-behavior {{.*}}cast-overflow.cpp:[[@LINE-1]] + // CHECK-0: SUMMARY: {{.*}}Sanitizer: float-cast-overflow {{.*}}cast-overflow.cpp:[[@LINE-1]] return 0; } case '1': { - // CHECK-1: runtime error: value -2.14748{{.*}} is outside the range of representable values of type 'int' + // CHECK-1: {{.*}}cast-overflow.cpp:[[@LINE+1]]:27: runtime error: value -2.14748{{.*}} is outside the range of representable values of type 'int' static int test_int = MinFloatRepresentableAsInt - 0x100; return 0; } case '2': { - // CHECK-2: runtime error: value -1 is outside the range of representable values of type 'unsigned int' + // CHECK-2: {{.*}}cast-overflow.cpp:[[@LINE+2]]:37: runtime error: value -1 is outside the range of representable values of type 'unsigned int' volatile float f = -1.0; volatile unsigned u = (unsigned)f; return 0; } case '3': { - // CHECK-3: runtime error: value 4.2949{{.*}} is outside the range of representable values of type 'unsigned int' + // CHECK-3: {{.*}}cast-overflow.cpp:[[@LINE+1]]:37: runtime error: value 4.2949{{.*}} is outside the range of representable values of type 'unsigned int' static int test_int = (unsigned)(MaxFloatRepresentableAsUInt + 0x100); return 0; } case '4': { - // CHECK-4: runtime error: value {{.*}} is outside the range of representable values of type 'int' + // CHECK-4: {{.*}}cast-overflow.cpp:[[@LINE+1]]:27: runtime error: value {{.*}} is outside the range of representable values of type 'int' static int test_int = Inf; return 0; } case '5': { - // CHECK-5: runtime error: value {{.*}} is outside the range of representable values of type 'int' + // CHECK-5: {{.*}}cast-overflow.cpp:[[@LINE+1]]:27: runtime error: value {{.*}} is outside the range of representable values of type 'int' static int test_int = NaN; return 0; } // Integer -> floating point overflow. case '6': { - // CHECK-6: {{runtime error: value 0xffffff00000000000000000000000001 is outside the range of representable values of type 'float'|__int128 not supported}} + // CHECK-6: cast-overflow.cpp:[[@LINE+2]]:{{34: runtime error: value 0xffffff00000000000000000000000001 is outside the range of representable values of type 'float'| __int128 not supported}} #if defined(__SIZEOF_INT128__) && !defined(_WIN32) static int test_int = (float)(FloatMaxAsUInt128 + 1); return 0; #else - puts("__int128 not supported"); + // Print the same line as the check above. That way the test is robust to + // line changes around it + printf("%s:%d: __int128 not supported", __FILE__, __LINE__ - 5); return 0; #endif } @@ -138,11 +140,11 @@ int main(int argc, char **argv) { // Floating point -> floating point overflow. case '8': - // CHECK-8: runtime error: value 1e+39 is outside the range of representable values of type 'float' + // CHECK-8: {{.*}}cast-overflow.cpp:[[@LINE+1]]:19: runtime error: value 1e+39 is outside the range of representable values of type 'float' return (float)1e39; case '9': volatile long double ld = 300.0; - // CHECK-9: runtime error: value 300 is outside the range of representable values of type 'char' + // CHECK-9: {{.*}}cast-overflow.cpp:[[@LINE+1]]:14: runtime error: value 300 is outside the range of representable values of type 'char' char c = ld; return c; } diff --git a/test/ubsan/TestCases/Integer/summary.cpp b/test/ubsan/TestCases/Integer/summary.cpp index 21f537b92767..e687afab4354 100644 --- a/test/ubsan/TestCases/Integer/summary.cpp +++ b/test/ubsan/TestCases/Integer/summary.cpp @@ -1,10 +1,13 @@ -// RUN: %clangxx -fsanitize=integer %s -o %t && %t 2>&1 | FileCheck %s +// RUN: %clangxx -fsanitize=integer %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE +// RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE // REQUIRES: ubsan-asan #include <stdint.h> int main() { (void)(uint64_t(10000000000000000000ull) + uint64_t(9000000000000000000ull)); - // CHECK: SUMMARY: AddressSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:44 + // CHECK-NOTYPE: SUMMARY: AddressSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:44 + // CHECK-TYPE: SUMMARY: AddressSanitizer: unsigned-integer-overflow {{.*}}summary.cpp:[[@LINE-2]]:44 return 0; } diff --git a/test/ubsan/TestCases/Integer/suppressions.cpp b/test/ubsan/TestCases/Integer/suppressions.cpp new file mode 100644 index 000000000000..e2f632d0725c --- /dev/null +++ b/test/ubsan/TestCases/Integer/suppressions.cpp @@ -0,0 +1,41 @@ +// XFAIL: win32 +// On Windows, %t starts with c:\. lit's ShLexer helpfully strips the +// quotes in the suppressions="%t..." lines below, so the UBSAN_OPTIONS +// env var that ubsan effectively sees is halt_on_error=1:suppressions=c:\... +// without any quotes. Since : is ubsan's UBSAN_OPTIONS separator, this +// confuses sanitizer_flag_parser. +// FIXME: Figure out how to make this test go on Windows. + +// RUN: %clangxx -fsanitize=integer -g0 %s -o %t + +// Fails without any suppression. +// RUN: %env_ubsan_opts=halt_on_error=1 not %run %t 2>&1 | FileCheck %s + +// RUN: echo "signed-integer-overflow:%t" > %t.wrong-supp +// RUN: %env_ubsan_opts=halt_on_error=1:suppressions="%t.wrong-supp" not %run %t 2>&1 | FileCheck %s + +// RUN: echo "unsigned-integer-overflow:do_overflow" > %t.func-supp +// RUN: %env_ubsan_opts=halt_on_error=1:suppressions="%t.func-supp" %run %t +// RUN: echo "unsigned-integer-overflow:%t" > %t.module-supp +// RUN: %env_ubsan_opts=halt_on_error=1:suppressions="%t.module-supp" %run %t + +// Note: file-level suppressions should work even without debug info. +// RUN: echo "unsigned-integer-overflow:%s" > %t.file-supp +// RUN: %env_ubsan_opts=halt_on_error=1:suppressions="%t.file-supp" %run %t + +// Suppressions don't work for unrecoverable kinds. +// RUN: %clangxx -fsanitize=integer -fno-sanitize-recover=integer %s -o %t-norecover +// RUN: %env_ubsan_opts=halt_on_error=1:suppressions="%t.module-supp" not %run %t-norecover 2>&1 | FileCheck %s + +#include <stdint.h> + +extern "C" void do_overflow() { + (void)(uint64_t(10000000000000000000ull) + uint64_t(9000000000000000000ull)); + // CHECK: runtime error: unsigned integer overflow +} + +int main() { + do_overflow(); + return 0; +} + diff --git a/test/ubsan/TestCases/Misc/Linux/ubsan_options.cc b/test/ubsan/TestCases/Misc/Linux/ubsan_options.cc index 2be8792cce96..eac4c32a2839 100644 --- a/test/ubsan/TestCases/Misc/Linux/ubsan_options.cc +++ b/test/ubsan/TestCases/Misc/Linux/ubsan_options.cc @@ -1,5 +1,5 @@ // RUN: %clangxx -fsanitize=integer -fsanitize-recover=integer %s -o %t -// RUN: not %t 2>&1 | FileCheck %s +// RUN: not %run %t 2>&1 | FileCheck %s // __ubsan_default_options() doesn't work on Darwin. // XFAIL: darwin diff --git a/test/ubsan/TestCases/Misc/bool.cpp b/test/ubsan/TestCases/Misc/bool.cpp index 37ecea27c941..f6dc24e4bc78 100644 --- a/test/ubsan/TestCases/Misc/bool.cpp +++ b/test/ubsan/TestCases/Misc/bool.cpp @@ -1,10 +1,13 @@ -// RUN: %clangxx -fsanitize=bool %s -O3 -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx -fsanitize=bool %s -O3 -o %t +// RUN: not %run %t 2>&1 | FileCheck %s +// RUN: %env_ubsan_opts=print_summary=1:report_error_type=1 not %run %t 2>&1 | FileCheck %s --check-prefix=SUMMARY unsigned char NotABool = 123; int main(int argc, char **argv) { bool *p = (bool*)&NotABool; - // CHECK: bool.cpp:9:10: runtime error: load of value 123, which is not a valid value for type 'bool' + // CHECK: bool.cpp:[[@LINE+1]]:10: runtime error: load of value 123, which is not a valid value for type 'bool' return *p; + // SUMMARY: SUMMARY: {{.*}}Sanitizer: invalid-bool-load {{.*}}bool.cpp:[[@LINE-1]] } diff --git a/test/ubsan/TestCases/Misc/Linux/coverage-levels.cc b/test/ubsan/TestCases/Misc/coverage-levels.cc index df6e835dd9df..046d8868e4d7 100644 --- a/test/ubsan/TestCases/Misc/Linux/coverage-levels.cc +++ b/test/ubsan/TestCases/Misc/coverage-levels.cc @@ -1,18 +1,20 @@ // Test various levels of coverage // +// FIXME: Port the environment variable logic below for the lit shell. +// REQUIRES: shell +// // RUN: mkdir -p %T/coverage-levels -// RUN: OPT=coverage=1:verbosity=1:coverage_dir=%T/coverage-levels // RUN: %clangxx -fsanitize=shift -DGOOD_SHIFT=1 -O1 -fsanitize-coverage=func %s -o %t -// RUN: UBSAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN +// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir=%T/coverage-levels %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN // RUN: %clangxx -fsanitize=undefined -DGOOD_SHIFT=1 -O1 -fsanitize-coverage=func %s -o %t -// RUN: UBSAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN +// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir=%T/coverage-levels %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN // RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=func %s -o %t -// RUN: UBSAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_WARN +// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir=%T/coverage-levels %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_WARN // RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=bb %s -o %t -// RUN: UBSAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2 --check-prefix=CHECK_WARN +// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir=%T/coverage-levels %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2 --check-prefix=CHECK_WARN // RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=edge %s -o %t -// RUN: UBSAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3 --check-prefix=CHECK_WARN +// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir=%T/coverage-levels %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3 --check-prefix=CHECK_WARN // Coverage is not yet implemented in TSan. // XFAIL: ubsan-tsan @@ -36,4 +38,4 @@ int main(int argc, char **argv) { // to dump coverage. // CHECK1: 1 PCs written // CHECK2: 3 PCs written -// CHECK3: 4 PCs written +// CHECK3: 3 PCs written diff --git a/test/ubsan/TestCases/Misc/log-path_test.cc b/test/ubsan/TestCases/Misc/log-path_test.cc index b39e1b077e27..5b45f0b6f847 100644 --- a/test/ubsan/TestCases/Misc/log-path_test.cc +++ b/test/ubsan/TestCases/Misc/log-path_test.cc @@ -1,6 +1,9 @@ // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 // XFAIL: android +// The globs below do not work in the lit shell. +// REQUIRES: shell + // RUN: %clangxx -fsanitize=undefined %s -O1 -o %t // Regular run. @@ -9,12 +12,12 @@ // Good log_path. // RUN: rm -f %t.log.* -// RUN: env UBSAN_OPTIONS=log_path=%t.log %run %t -4 2> %t.out +// RUN: %env_ubsan_opts=log_path='"%t.log"' %run %t -4 2> %t.out // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.* // Run w/o errors should not produce any log. // RUN: rm -f %t.log.* -// RUN: env UBSAN_OPTIONS=log_path=%t.log %run %t 4 +// RUN: %env_ubsan_opts=log_path='"%t.log"' %run %t 4 // RUN: not cat %t.log.* // FIXME: log_path is not supported on Windows yet. diff --git a/test/ubsan/TestCases/Misc/missing_return.cpp b/test/ubsan/TestCases/Misc/missing_return.cpp index 75e26df536a6..68082272d62c 100644 --- a/test/ubsan/TestCases/Misc/missing_return.cpp +++ b/test/ubsan/TestCases/Misc/missing_return.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx -fsanitize=return -g %s -O3 -o %t // RUN: not %run %t 2>&1 | FileCheck %s -// RUN: env UBSAN_OPTIONS=print_stacktrace=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%os-STACKTRACE +// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%os-STACKTRACE // CHECK: missing_return.cpp:[[@LINE+1]]:5: runtime error: execution reached the end of a value-returning function without returning a value int f() { diff --git a/test/ubsan/TestCases/Misc/nonnull-arg.cpp b/test/ubsan/TestCases/Misc/nonnull-arg.cpp index 084dedc27b85..0332d96c0213 100644 --- a/test/ubsan/TestCases/Misc/nonnull-arg.cpp +++ b/test/ubsan/TestCases/Misc/nonnull-arg.cpp @@ -7,6 +7,9 @@ // RUN: not %run %t 0m 2>&1 | FileCheck %s --check-prefix=METHOD // RUN: not %run %t 0f 2>&1 | FileCheck %s --check-prefix=FUNC // RUN: not %run %t 0v 2>&1 | FileCheck %s --check-prefix=VARIADIC +// +// AArch64 lacks variadic instrumentation for MSAN. +// REQUIRES: stable-runtime class C { int *null_; @@ -40,19 +43,19 @@ int main(int argc, char *argv[]) { case 'c': return C(0x0, arg).value(); // CTOR: {{.*}}nonnull-arg.cpp:[[@LINE-1]]:21: runtime error: null pointer passed as argument 2, which is declared to never be null - // CTOR-NEXT: {{.*}}nonnull-arg.cpp:16:31: note: nonnull attribute specified here + // CTOR-NEXT: {{.*}}nonnull-arg.cpp:19:31: note: nonnull attribute specified here case 'm': return C(0x0, &local).method(arg, 0x0); // METHOD: {{.*}}nonnull-arg.cpp:[[@LINE-1]]:36: runtime error: null pointer passed as argument 1, which is declared to never be null - // METHOD-NEXT: {{.*}}nonnull-arg.cpp:19:54: note: nonnull attribute specified here + // METHOD-NEXT: {{.*}}nonnull-arg.cpp:22:54: note: nonnull attribute specified here case 'f': return func(arg); // FUNC: {{.*}}nonnull-arg.cpp:[[@LINE-1]]:19: runtime error: null pointer passed as argument 1, which is declared to never be null - // FUNC-NEXT: {{.*}}nonnull-arg.cpp:24:16: note: nonnull attribute specified here + // FUNC-NEXT: {{.*}}nonnull-arg.cpp:27:16: note: nonnull attribute specified here case 'v': return variadic(42, arg); // VARIADIC: {{.*}}nonnull-arg.cpp:[[@LINE-1]]:27: runtime error: null pointer passed as argument 2, which is declared to never be null - // VARIADIC-NEXT: {{.*}}nonnull-arg.cpp:27:16: note: nonnull attribute specified here + // VARIADIC-NEXT: {{.*}}nonnull-arg.cpp:30:16: note: nonnull attribute specified here } return 0; } diff --git a/test/ubsan/TestCases/TypeCheck/Function/function.cpp b/test/ubsan/TestCases/TypeCheck/Function/function.cpp index 5a2fda4c9d46..6e7e314bf7e2 100644 --- a/test/ubsan/TestCases/TypeCheck/Function/function.cpp +++ b/test/ubsan/TestCases/TypeCheck/Function/function.cpp @@ -1,7 +1,7 @@ // RUN: %clangxx -fsanitize=function %s -O3 -g -o %t // RUN: %run %t 2>&1 | FileCheck %s // Verify that we can disable symbolization if needed: -// RUN: UBSAN_OPTIONS=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM +// RUN: %env_ubsan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM // -fsanitize=function is unsupported on Darwin yet. // XFAIL: darwin diff --git a/test/ubsan/TestCases/TypeCheck/misaligned.cpp b/test/ubsan/TestCases/TypeCheck/misaligned.cpp index 1b0abad747bc..43071672e457 100644 --- a/test/ubsan/TestCases/TypeCheck/misaligned.cpp +++ b/test/ubsan/TestCases/TypeCheck/misaligned.cpp @@ -1,3 +1,7 @@ +// FIXME: This test currently fails on Windows because we use the MSVC linker, +// which throws away DWARF debug info. +// XFAIL: win32 +// // RUN: %clangxx -fsanitize=alignment -g %s -O3 -o %t // RUN: %run %t l0 && %run %t s0 && %run %t r0 && %run %t m0 && %run %t f0 && %run %t n0 && %run %t u0 // RUN: %run %t l1 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD --strict-whitespace @@ -7,7 +11,7 @@ // RUN: %run %t f1 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN // RUN: %run %t n1 2>&1 | FileCheck %s --check-prefix=CHECK-NEW // RUN: %run %t u1 2>&1 | FileCheck %s --check-prefix=CHECK-UPCAST -// RUN: env UBSAN_OPTIONS=print_stacktrace=1 %run %t l1 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD --check-prefix=CHECK-%os-STACK-LOAD +// RUN: %env_ubsan_opts=print_stacktrace=1 %run %t l1 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD --check-prefix=CHECK-%os-STACK-LOAD // RUN: %clangxx -fsanitize=alignment -fno-sanitize-recover=alignment %s -O3 -o %t // RUN: not %run %t w1 2>&1 | FileCheck %s --check-prefix=CHECK-WILD diff --git a/test/ubsan/TestCases/TypeCheck/vptr.cpp b/test/ubsan/TestCases/TypeCheck/vptr.cpp index a95edf918c95..4a1fa8d54b18 100644 --- a/test/ubsan/TestCases/TypeCheck/vptr.cpp +++ b/test/ubsan/TestCases/TypeCheck/vptr.cpp @@ -1,28 +1,27 @@ // RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr -g %s -O3 -o %t -// RUN: export UBSAN_OPTIONS=print_stacktrace=1 // RUN: %run %t rT && %run %t mT && %run %t fT && %run %t cT // RUN: %run %t rU && %run %t mU && %run %t fU && %run %t cU // RUN: %run %t rS && %run %t rV && %run %t oV -// RUN: not %run %t mS 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER --check-prefix=CHECK-%os-MEMBER --strict-whitespace -// RUN: not %run %t fS 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN --strict-whitespace -// RUN: not %run %t cS 2>&1 | FileCheck %s --check-prefix=CHECK-DOWNCAST --check-prefix=CHECK-%os-DOWNCAST --strict-whitespace -// RUN: not %run %t mV 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER --check-prefix=CHECK-%os-MEMBER --strict-whitespace -// RUN: not %run %t fV 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN --strict-whitespace -// RUN: not %run %t cV 2>&1 | FileCheck %s --check-prefix=CHECK-DOWNCAST --check-prefix=CHECK-%os-DOWNCAST --strict-whitespace -// RUN: not %run %t oU 2>&1 | FileCheck %s --check-prefix=CHECK-OFFSET --check-prefix=CHECK-%os-OFFSET --strict-whitespace -// RUN: not %run %t m0 2>&1 | FileCheck %s --check-prefix=CHECK-NULL-MEMBER --check-prefix=CHECK-%os-NULL-MEMBER --strict-whitespace +// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t mS 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER --check-prefix=CHECK-%os-MEMBER --strict-whitespace +// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t fS 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN --strict-whitespace +// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t cS 2>&1 | FileCheck %s --check-prefix=CHECK-DOWNCAST --check-prefix=CHECK-%os-DOWNCAST --strict-whitespace +// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t mV 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER --check-prefix=CHECK-%os-MEMBER --strict-whitespace +// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t fV 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN --strict-whitespace +// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t cV 2>&1 | FileCheck %s --check-prefix=CHECK-DOWNCAST --check-prefix=CHECK-%os-DOWNCAST --strict-whitespace +// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t oU 2>&1 | FileCheck %s --check-prefix=CHECK-OFFSET --check-prefix=CHECK-%os-OFFSET --strict-whitespace +// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t m0 2>&1 | FileCheck %s --check-prefix=CHECK-NULL-MEMBER --check-prefix=CHECK-%os-NULL-MEMBER --strict-whitespace // RUN: (echo "vptr_check:S"; echo "vptr_check:T"; echo "vptr_check:U") > %t.supp -// RUN: UBSAN_OPTIONS="suppressions='%t.supp'" %run %t mS -// RUN: UBSAN_OPTIONS="suppressions='%t.supp'" %run %t fS -// RUN: UBSAN_OPTIONS="suppressions='%t.supp'" %run %t cS -// RUN: UBSAN_OPTIONS="suppressions='%t.supp'" %run %t mV -// RUN: UBSAN_OPTIONS="suppressions='%t.supp'" %run %t fV -// RUN: UBSAN_OPTIONS="suppressions='%t.supp'" %run %t cV -// RUN: UBSAN_OPTIONS="suppressions='%t.supp'" %run %t oU +// RUN: %env_ubsan_opts=suppressions='"%t.supp"' %run %t mS +// RUN: %env_ubsan_opts=suppressions='"%t.supp"' %run %t fS +// RUN: %env_ubsan_opts=suppressions='"%t.supp"' %run %t cS +// RUN: %env_ubsan_opts=suppressions='"%t.supp"' %run %t mV +// RUN: %env_ubsan_opts=suppressions='"%t.supp"' %run %t fV +// RUN: %env_ubsan_opts=suppressions='"%t.supp"' %run %t cV +// RUN: %env_ubsan_opts=suppressions='"%t.supp"' %run %t oU // RUN: echo "vptr_check:S" > %t.loc-supp -// RUN: UBSAN_OPTIONS="suppressions='%t.loc-supp'" not %run %t x- 2>&1 | FileCheck %s --check-prefix=CHECK-LOC-SUPPRESS +// RUN: %env_ubsan_opts=suppressions='"%t.loc-supp"' not %run %t x- 2>&1 | FileCheck %s --check-prefix=CHECK-LOC-SUPPRESS // REQUIRES: stable-runtime, cxxabi #include <new> diff --git a/test/ubsan/lit.common.cfg b/test/ubsan/lit.common.cfg index 7ae078a8625c..e50862983d62 100644 --- a/test/ubsan/lit.common.cfg +++ b/test/ubsan/lit.common.cfg @@ -14,6 +14,7 @@ def get_required_attr(config, attr_name): # Setup source root. config.test_source_root = os.path.dirname(__file__) +default_ubsan_opts = [] # 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": @@ -24,7 +25,7 @@ elif ubsan_lit_test_mode == "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' + default_ubsan_opts += ['detect_leaks=0'] elif ubsan_lit_test_mode == "MemorySanitizer": config.name = 'UBSan-MSan-' + config.target_arch config.available_features.add("ubsan-msan") @@ -36,6 +37,20 @@ elif ubsan_lit_test_mode == "ThreadSanitizer": else: lit_config.fatal("Unknown UBSan test mode: %r" % ubsan_lit_test_mode) +# Platform-specific default for lit tests. +if config.host_os == 'Darwin': + # On Darwin, we default to `abort_on_error=1`, which would make tests run + # much slower. Let's override this and run lit tests with 'abort_on_error=0'. + default_ubsan_opts += ['abort_on_error=0'] + default_ubsan_opts += ['log_to_syslog=0'] +default_ubsan_opts_str = ':'.join(default_ubsan_opts) +if default_ubsan_opts_str: + config.environment['UBSAN_OPTIONS'] = default_ubsan_opts_str + default_ubsan_opts_str += ':' +# Substitution to setup UBSAN_OPTIONS in portable way. +config.substitutions.append(('%env_ubsan_opts=', + 'env UBSAN_OPTIONS=' + default_ubsan_opts_str)) + def build_invocation(compile_flags): return " " + " ".join([config.clang] + compile_flags) + " " @@ -61,5 +76,5 @@ if config.host_os == 'Windows': # Allow tests to use REQUIRES=stable-runtime. For use when you cannot use XFAIL # because the test hangs or fails on one configuration and not the other. -if config.target_arch.startswith('arm') == False: +if config.target_arch.startswith('arm') == False and config.target_arch != 'aarch64': config.available_features.add('stable-runtime') |