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