• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: mkdir -p %T/coverage-levels
7 // RUN: %clangxx -fsanitize=shift                        -DGOOD_SHIFT=1 -O1 -fsanitize-coverage=func  %s -o %t
8 // 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
9 // RUN: %clangxx -fsanitize=undefined                    -DGOOD_SHIFT=1 -O1 -fsanitize-coverage=func  %s -o %t
10 // 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
11 
12 // RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=func  %s -o %t
13 // 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
14 // RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=bb  %s -o %t
15 // 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
16 // RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=edge  %s -o %t
17 // 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
18 
19 // Coverage is not yet implemented in TSan.
20 // XFAIL: ubsan-tsan
21 
22 volatile int sink;
main(int argc,char ** argv)23 int main(int argc, char **argv) {
24   int shift = argc * 32;
25 #if GOOD_SHIFT
26   shift = 3;
27 #endif
28   if ((argc << shift) == 16)  // False.
29     return 1;
30   return 0;
31 }
32 
33 // CHECK_WARN: shift exponent 32 is too large
34 // CHECK_NOWARN-NOT: ERROR
35 // FIXME: Currently, coverage instrumentation kicks in after ubsan, so we get
36 // more than the minimal number of instrumented blocks.
37 // FIXME: Currently, ubsan with -fno-sanitize-recover and w/o asan will fail
38 // to dump coverage.
39 // CHECK1:  1 PCs written
40 // CHECK2:  3 PCs written
41 // CHECK3:  3 PCs written
42