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// XFAIL: msvc
6
7#ifdef TRACE_RT
8int pc_count;
9void *last_callee;
10extern "C" void __sanitizer_cov_trace_pc() {
11 pc_count++;
12}
13extern "C" void __sanitizer_cov_trace_pc_indir(void *callee) {
14 last_callee = callee;
15}
16#else
17# include "defines.h"
18# include <assert.h>
19# include <stdio.h>
20extern int pc_count;
21extern void *last_callee;
22
23ATTRIBUTE_NOINLINE void foo() { printf(format: "foo\n"); }
24ATTRIBUTE_NOINLINE void bar() { printf(format: "bar\n"); }
25
26int main(int argc, char **argv) {
27 void (*f)(void) = argc ? foo : bar;
28 int c1 = pc_count;
29 f();
30 int c2 = pc_count;
31 assert(c1 < c2);
32 assert(last_callee == foo);
33}
34#endif
35

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

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