1 // -mretpoline does not work yet on Darwin. 2 // XFAIL: darwin 3 4 // RUN: %clangxx_cfi -o %t %s 5 // RUN: %run %t 6 // RUN: %clangxx_cfi -mretpoline -o %t2 %s 7 // RUN: %run %t2 8 9 // Tests that the CFI mechanism does not crash the program when making various 10 // kinds of valid calls involving classes with various different linkages and 11 // types of inheritance, and both virtual and non-virtual member functions. 12 13 #include "utils.h" 14 15 struct A { 16 virtual void f(); 17 void g(); 18 }; 19 f()20void A::f() {} g()21void A::g() {} 22 23 struct A2 : A { 24 virtual void f(); 25 void g(); 26 }; 27 f()28void A2::f() {} g()29void A2::g() {} 30 31 struct B { fB32 virtual void f() {} gB33 void g() {} 34 }; 35 36 struct B2 : B { fB237 virtual void f() {} gB238 void g() {} 39 }; 40 41 namespace { 42 43 struct C { 44 virtual void f(); 45 void g(); 46 }; 47 f()48void C::f() {} g()49void C::g() {} 50 51 struct C2 : C { 52 virtual void f(); 53 void g(); 54 }; 55 f()56void C2::f() {} g()57void C2::g() {} 58 59 struct D { f__anon884c4ff20111::D60 virtual void f() {} g__anon884c4ff20111::D61 void g() {} 62 }; 63 64 struct D2 : D { f__anon884c4ff20111::D265 virtual void f() {} g__anon884c4ff20111::D266 void g() {} 67 }; 68 69 } 70 71 struct E { fE72 virtual void f() {} gE73 void g() {} 74 }; 75 76 struct E2 : virtual E { fE277 virtual void f() {} gE278 void g() {} 79 }; 80 main()81int main() { 82 A *a = new A; 83 break_optimization(a); 84 a->f(); 85 a->g(); 86 a = new A2; 87 break_optimization(a); 88 a->f(); 89 a->g(); 90 91 B *b = new B; 92 break_optimization(b); 93 b->f(); 94 b->g(); 95 b = new B2; 96 break_optimization(b); 97 b->f(); 98 b->g(); 99 100 C *c = new C; 101 break_optimization(c); 102 c->f(); 103 c->g(); 104 c = new C2; 105 break_optimization(c); 106 c->f(); 107 c->g(); 108 109 D *d = new D; 110 break_optimization(d); 111 d->f(); 112 d->g(); 113 d = new D2; 114 break_optimization(d); 115 d->f(); 116 d->g(); 117 118 E *e = new E; 119 break_optimization(e); 120 e->f(); 121 e->g(); 122 e = new E2; 123 break_optimization(e); 124 e->f(); 125 e->g(); 126 } 127