1 // Test various levels of coverage
3 // FIXME: Port the environment variable logic below for the lit shell.
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
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
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
23 // Coverage is not yet implemented in TSan.
25 // UNSUPPORTED: ubsan-standalone-static
26 // No coverage support
27 // UNSUPPORTED: target={{.*openbsd.*}}
30 int main(int argc
, char **argv
) {
31 int shift
= argc
* 33;
35 if ((argc
<< shift
) == 16) // False.
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
46 // CHECK1: 1 PCs written
47 // CHECK2: 2 PCs written
48 // CHECK3: 2 PCs written