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