1// Test various levels of coverage
2//
3// RUN: %clangxx_msan -DINIT_VAR=1 -O1 -fsanitize-coverage=func,trace-pc-guard %s -o %t
4// RUN: mkdir -p %t-dir
5// RUN: MSAN_OPTIONS=coverage=1:verbosity=1:coverage_dir=%t-dir %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN
6// RUN: %clangxx_msan -O1 -fsanitize-coverage=func,trace-pc-guard %s -o %t
7// RUN: MSAN_OPTIONS=coverage=1:verbosity=1:coverage_dir=%t-dir not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_WARN
8// RUN: %clangxx_msan -O1 -fsanitize-coverage=bb,trace-pc-guard %s -o %t
9// RUN: MSAN_OPTIONS=coverage=1:verbosity=1:coverage_dir=%t-dir not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2 --check-prefix=CHECK_WARN
10// RUN: %clangxx_msan -O1 -fsanitize-coverage=edge,trace-pc-guard %s -o %t
11// RUN: MSAN_OPTIONS=coverage=1:verbosity=1:coverage_dir=%t-dir not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3 --check-prefix=CHECK_WARN
12
13volatile int sink;
14int main(int argc, char **argv) {
15 int var;
16#if INIT_VAR
17 var = 0;
18#endif
19 if (argc == 0)
20 sink = 0;
21 return *(volatile int*)&var;
22}
23
24// CHECK_WARN: WARNING: MemorySanitizer: use-of-uninitialized-value
25// CHECK_NOWARN-NOT: ERROR
26// CHECK1: 1 PCs written
27// CHECK2: 1 PCs written
28// CHECK3: 2 PCs written
29

source code of compiler-rt/test/msan/coverage-levels.cpp