1// Tests trace pc guard coverage collection.
2
3// REQUIRES: has_sancovcc
4// UNSUPPORTED: ubsan,i386-darwin,target={{(powerpc64|s390x|thumb).*}}
5// XFAIL: tsan
6// XFAIL: android && asan
7
8// RUN: DIR=%t_workdir
9// RUN: rm -rf $DIR
10// RUN: mkdir -p $DIR
11// RUN: cd $DIR
12// RUN: %clangxx -O0 -fsanitize-coverage=trace-pc-guard %s -o %t
13// RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s
14// RUN: %sancovcc -covered-functions -strip_path_prefix=TestCases/ *.sancov %t 2>&1 | \
15// RUN: FileCheck --check-prefix=CHECK-SANCOV %s
16// RUN: %env_tool_opts=coverage=0 %t 2>&1 | FileCheck --check-prefix=CHECK-NOCOV %s
17// RUN: rm -rf $DIR
18// Make some room to stabilize line numbers
19
20#include <stdio.h>
21
22int foo() {
23 fprintf(stderr, format: "foo\n");
24 return 1;
25}
26
27int main() {
28 fprintf(stderr, format: "main\n");
29 foo();
30 foo();
31}
32
33// CHECK: main
34// CHECK-NEXT: foo
35// CHECK-NEXT: foo
36// CHECK-NEXT: SanitizerCoverage: ./sanitizer_coverage_trace_pc_guard.{{.*}}.sancov: 2 PCs written
37//
38// CHECK-SANCOV: sanitizer_coverage_trace_pc_guard.cpp:[[@LINE-16]] foo
39// CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard.cpp:[[@LINE-12]] main
40//
41// CHECK-NOCOV-NOT: SanitizerCoverage
42

source code of compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cpp