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