1// Test various levels of coverage
2//
3// FIXME: Port the environment variable logic below for the lit shell.
4// REQUIRES: shell
5//
6// RUN: rm -rf %t-dir && mkdir %t-dir
7// RUN: %clangxx -fsanitize=shift -DGOOD_SHIFT=1 -O1 -fsanitize-coverage=func,trace-pc-guard %s -o %t
8// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir='"%t-dir"' %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN
9// RUN: %clangxx -fsanitize=undefined -DGOOD_SHIFT=1 -O1 -fsanitize-coverage=func,trace-pc-guard %s -o %t
10// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir='"%t-dir"' %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN
11
12// Also works without any sanitizer.
13// RUN: %clangxx -DGOOD_SHIFT=1 -O1 -fsanitize-coverage=func,trace-pc-guard %s -o %t
14// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir='"%t-dir"' %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN
15
16// RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=func,trace-pc-guard %s -o %t
17// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir='"%t-dir"' %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_WARN
18// RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=bb,trace-pc-guard %s -o %t
19// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir='"%t-dir"' %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2 --check-prefix=CHECK_WARN
20// RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=edge,trace-pc-guard %s -o %t
21// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir='"%t-dir"' %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3 --check-prefix=CHECK_WARN
22
23// Coverage is not yet implemented in TSan.
24// XFAIL: ubsan-tsan
25// UNSUPPORTED: ubsan-standalone-static
26// No coverage support
27// UNSUPPORTED: target={{.*openbsd.*}}
28
29volatile int sink;
30int main(int argc, char **argv) {
31 int shift = argc * 33;
32#if GOOD_SHIFT
33 shift = 3;
34#endif
35 if ((argc << shift) == 16) // False.
36 return 1;
37 return 0;
38}
39
40// CHECK_WARN: shift exponent 33 is too large
41// CHECK_NOWARN-NOT: ERROR
42// FIXME: Currently, coverage instrumentation kicks in after ubsan, so we get
43// more than the minimal number of instrumented blocks.
44// FIXME: Currently, ubsan with -fno-sanitize-recover and w/o asan will fail
45// to dump coverage.
46// CHECK1: 1 PCs written
47// CHECK2: 2 PCs written
48// CHECK3: 2 PCs written
49

source code of compiler-rt/test/ubsan/TestCases/Misc/coverage-levels.cpp