xref: /aosp_15_r20/external/compiler-rt/test/cfi/stats.cpp (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi -g -fsanitize-stats -o %t %s
2*7c3d14c8STreehugger Robot // RUN: env SANITIZER_STATS_PATH=%t.stats %t
3*7c3d14c8STreehugger Robot // RUN: sanstats %t.stats | FileCheck %s
4*7c3d14c8STreehugger Robot 
5*7c3d14c8STreehugger Robot // FIXME: We currently emit the wrong debug info under devirtualization.
6*7c3d14c8STreehugger Robot // UNSUPPORTED: devirt
7*7c3d14c8STreehugger Robot 
8*7c3d14c8STreehugger Robot struct ABase {};
9*7c3d14c8STreehugger Robot 
10*7c3d14c8STreehugger Robot struct A : ABase {
vfA11*7c3d14c8STreehugger Robot   virtual void vf() {}
nvfA12*7c3d14c8STreehugger Robot   void nvf() {}
13*7c3d14c8STreehugger Robot };
14*7c3d14c8STreehugger Robot 
vcall(A * a)15*7c3d14c8STreehugger Robot extern "C" __attribute__((noinline)) void vcall(A *a) {
16*7c3d14c8STreehugger Robot   // CHECK: stats.cpp:[[@LINE+1]] {{_?}}vcall cfi-vcall 37
17*7c3d14c8STreehugger Robot   a->vf();
18*7c3d14c8STreehugger Robot }
19*7c3d14c8STreehugger Robot 
nvcall(A * a)20*7c3d14c8STreehugger Robot extern "C" __attribute__((noinline)) void nvcall(A *a) {
21*7c3d14c8STreehugger Robot   // CHECK: stats.cpp:[[@LINE+1]] {{_?}}nvcall cfi-nvcall 51
22*7c3d14c8STreehugger Robot   a->nvf();
23*7c3d14c8STreehugger Robot }
24*7c3d14c8STreehugger Robot 
dcast(A * a)25*7c3d14c8STreehugger Robot extern "C" __attribute__((noinline)) A *dcast(A *a) {
26*7c3d14c8STreehugger Robot   // CHECK: stats.cpp:[[@LINE+1]] {{_?}}dcast cfi-derived-cast 24
27*7c3d14c8STreehugger Robot   return (A *)(ABase *)a;
28*7c3d14c8STreehugger Robot }
29*7c3d14c8STreehugger Robot 
ucast(A * a)30*7c3d14c8STreehugger Robot extern "C" __attribute__((noinline)) A *ucast(A *a) {
31*7c3d14c8STreehugger Robot   // CHECK: stats.cpp:[[@LINE+1]] {{_?}}ucast cfi-unrelated-cast 81
32*7c3d14c8STreehugger Robot   return (A *)(char *)a;
33*7c3d14c8STreehugger Robot }
34*7c3d14c8STreehugger Robot 
unreachable(A * a)35*7c3d14c8STreehugger Robot extern "C" __attribute__((noinline)) void unreachable(A *a) {
36*7c3d14c8STreehugger Robot   // CHECK-NOT: unreachable
37*7c3d14c8STreehugger Robot   a->vf();
38*7c3d14c8STreehugger Robot }
39*7c3d14c8STreehugger Robot 
main()40*7c3d14c8STreehugger Robot int main() {
41*7c3d14c8STreehugger Robot   A a;
42*7c3d14c8STreehugger Robot   for (unsigned i = 0; i != 37; ++i)
43*7c3d14c8STreehugger Robot     vcall(&a);
44*7c3d14c8STreehugger Robot   for (unsigned i = 0; i != 51; ++i)
45*7c3d14c8STreehugger Robot     nvcall(&a);
46*7c3d14c8STreehugger Robot   for (unsigned i = 0; i != 24; ++i)
47*7c3d14c8STreehugger Robot     dcast(&a);
48*7c3d14c8STreehugger Robot   for (unsigned i = 0; i != 81; ++i)
49*7c3d14c8STreehugger Robot     ucast(&a);
50*7c3d14c8STreehugger Robot   for (unsigned i = 0; i != 0; ++i)
51*7c3d14c8STreehugger Robot     unreachable(&a);
52*7c3d14c8STreehugger Robot }
53