1*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi -o %t %s 2*7c3d14c8STreehugger Robot // RUN: %t 3*7c3d14c8STreehugger Robot 4*7c3d14c8STreehugger Robot // Tests that the CFI mechanism does not crash the program when making various 5*7c3d14c8STreehugger Robot // kinds of valid calls involving classes with various different linkages and 6*7c3d14c8STreehugger Robot // types of inheritance, and both virtual and non-virtual member functions. 7*7c3d14c8STreehugger Robot 8*7c3d14c8STreehugger Robot #include "utils.h" 9*7c3d14c8STreehugger Robot 10*7c3d14c8STreehugger Robot struct A { 11*7c3d14c8STreehugger Robot virtual void f(); 12*7c3d14c8STreehugger Robot void g(); 13*7c3d14c8STreehugger Robot }; 14*7c3d14c8STreehugger Robot f()15*7c3d14c8STreehugger Robotvoid A::f() {} g()16*7c3d14c8STreehugger Robotvoid A::g() {} 17*7c3d14c8STreehugger Robot 18*7c3d14c8STreehugger Robot struct A2 : A { 19*7c3d14c8STreehugger Robot virtual void f(); 20*7c3d14c8STreehugger Robot void g(); 21*7c3d14c8STreehugger Robot }; 22*7c3d14c8STreehugger Robot f()23*7c3d14c8STreehugger Robotvoid A2::f() {} g()24*7c3d14c8STreehugger Robotvoid A2::g() {} 25*7c3d14c8STreehugger Robot 26*7c3d14c8STreehugger Robot struct B { fB27*7c3d14c8STreehugger Robot virtual void f() {} gB28*7c3d14c8STreehugger Robot void g() {} 29*7c3d14c8STreehugger Robot }; 30*7c3d14c8STreehugger Robot 31*7c3d14c8STreehugger Robot struct B2 : B { fB232*7c3d14c8STreehugger Robot virtual void f() {} gB233*7c3d14c8STreehugger Robot void g() {} 34*7c3d14c8STreehugger Robot }; 35*7c3d14c8STreehugger Robot 36*7c3d14c8STreehugger Robot namespace { 37*7c3d14c8STreehugger Robot 38*7c3d14c8STreehugger Robot struct C { 39*7c3d14c8STreehugger Robot virtual void f(); 40*7c3d14c8STreehugger Robot void g(); 41*7c3d14c8STreehugger Robot }; 42*7c3d14c8STreehugger Robot f()43*7c3d14c8STreehugger Robotvoid C::f() {} g()44*7c3d14c8STreehugger Robotvoid C::g() {} 45*7c3d14c8STreehugger Robot 46*7c3d14c8STreehugger Robot struct C2 : C { 47*7c3d14c8STreehugger Robot virtual void f(); 48*7c3d14c8STreehugger Robot void g(); 49*7c3d14c8STreehugger Robot }; 50*7c3d14c8STreehugger Robot f()51*7c3d14c8STreehugger Robotvoid C2::f() {} g()52*7c3d14c8STreehugger Robotvoid C2::g() {} 53*7c3d14c8STreehugger Robot 54*7c3d14c8STreehugger Robot struct D { f__anond6951ef30111::D55*7c3d14c8STreehugger Robot virtual void f() {} g__anond6951ef30111::D56*7c3d14c8STreehugger Robot void g() {} 57*7c3d14c8STreehugger Robot }; 58*7c3d14c8STreehugger Robot 59*7c3d14c8STreehugger Robot struct D2 : D { f__anond6951ef30111::D260*7c3d14c8STreehugger Robot virtual void f() {} g__anond6951ef30111::D261*7c3d14c8STreehugger Robot void g() {} 62*7c3d14c8STreehugger Robot }; 63*7c3d14c8STreehugger Robot 64*7c3d14c8STreehugger Robot } 65*7c3d14c8STreehugger Robot 66*7c3d14c8STreehugger Robot struct E { fE67*7c3d14c8STreehugger Robot virtual void f() {} gE68*7c3d14c8STreehugger Robot void g() {} 69*7c3d14c8STreehugger Robot }; 70*7c3d14c8STreehugger Robot 71*7c3d14c8STreehugger Robot struct E2 : virtual E { fE272*7c3d14c8STreehugger Robot virtual void f() {} gE273*7c3d14c8STreehugger Robot void g() {} 74*7c3d14c8STreehugger Robot }; 75*7c3d14c8STreehugger Robot main()76*7c3d14c8STreehugger Robotint main() { 77*7c3d14c8STreehugger Robot A *a = new A; 78*7c3d14c8STreehugger Robot break_optimization(a); 79*7c3d14c8STreehugger Robot a->f(); 80*7c3d14c8STreehugger Robot a->g(); 81*7c3d14c8STreehugger Robot a = new A2; 82*7c3d14c8STreehugger Robot break_optimization(a); 83*7c3d14c8STreehugger Robot a->f(); 84*7c3d14c8STreehugger Robot a->g(); 85*7c3d14c8STreehugger Robot 86*7c3d14c8STreehugger Robot B *b = new B; 87*7c3d14c8STreehugger Robot break_optimization(b); 88*7c3d14c8STreehugger Robot b->f(); 89*7c3d14c8STreehugger Robot b->g(); 90*7c3d14c8STreehugger Robot b = new B2; 91*7c3d14c8STreehugger Robot break_optimization(b); 92*7c3d14c8STreehugger Robot b->f(); 93*7c3d14c8STreehugger Robot b->g(); 94*7c3d14c8STreehugger Robot 95*7c3d14c8STreehugger Robot C *c = new C; 96*7c3d14c8STreehugger Robot break_optimization(c); 97*7c3d14c8STreehugger Robot c->f(); 98*7c3d14c8STreehugger Robot c->g(); 99*7c3d14c8STreehugger Robot c = new C2; 100*7c3d14c8STreehugger Robot break_optimization(c); 101*7c3d14c8STreehugger Robot c->f(); 102*7c3d14c8STreehugger Robot c->g(); 103*7c3d14c8STreehugger Robot 104*7c3d14c8STreehugger Robot D *d = new D; 105*7c3d14c8STreehugger Robot break_optimization(d); 106*7c3d14c8STreehugger Robot d->f(); 107*7c3d14c8STreehugger Robot d->g(); 108*7c3d14c8STreehugger Robot d = new D2; 109*7c3d14c8STreehugger Robot break_optimization(d); 110*7c3d14c8STreehugger Robot d->f(); 111*7c3d14c8STreehugger Robot d->g(); 112*7c3d14c8STreehugger Robot 113*7c3d14c8STreehugger Robot E *e = new E; 114*7c3d14c8STreehugger Robot break_optimization(e); 115*7c3d14c8STreehugger Robot e->f(); 116*7c3d14c8STreehugger Robot e->g(); 117*7c3d14c8STreehugger Robot e = new E2; 118*7c3d14c8STreehugger Robot break_optimization(e); 119*7c3d14c8STreehugger Robot e->f(); 120*7c3d14c8STreehugger Robot e->g(); 121*7c3d14c8STreehugger Robot } 122