diff options
Diffstat (limited to 'test/ubsan/TestCases/Misc/Linux')
-rw-r--r-- | test/ubsan/TestCases/Misc/Linux/coverage-levels.cc | 39 | ||||
-rw-r--r-- | test/ubsan/TestCases/Misc/Linux/lit.local.cfg | 9 | ||||
-rw-r--r-- | test/ubsan/TestCases/Misc/Linux/ubsan_options.cc | 18 |
3 files changed, 66 insertions, 0 deletions
diff --git a/test/ubsan/TestCases/Misc/Linux/coverage-levels.cc b/test/ubsan/TestCases/Misc/Linux/coverage-levels.cc new file mode 100644 index 0000000000000..df6e835dd9dff --- /dev/null +++ b/test/ubsan/TestCases/Misc/Linux/coverage-levels.cc @@ -0,0 +1,39 @@ +// Test various levels of coverage +// +// 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: %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: %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: %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: %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 + +// Coverage is not yet implemented in TSan. +// XFAIL: ubsan-tsan + +volatile int sink; +int main(int argc, char **argv) { + int shift = argc * 32; +#if GOOD_SHIFT + shift = 3; +#endif + if ((argc << shift) == 16) // False. + return 1; + return 0; +} + +// CHECK_WARN: shift exponent 32 is too large +// CHECK_NOWARN-NOT: ERROR +// FIXME: Currently, coverage instrumentation kicks in after ubsan, so we get +// more than the minimal number of instrumented blocks. +// FIXME: Currently, ubsan with -fno-sanitize-recover and w/o asan will fail +// to dump coverage. +// CHECK1: 1 PCs written +// CHECK2: 3 PCs written +// CHECK3: 4 PCs written diff --git a/test/ubsan/TestCases/Misc/Linux/lit.local.cfg b/test/ubsan/TestCases/Misc/Linux/lit.local.cfg new file mode 100644 index 0000000000000..57271b8078a49 --- /dev/null +++ b/test/ubsan/TestCases/Misc/Linux/lit.local.cfg @@ -0,0 +1,9 @@ +def getRoot(config): + if not config.parent: + return config + return getRoot(config.parent) + +root = getRoot(config) + +if root.host_os not in ['Linux']: + config.unsupported = True diff --git a/test/ubsan/TestCases/Misc/Linux/ubsan_options.cc b/test/ubsan/TestCases/Misc/Linux/ubsan_options.cc new file mode 100644 index 0000000000000..2be8792cce960 --- /dev/null +++ b/test/ubsan/TestCases/Misc/Linux/ubsan_options.cc @@ -0,0 +1,18 @@ +// RUN: %clangxx -fsanitize=integer -fsanitize-recover=integer %s -o %t +// RUN: not %t 2>&1 | FileCheck %s + +// __ubsan_default_options() doesn't work on Darwin. +// XFAIL: darwin + +#include <stdint.h> + +extern "C" const char *__ubsan_default_options() { + return "halt_on_error=1"; +} + +int main() { + (void)(uint64_t(10000000000000000000ull) + uint64_t(9000000000000000000ull)); + // CHECK: ubsan_options.cc:[[@LINE-1]]:44: runtime error: unsigned integer overflow + return 0; +} + |