1// RUN: %clangxx_cfi %debug_info_flags -fsanitize-stats -o %t %s
2// RUN: env SANITIZER_STATS_PATH=%t.stats %run %t
3// RUN: sanstats %t.stats | FileCheck %s
4
5// FIXME: We currently emit the wrong debug info under devirtualization.
6// UNSUPPORTED: devirt
7
8// FIXME: %t.stats must be transferred from device to host for this to work on Android.
9// XFAIL: android
10
11struct ABase {};
12
13struct A : ABase {
14 virtual void vf() {}
15 void nvf() {}
16};
17
18extern "C" __attribute__((noinline)) void vcall(A *a) {
19 // CHECK: stats.cpp:[[@LINE+1]] {{_?}}vcall cfi-vcall 37
20 a->vf();
21}
22
23extern "C" __attribute__((noinline)) void nvcall(A *a) {
24 // CHECK: stats.cpp:[[@LINE+1]] {{_?}}nvcall cfi-nvcall 51
25 a->nvf();
26}
27
28extern "C" __attribute__((noinline)) A *dcast(A *a) {
29 // CHECK: stats.cpp:[[@LINE+1]] {{_?}}dcast cfi-derived-cast 24
30 return (A *)(ABase *)a;
31}
32
33extern "C" __attribute__((noinline)) A *ucast(A *a) {
34 // CHECK: stats.cpp:[[@LINE+1]] {{_?}}ucast cfi-unrelated-cast 81
35 return (A *)(char *)a;
36}
37
38extern "C" __attribute__((noinline)) void unreachable(A *a) {
39 // CHECK-NOT: unreachable
40 a->vf();
41}
42
43int main() {
44 A a;
45 for (unsigned i = 0; i != 37; ++i)
46 vcall(&a);
47 for (unsigned i = 0; i != 51; ++i)
48 nvcall(&a);
49 for (unsigned i = 0; i != 24; ++i)
50 dcast(&a);
51 for (unsigned i = 0; i != 81; ++i)
52 ucast(&a);
53 for (unsigned i = 0; i != 0; ++i)
54 unreachable(&a);
55}
56