Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / cfi / cross-dso / stats.cpp
blob9d8c2ee3e0d952c62e8df4d7f6735fc01ad21ee1
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
6 // CFI-icall is not implemented in thinlto mode => ".cfi" suffixes are missing
7 // in sanstats output.
9 // FIXME: %t.stats must be transferred from device to host for this to work on Android.
10 // XFAIL: android
12 struct ABase {};
14 struct A : ABase {
15 virtual void vf() {}
16 void nvf() {}
19 extern "C" void vcall(A *a);
20 extern "C" void nvcall(A *a);
22 #ifdef SHARED_LIB
24 extern "C" __attribute__((noinline)) void vcall(A *a) {
25 // CHECK-DAG: stats.cpp:[[@LINE+1]] vcall.cfi cfi-vcall 37
26 a->vf();
29 extern "C" __attribute__((noinline)) void nvcall(A *a) {
30 // CHECK-DAG: stats.cpp:[[@LINE+1]] nvcall.cfi cfi-nvcall 51
31 a->nvf();
34 #else
36 extern "C" __attribute__((noinline)) A *dcast(A *a) {
37 // CHECK-DAG: stats.cpp:[[@LINE+1]] dcast.cfi cfi-derived-cast 24
38 return (A *)(ABase *)a;
41 extern "C" __attribute__((noinline)) A *ucast(A *a) {
42 // CHECK-DAG: stats.cpp:[[@LINE+1]] ucast.cfi cfi-unrelated-cast 81
43 return (A *)(char *)a;
46 extern "C" __attribute__((noinline)) void unreachable(A *a) {
47 // CHECK-NOT: unreachable
48 a->vf();
51 int main() {
52 A a;
53 for (unsigned i = 0; i != 37; ++i)
54 vcall(&a);
55 for (unsigned i = 0; i != 51; ++i)
56 nvcall(&a);
57 for (unsigned i = 0; i != 24; ++i)
58 dcast(&a);
59 for (unsigned i = 0; i != 81; ++i)
60 ucast(&a);
61 for (unsigned i = 0; i != 0; ++i)
62 unreachable(&a);
65 #endif