1 // RUN: %clangxx_cfi_dso -DSHARED_LIB -fPIC -g -fsanitize-stats -shared -o %t.so %s
2 // RUN: %clangxx_cfi_dso -g -fsanitize-stats -o %t %s %t.so
3 // RUN: env SANITIZER_STATS_PATH=%t.stats %t
4 // RUN: sanstats %t.stats | FileCheck %s
5 
6 // CFI-icall is not implemented in thinlto mode => ".cfi" suffixes are missing
7 // in sanstats output.
8 // XFAIL: thinlto
9 
10 struct ABase {};
11 
12 struct A : ABase {
13   virtual void vf() {}
14   void nvf() {}
15 };
16 
17 extern "C" void vcall(A *a);
18 extern "C" void nvcall(A *a);
19 
20 #ifdef SHARED_LIB
21 
22 extern "C" __attribute__((noinline)) void vcall(A *a) {
23   // CHECK: stats.cpp:[[@LINE+1]] vcall.cfi cfi-vcall 37
24   a->vf();
25 }
26 
27 extern "C" __attribute__((noinline)) void nvcall(A *a) {
28   // CHECK: stats.cpp:[[@LINE+1]] nvcall.cfi cfi-nvcall 51
29   a->nvf();
30 }
31 
32 #else
33 
34 extern "C" __attribute__((noinline)) A *dcast(A *a) {
35   // CHECK: stats.cpp:[[@LINE+1]] dcast.cfi cfi-derived-cast 24
36   return (A *)(ABase *)a;
37 }
38 
39 extern "C" __attribute__((noinline)) A *ucast(A *a) {
40   // CHECK: stats.cpp:[[@LINE+1]] ucast.cfi cfi-unrelated-cast 81
41   return (A *)(char *)a;
42 }
43 
44 extern "C" __attribute__((noinline)) void unreachable(A *a) {
45   // CHECK-NOT: unreachable
46   a->vf();
47 }
48 
49 int main() {
50   A a;
51   for (unsigned i = 0; i != 37; ++i)
52     vcall(&a);
53   for (unsigned i = 0; i != 51; ++i)
54     nvcall(&a);
55   for (unsigned i = 0; i != 24; ++i)
56     dcast(&a);
57   for (unsigned i = 0; i != 81; ++i)
58     ucast(&a);
59   for (unsigned i = 0; i != 0; ++i)
60     unreachable(&a);
61 }
62 
63 #endif
64