1// Test -fsanitize-coverage=edge,indirect-call,trace-pc
2// RUN: %clangxx_asan -O0 -DTRACE_RT %s -o %t-rt.o -c
3// RUN: %clangxx_asan -O0 -fsanitize-coverage=edge,trace-pc,indirect-calls %s -o %t %t-rt.o
4// RUN: %run %t
5#ifdef TRACE_RT
6int pc_count;
7void *last_callee;
8extern "C" void __sanitizer_cov_trace_pc() {
9 pc_count++;
10}
11extern "C" void __sanitizer_cov_trace_pc_indir(void *callee) {
12 last_callee = callee;
13}
14#else
15#include <stdio.h>
16#include <assert.h>
17extern int pc_count;
18extern void *last_callee;
19
20__attribute__((noinline)) void foo() { printf(format: "foo\n"); }
21__attribute__((noinline)) void bar() { printf(format: "bar\n"); }
22
23int main(int argc, char **argv) {
24 void (*f)(void) = argc ? foo : bar;
25 int c1 = pc_count;
26 f();
27 int c2 = pc_count;
28 assert(c1 < c2);
29 assert(last_callee == foo);
30}
31#endif
32

source code of compiler-rt/test/asan/TestCases/coverage-trace-pc.cpp