Index: lib/ubsan/ubsan_diag.h =================================================================== --- lib/ubsan/ubsan_diag.h +++ lib/ubsan/ubsan_diag.h @@ -244,6 +244,7 @@ ~ScopedReport(); }; +bool HasReportedErrors(); void InitializeSuppressions(); bool IsVptrCheckSuppressed(const char *TypeName); // Sometimes UBSan runtime can know filename from handlers arguments, even if Index: lib/ubsan/ubsan_diag.cc =================================================================== --- lib/ubsan/ubsan_diag.cc +++ lib/ubsan/ubsan_diag.cc @@ -363,11 +363,16 @@ PrintMemorySnippet(Decor, Loc.getMemoryLocation(), Ranges, NumRanges, Args); } +static bool ReportedErrors = false; + +bool __ubsan::HasReportedErrors() { return ReportedErrors; } + ScopedReport::ScopedReport(ReportOptions Opts, Location SummaryLoc, ErrorType Type) : Opts(Opts), SummaryLoc(SummaryLoc), Type(Type) { InitAsStandaloneIfNecessary(); CommonSanitizerReportMutex.Lock(); + ReportedErrors = true; } ScopedReport::~ScopedReport() { Index: lib/ubsan/ubsan_init.cc =================================================================== --- lib/ubsan/ubsan_init.cc +++ lib/ubsan/ubsan_init.cc @@ -34,8 +34,14 @@ } ubsan_mode; static StaticSpinMutex ubsan_init_mu; +static void ReportFailure() { + if (HasReportedErrors() && common_flags()->exitcode) + Die(); +} + static void CommonInit() { InitializeSuppressions(); + Atexit(ReportFailure); } static void CommonStandaloneInit() { Index: test/ubsan/TestCases/Float/cast-overflow.cpp =================================================================== --- test/ubsan/TestCases/Float/cast-overflow.cpp +++ test/ubsan/TestCases/Float/cast-overflow.cpp @@ -1,12 +1,12 @@ // RUN: %clangxx -fsanitize=float-cast-overflow %s -o %t // RUN: %run %t _ -// 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 -// RUN: %run %t 4 2>&1 | FileCheck %s --check-prefix=CHECK-4 -// RUN: %run %t 5 2>&1 | FileCheck %s --check-prefix=CHECK-5 -// RUN: %run %t 6 2>&1 | FileCheck %s --check-prefix=CHECK-6 +// RUN: %env_ubsan_opts=print_summary=1:report_error_type=1 not %run %t 0 2>&1 | FileCheck %s --check-prefix=CHECK-0 +// RUN: not %run %t 1 2>&1 | FileCheck %s --check-prefix=CHECK-1 +// RUN: not %run %t 2 2>&1 | FileCheck %s --check-prefix=CHECK-2 +// RUN: not %run %t 3 2>&1 | FileCheck %s --check-prefix=CHECK-3 +// RUN: not %run %t 4 2>&1 | FileCheck %s --check-prefix=CHECK-4 +// RUN: not %run %t 5 2>&1 | FileCheck %s --check-prefix=CHECK-5 +// RUN: not %run %t 6 2>&1 | FileCheck %s --check-prefix=CHECK-6 // FIXME: %run %t 7 2>&1 | FileCheck %s --check-prefix=CHECK-7 // FIXME: not %run %t 8 2>&1 | FileCheck %s --check-prefix=CHECK-8 // RUN: not %run %t 9 2>&1 | FileCheck %s --check-prefix=CHECK-9 @@ -129,7 +129,7 @@ // 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; + return 1; #endif } // FIXME: The backend cannot lower __fp16 operations on x86 yet. Index: test/ubsan/TestCases/Integer/add-overflow.cpp =================================================================== --- test/ubsan/TestCases/Integer/add-overflow.cpp +++ test/ubsan/TestCases/Integer/add-overflow.cpp @@ -1,6 +1,6 @@ -// RUN: %clangxx -DADD_I32 -fsanitize=signed-integer-overflow %s -o %t1 && %run %t1 2>&1 | FileCheck %s --check-prefix=CHECK-ADD_I32 -// RUN: %clangxx -DADD_I64 -fsanitize=signed-integer-overflow %s -o %t2 && %run %t2 2>&1 | FileCheck %s --check-prefix=CHECK-ADD_I64 -// RUN: %clangxx -DADD_I128 -fsanitize=signed-integer-overflow %s -o %t3 && %run %t3 2>&1 | FileCheck %s --check-prefix=CHECK-ADD_I128 +// RUN: %clangxx -DADD_I32 -fsanitize=signed-integer-overflow %s -o %t1 && not %run %t1 2>&1 | FileCheck %s --check-prefix=CHECK-ADD_I32 +// RUN: %clangxx -DADD_I64 -fsanitize=signed-integer-overflow %s -o %t2 && not %run %t2 2>&1 | FileCheck %s --check-prefix=CHECK-ADD_I64 +// RUN: %clangxx -DADD_I128 -fsanitize=signed-integer-overflow %s -o %t3 && not %run %t3 2>&1 | FileCheck %s --check-prefix=CHECK-ADD_I128 #include #include @@ -26,6 +26,7 @@ (void)((__int128_t(1) << 126) + (__int128_t(1) << 126)); # else puts("__int128 not supported"); + return 1; # endif // CHECK-ADD_I128: {{0x40000000000000000000000000000000 \+ 0x40000000000000000000000000000000 cannot be represented in type '__int128'|__int128 not supported}} #endif Index: test/ubsan/TestCases/Integer/div-overflow.cpp =================================================================== --- test/ubsan/TestCases/Integer/div-overflow.cpp +++ test/ubsan/TestCases/Integer/div-overflow.cpp @@ -1,4 +1,4 @@ -// RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s +// RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t && not %run %t 2>&1 | FileCheck %s #include Index: test/ubsan/TestCases/Integer/div-zero.cpp =================================================================== --- test/ubsan/TestCases/Integer/div-zero.cpp +++ test/ubsan/TestCases/Integer/div-zero.cpp @@ -1,7 +1,7 @@ -// RUN: %clangxx -fsanitize=integer-divide-by-zero -DDIVIDEND=0 %s -o %t && %run %t 2>&1 | FileCheck %s -// RUN: %clangxx -fsanitize=integer-divide-by-zero -DDIVIDEND=1U %s -o %t && %run %t 2>&1 | FileCheck %s -// RUN: %clangxx -fsanitize=float-divide-by-zero -DDIVIDEND=1.5 %s -o %t && %run %t 2>&1 | FileCheck %s -// RUN: %clangxx -fsanitize=integer-divide-by-zero -DDIVIDEND='intmax(123)' %s -o %t && %run %t 2>&1 | FileCheck %s +// RUN: %clangxx -fsanitize=integer-divide-by-zero -DDIVIDEND=0 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx -fsanitize=integer-divide-by-zero -DDIVIDEND=1U %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx -fsanitize=float-divide-by-zero -DDIVIDEND=1.5 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx -fsanitize=integer-divide-by-zero -DDIVIDEND='intmax(123)' %s -o %t && not %run %t 2>&1 | FileCheck %s #if defined(__SIZEOF_INT128__) && !defined(_WIN32) typedef __int128 intmax; Index: test/ubsan/TestCases/Integer/incdec-overflow.cpp =================================================================== --- test/ubsan/TestCases/Integer/incdec-overflow.cpp +++ test/ubsan/TestCases/Integer/incdec-overflow.cpp @@ -1,7 +1,7 @@ -// RUN: %clangxx -DOP=n++ -fsanitize=signed-integer-overflow %s -o %t1 && %run %t1 2>&1 | FileCheck %s --check-prefix=PLUS -// RUN: %clangxx -DOP=++n -fsanitize=signed-integer-overflow %s -o %t2 && %run %t2 2>&1 | FileCheck %s --check-prefix=PLUS -// RUN: %clangxx -DOP=m-- -fsanitize=signed-integer-overflow %s -o %t3 && %run %t3 2>&1 | FileCheck %s --check-prefix=MINUS -// RUN: %clangxx -DOP=--m -fsanitize=signed-integer-overflow %s -o %t4 && %run %t4 2>&1 | FileCheck %s --check-prefix=MINUS +// RUN: %clangxx -DOP=n++ -fsanitize=signed-integer-overflow %s -o %t1 && not %run %t1 2>&1 | FileCheck %s --check-prefix=PLUS +// RUN: %clangxx -DOP=++n -fsanitize=signed-integer-overflow %s -o %t2 && not %run %t2 2>&1 | FileCheck %s --check-prefix=PLUS +// RUN: %clangxx -DOP=m-- -fsanitize=signed-integer-overflow %s -o %t3 && not %run %t3 2>&1 | FileCheck %s --check-prefix=MINUS +// RUN: %clangxx -DOP=--m -fsanitize=signed-integer-overflow %s -o %t4 && not %run %t4 2>&1 | FileCheck %s --check-prefix=MINUS #include Index: test/ubsan/TestCases/Integer/mul-overflow.cpp =================================================================== --- test/ubsan/TestCases/Integer/mul-overflow.cpp +++ test/ubsan/TestCases/Integer/mul-overflow.cpp @@ -1,4 +1,4 @@ -// RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s +// RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t && not %run %t 2>&1 | FileCheck %s #include Index: test/ubsan/TestCases/Integer/negate-overflow.cpp =================================================================== --- test/ubsan/TestCases/Integer/negate-overflow.cpp +++ test/ubsan/TestCases/Integer/negate-overflow.cpp @@ -1,5 +1,5 @@ -// RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t1 && %run %t1 2>&1 | FileCheck %s --check-prefix=CHECKS -// RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t2 && %run %t2 2>&1 | FileCheck %s --check-prefix=CHECKU +// RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t1 && not %run %t1 2>&1 | FileCheck %s --check-prefix=CHECKS +// RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t2 && not %run %t2 2>&1 | FileCheck %s --check-prefix=CHECKU int main() { // CHECKS-NOT: runtime error Index: test/ubsan/TestCases/Integer/no-recover.cpp =================================================================== --- test/ubsan/TestCases/Integer/no-recover.cpp +++ test/ubsan/TestCases/Integer/no-recover.cpp @@ -1,5 +1,5 @@ -// RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER -// RUN: %clangxx -fsanitize=unsigned-integer-overflow -fno-sanitize-recover=all -fsanitize-recover=unsigned-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER +// RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER +// RUN: %clangxx -fsanitize=unsigned-integer-overflow -fno-sanitize-recover=all -fsanitize-recover=unsigned-integer-overflow %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER // RUN: %clangxx -fsanitize=unsigned-integer-overflow -fno-sanitize-recover=unsigned-integer-overflow %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=ABORT #include Index: test/ubsan/TestCases/Integer/sub-overflow.cpp =================================================================== --- test/ubsan/TestCases/Integer/sub-overflow.cpp +++ test/ubsan/TestCases/Integer/sub-overflow.cpp @@ -1,6 +1,6 @@ -// RUN: %clangxx -DSUB_I32 -fsanitize=signed-integer-overflow %s -o %t1 && %run %t1 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I32 -// RUN: %clangxx -DSUB_I64 -fsanitize=signed-integer-overflow %s -o %t2 && %run %t2 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I64 -// RUN: %clangxx -DSUB_I128 -fsanitize=signed-integer-overflow %s -o %t3 && %run %t3 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I128 +// RUN: %clangxx -DSUB_I32 -fsanitize=signed-integer-overflow %s -o %t1 && not %run %t1 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I32 +// RUN: %clangxx -DSUB_I64 -fsanitize=signed-integer-overflow %s -o %t2 && not %run %t2 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I64 +// RUN: %clangxx -DSUB_I128 -fsanitize=signed-integer-overflow %s -o %t3 && not %run %t3 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I128 #include #include @@ -25,6 +25,7 @@ (void)(-(__int128_t(1) << 126) - (__int128_t(1) << 126) - 1); # else puts("__int128 not supported"); + return 1; # endif // CHECK-SUB_I128: {{0x80000000000000000000000000000000 - 1 cannot be represented in type '__int128'|__int128 not supported}} #endif Index: test/ubsan/TestCases/Integer/summary.cpp =================================================================== --- test/ubsan/TestCases/Integer/summary.cpp +++ test/ubsan/TestCases/Integer/summary.cpp @@ -1,6 +1,6 @@ // 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 +// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE +// RUN: %env_ubsan_opts=report_error_type=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE // REQUIRES: ubsan-asan #include Index: test/ubsan/TestCases/Integer/uadd-overflow.cpp =================================================================== --- test/ubsan/TestCases/Integer/uadd-overflow.cpp +++ test/ubsan/TestCases/Integer/uadd-overflow.cpp @@ -1,6 +1,6 @@ -// RUN: %clangxx -DADD_I32 -fsanitize=unsigned-integer-overflow %s -o %t1 && %run %t1 2>&1 | FileCheck %s --check-prefix=CHECK-ADD_I32 -// RUN: %clangxx -DADD_I64 -fsanitize=unsigned-integer-overflow %s -o %t2 && %run %t2 2>&1 | FileCheck %s --check-prefix=CHECK-ADD_I64 -// RUN: %clangxx -DADD_I128 -fsanitize=unsigned-integer-overflow %s -o %t3 && %run %t3 2>&1 | FileCheck %s --check-prefix=CHECK-ADD_I128 +// RUN: %clangxx -DADD_I32 -fsanitize=unsigned-integer-overflow %s -o %t1 && not %run %t1 2>&1 | FileCheck %s --check-prefix=CHECK-ADD_I32 +// RUN: %clangxx -DADD_I64 -fsanitize=unsigned-integer-overflow %s -o %t2 && not %run %t2 2>&1 | FileCheck %s --check-prefix=CHECK-ADD_I64 +// RUN: %clangxx -DADD_I128 -fsanitize=unsigned-integer-overflow %s -o %t3 && not %run %t3 2>&1 | FileCheck %s --check-prefix=CHECK-ADD_I128 #include #include @@ -26,6 +26,7 @@ (void)((__uint128_t(1) << 127) + (__uint128_t(1) << 127)); # else puts("__int128 not supported"); + return 1; # endif // CHECK-ADD_I128: {{0x80000000000000000000000000000000 \+ 0x80000000000000000000000000000000 cannot be represented in type 'unsigned __int128'|__int128 not supported}} #endif Index: test/ubsan/TestCases/Integer/uincdec-overflow.cpp =================================================================== --- test/ubsan/TestCases/Integer/uincdec-overflow.cpp +++ test/ubsan/TestCases/Integer/uincdec-overflow.cpp @@ -1,7 +1,7 @@ -// RUN: %clangxx -DOP=n++ -fsanitize=unsigned-integer-overflow %s -o %t1 && %run %t1 2>&1 | FileCheck --check-prefix=CHECK-INC %s -// RUN: %clangxx -DOP=++n -fsanitize=unsigned-integer-overflow %s -o %t2 && %run %t2 2>&1 | FileCheck --check-prefix=CHECK-INC %s -// RUN: %clangxx -DOP=m-- -fsanitize=unsigned-integer-overflow %s -o %t3 && %run %t3 2>&1 | FileCheck --check-prefix=CHECK-DEC %s -// RUN: %clangxx -DOP=--m -fsanitize=unsigned-integer-overflow %s -o %t4 && %run %t4 2>&1 | FileCheck --check-prefix=CHECK-DEC %s +// RUN: %clangxx -DOP=n++ -fsanitize=unsigned-integer-overflow %s -o %t1 && not %run %t1 2>&1 | FileCheck --check-prefix=CHECK-INC %s +// RUN: %clangxx -DOP=++n -fsanitize=unsigned-integer-overflow %s -o %t2 && not %run %t2 2>&1 | FileCheck --check-prefix=CHECK-INC %s +// RUN: %clangxx -DOP=m-- -fsanitize=unsigned-integer-overflow %s -o %t3 && not %run %t3 2>&1 | FileCheck --check-prefix=CHECK-DEC %s +// RUN: %clangxx -DOP=--m -fsanitize=unsigned-integer-overflow %s -o %t4 && not %run %t4 2>&1 | FileCheck --check-prefix=CHECK-DEC %s #include Index: test/ubsan/TestCases/Integer/umul-overflow.cpp =================================================================== --- test/ubsan/TestCases/Integer/umul-overflow.cpp +++ test/ubsan/TestCases/Integer/umul-overflow.cpp @@ -1,4 +1,4 @@ -// RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s +// RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t && not %run %t 2>&1 | FileCheck %s #include Index: test/ubsan/TestCases/Integer/usub-overflow.cpp =================================================================== --- test/ubsan/TestCases/Integer/usub-overflow.cpp +++ test/ubsan/TestCases/Integer/usub-overflow.cpp @@ -1,6 +1,6 @@ -// RUN: %clangxx -DSUB_I32 -fsanitize=unsigned-integer-overflow %s -o %t1 && %run %t1 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I32 -// RUN: %clangxx -DSUB_I64 -fsanitize=unsigned-integer-overflow %s -o %t2 && %run %t2 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I64 -// RUN: %clangxx -DSUB_I128 -fsanitize=unsigned-integer-overflow %s -o %t3 && %run %t3 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I128 +// RUN: %clangxx -DSUB_I32 -fsanitize=unsigned-integer-overflow %s -o %t1 && not %run %t1 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I32 +// RUN: %clangxx -DSUB_I64 -fsanitize=unsigned-integer-overflow %s -o %t2 && not %run %t2 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I64 +// RUN: %clangxx -DSUB_I128 -fsanitize=unsigned-integer-overflow %s -o %t3 && not %run %t3 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I128 #include #include @@ -25,6 +25,7 @@ (void)((__uint128_t(1) << 126) - (__uint128_t(1) << 127)); # else puts("__int128 not supported\n"); + return 1; # endif // CHECK-SUB_I128: {{0x40000000000000000000000000000000 - 0x80000000000000000000000000000000 cannot be represented in type 'unsigned __int128'|__int128 not supported}} #endif Index: test/ubsan/TestCases/Misc/bounds.cpp =================================================================== --- test/ubsan/TestCases/Misc/bounds.cpp +++ test/ubsan/TestCases/Misc/bounds.cpp @@ -2,8 +2,8 @@ // RUN: %run %t 0 0 0 // RUN: %run %t 1 2 3 // RUN: %expect_crash %run %t 2 0 0 2>&1 | FileCheck %s --check-prefix=CHECK-A-2 -// RUN: %run %t 0 3 0 2>&1 | FileCheck %s --check-prefix=CHECK-B-3 -// RUN: %run %t 0 0 4 2>&1 | FileCheck %s --check-prefix=CHECK-C-4 +// RUN: not %run %t 0 3 0 2>&1 | FileCheck %s --check-prefix=CHECK-B-3 +// RUN: not %run %t 0 0 4 2>&1 | FileCheck %s --check-prefix=CHECK-C-4 int main(int argc, char **argv) { int arr[2][3][4] = {}; Index: test/ubsan/TestCases/Misc/coverage-levels.cc =================================================================== --- test/ubsan/TestCases/Misc/coverage-levels.cc +++ test/ubsan/TestCases/Misc/coverage-levels.cc @@ -14,11 +14,11 @@ // 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: %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: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir='"%T/coverage-levels"' not %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: %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: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir='"%T/coverage-levels"' not %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: %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 +// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir='"%T/coverage-levels"' not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3 --check-prefix=CHECK_WARN // Coverage is not yet implemented in TSan. // XFAIL: ubsan-tsan Index: test/ubsan/TestCases/Misc/deduplication.cpp =================================================================== --- test/ubsan/TestCases/Misc/deduplication.cpp +++ test/ubsan/TestCases/Misc/deduplication.cpp @@ -1,4 +1,4 @@ -// RUN: %clangxx -fsanitize=undefined %s -o %t && %run %t 2>&1 | FileCheck %s +// RUN: %clangxx -fsanitize=undefined %s -o %t && not %run %t 2>&1 | FileCheck %s // Verify deduplication works by ensuring only one diag is emitted. #include #include Index: test/ubsan/TestCases/Misc/enum.cpp =================================================================== --- test/ubsan/TestCases/Misc/enum.cpp +++ test/ubsan/TestCases/Misc/enum.cpp @@ -1,4 +1,4 @@ -// RUN: %clangxx -fsanitize=enum %s -O3 -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-PLAIN +// RUN: %clangxx -fsanitize=enum %s -O3 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-PLAIN // RUN: %clangxx -fsanitize=enum -std=c++11 -DE="class E" %s -O3 -o %t && %run %t // RUN: %clangxx -fsanitize=enum -std=c++11 -DE="class E : bool" %s -O3 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-BOOL Index: test/ubsan/TestCases/Misc/exitcode.cc =================================================================== --- /dev/null +++ test/ubsan/TestCases/Misc/exitcode.cc @@ -0,0 +1,13 @@ +// RUN: %clangxx -fsanitize=undefined -DDIVISOR=0 %s -o %t-ZERO +// RUN: %clangxx -fsanitize=undefined -DDIVISOR=1 %s -o %t-ONE +// RUN: not %run %t-ZERO 2>&1 | FileCheck %s +// RUN: %env_ubsan_opts=exitcode=15 not %run %t-ZERO 2>&1 | FileCheck %s +// RUN: %env_ubsan_opts=exitcode=0 %run %t-ZERO 2>&1 | FileCheck %s +// RUN: %run %t-ONE 2>&1 | count 0 + +int main() { + int a = 1 / DIVISOR; + return 0; +} + +// CHECK: runtime error: division by zero Index: test/ubsan/TestCases/Misc/log-path_test.cc =================================================================== --- test/ubsan/TestCases/Misc/log-path_test.cc +++ test/ubsan/TestCases/Misc/log-path_test.cc @@ -7,12 +7,12 @@ // RUN: %clangxx -fsanitize=undefined %s -O1 -o %t // Regular run. -// RUN: %run %t -4 2> %t.out +// RUN: not %run %t -4 2> %t.out // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.out // Good log_path. // RUN: rm -f %t.log.* -// RUN: %env_ubsan_opts=log_path='"%t.log"' %run %t -4 2> %t.out +// RUN: %env_ubsan_opts=log_path='"%t.log"' not %run %t -4 2> %t.out // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.* // Run w/o errors should not produce any log. Index: test/ubsan/TestCases/Misc/nonnull.cpp =================================================================== --- test/ubsan/TestCases/Misc/nonnull.cpp +++ test/ubsan/TestCases/Misc/nonnull.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx -fsanitize=returns-nonnull-attribute -w %s -O3 -o %t // RUN: %run %t foo 2>&1 | count 0 -// RUN: %run %t 2>&1 | FileCheck %s +// RUN: not %run %t 2>&1 | FileCheck %s // RUN: %clangxx -fsanitize=returns-nonnull-attribute -fno-sanitize-recover=returns-nonnull-attribute -w %s -O3 -o %t.abort // RUN: not %run %t.abort &> /dev/null Index: test/ubsan/TestCases/Misc/nullability.c =================================================================== --- test/ubsan/TestCases/Misc/nullability.c +++ test/ubsan/TestCases/Misc/nullability.c @@ -1,6 +1,6 @@ // RUN: %clang -w -fsanitize=nullability-arg,nullability-assign,nullability-return %s -O3 -o %t // RUN: %run %t foo 2>&1 | count 0 -// RUN: %run %t 2>&1 | FileCheck %s +// RUN: not %run %t 2>&1 | FileCheck %s // CHECK: nullability.c:[[@LINE+2]]:41: runtime error: null pointer returned from function declared to never return null // CHECK-NEXT: nullability.c:[[@LINE+1]]:6: note: _Nonnull return type annotation specified here Index: test/ubsan/TestCases/Misc/vla.c =================================================================== --- test/ubsan/TestCases/Misc/vla.c +++ test/ubsan/TestCases/Misc/vla.c @@ -1,6 +1,6 @@ // RUN: %clang -fsanitize=vla-bound %s -O3 -o %t -// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MINUS-ONE -// RUN: %run %t a 2>&1 | FileCheck %s --check-prefix=CHECK-ZERO +// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MINUS-ONE +// RUN: not %run %t a 2>&1 | FileCheck %s --check-prefix=CHECK-ZERO // RUN: %run %t a b int main(int argc, char **argv) { Index: test/ubsan/TestCases/Pointer/index-overflow.cpp =================================================================== --- test/ubsan/TestCases/Pointer/index-overflow.cpp +++ test/ubsan/TestCases/Pointer/index-overflow.cpp @@ -1,5 +1,5 @@ // RUN: %clangxx -fsanitize=pointer-overflow %s -o %t -// RUN: %t 1 2>&1 | FileCheck %s --check-prefix=ERR +// RUN: not %t 1 2>&1 | FileCheck %s --check-prefix=ERR // RUN: %t 0 2>&1 | FileCheck %s --check-prefix=SAFE // RUN: %t -1 2>&1 | FileCheck %s --check-prefix=SAFE Index: test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp =================================================================== --- test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp +++ test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp @@ -1,5 +1,5 @@ // RUN: %clangxx -fsanitize=pointer-overflow %s -o %t -// RUN: %t 2>&1 | FileCheck %s +// RUN: not %t 2>&1 | FileCheck %s int main(int argc, char *argv[]) { char c; Index: test/ubsan/TestCases/TypeCheck/Function/function.cpp =================================================================== --- test/ubsan/TestCases/TypeCheck/Function/function.cpp +++ 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 +// RUN: not %run %t 2>&1 | FileCheck %s // Verify that we can disable symbolization if needed: -// RUN: %env_ubsan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM +// RUN: %env_ubsan_opts=symbolize=0 not %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM // -fsanitize=function is unsupported on Darwin yet. // XFAIL: darwin Index: test/ubsan/TestCases/TypeCheck/Linux/PR33221.cpp =================================================================== --- test/ubsan/TestCases/TypeCheck/Linux/PR33221.cpp +++ test/ubsan/TestCases/TypeCheck/Linux/PR33221.cpp @@ -1,5 +1,5 @@ // RUN: %clangxx -std=c++11 -frtti -fsanitize=vptr -g %s -O3 -o %t -// RUN: %run %t &> %t.log +// RUN: not %run %t &> %t.log // RUN: cat %t.log | not count 0 && FileCheck --input-file %t.log %s || cat %t.log | count 0 // REQUIRES: cxxabi @@ -24,7 +24,6 @@ void *non_accessible = mmap(nullptr, page_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (non_accessible == MAP_FAILED) return 0; Index: test/ubsan/TestCases/TypeCheck/PR33221.cpp =================================================================== --- test/ubsan/TestCases/TypeCheck/PR33221.cpp +++ test/ubsan/TestCases/TypeCheck/PR33221.cpp @@ -1,5 +1,5 @@ // RUN: %clangxx -frtti -fsanitize=vptr -g %s -O3 -o %t -// RUN: %run %t 2>&1 | FileCheck %s +// RUN: not %run %t 2>&1 | FileCheck %s // REQUIRES: cxxabi Index: test/ubsan/TestCases/TypeCheck/misaligned.cpp =================================================================== --- test/ubsan/TestCases/TypeCheck/misaligned.cpp +++ test/ubsan/TestCases/TypeCheck/misaligned.cpp @@ -1,13 +1,13 @@ // RUN: %clangxx %gmlt -fsanitize=alignment %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 -// RUN: %run %t s1 2>&1 | FileCheck %s --check-prefix=CHECK-STORE -// RUN: %run %t r1 2>&1 | FileCheck %s --check-prefix=CHECK-REFERENCE -// RUN: %run %t m1 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER -// 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_opts=print_stacktrace=1 %run %t l1 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD --check-prefix=CHECK-STACK-LOAD +// RUN: not %run %t l1 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD --strict-whitespace +// RUN: not %run %t s1 2>&1 | FileCheck %s --check-prefix=CHECK-STORE +// RUN: not %run %t r1 2>&1 | FileCheck %s --check-prefix=CHECK-REFERENCE +// RUN: not %run %t m1 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER +// RUN: not %run %t f1 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN +// RUN: not %run %t n1 2>&1 | FileCheck %s --check-prefix=CHECK-NEW +// RUN: not %run %t u1 2>&1 | FileCheck %s --check-prefix=CHECK-UPCAST +// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t l1 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD --check-prefix=CHECK-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