Home | History | Annotate | Download | only in TestCases
      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
      6 int pc_count;
      7 void *last_callee;
      8 extern "C" void __sanitizer_cov_trace_pc() {
      9   pc_count++;
     10 }
     11 extern "C" void __sanitizer_cov_trace_pc_indir(void *callee) {
     12   last_callee = callee;
     13 }
     14 #else
     15 #include <stdio.h>
     16 #include <assert.h>
     17 extern int pc_count;
     18 extern void *last_callee;
     19 
     20 __attribute__((noinline)) void foo() { printf("foo\n"); }
     21 __attribute__((noinline)) void bar() { printf("bar\n"); }
     22 
     23 int 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