2018-03-10 04:41:56 +08:00
|
|
|
// -mretpoline does not work yet on Darwin.
|
|
|
|
// XFAIL: darwin
|
|
|
|
|
2015-02-21 04:31:18 +08:00
|
|
|
// RUN: %clangxx_cfi -o %t %s
|
2017-10-02 18:21:26 +08:00
|
|
|
// RUN: %run %t
|
2018-03-10 03:11:44 +08:00
|
|
|
// RUN: %clangxx_cfi -mretpoline -o %t2 %s
|
|
|
|
// RUN: %run %t2
|
2015-02-21 04:31:18 +08:00
|
|
|
|
|
|
|
// Tests that the CFI mechanism does not crash the program when making various
|
|
|
|
// kinds of valid calls involving classes with various different linkages and
|
2015-04-02 08:33:36 +08:00
|
|
|
// types of inheritance, and both virtual and non-virtual member functions.
|
2015-02-21 04:31:18 +08:00
|
|
|
|
2015-02-21 09:36:08 +08:00
|
|
|
#include "utils.h"
|
2015-02-21 04:31:18 +08:00
|
|
|
|
|
|
|
struct A {
|
|
|
|
virtual void f();
|
2015-04-02 08:33:36 +08:00
|
|
|
void g();
|
2015-02-21 04:31:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void A::f() {}
|
2015-04-02 08:33:36 +08:00
|
|
|
void A::g() {}
|
2015-02-21 04:31:18 +08:00
|
|
|
|
|
|
|
struct A2 : A {
|
|
|
|
virtual void f();
|
2015-04-02 08:33:36 +08:00
|
|
|
void g();
|
2015-02-21 04:31:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void A2::f() {}
|
2015-04-02 08:33:36 +08:00
|
|
|
void A2::g() {}
|
2015-02-21 04:31:18 +08:00
|
|
|
|
|
|
|
struct B {
|
|
|
|
virtual void f() {}
|
2015-04-02 08:33:36 +08:00
|
|
|
void g() {}
|
2015-02-21 04:31:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct B2 : B {
|
|
|
|
virtual void f() {}
|
2015-04-02 08:33:36 +08:00
|
|
|
void g() {}
|
2015-02-21 04:31:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct C {
|
|
|
|
virtual void f();
|
2015-04-02 08:33:36 +08:00
|
|
|
void g();
|
2015-02-21 04:31:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void C::f() {}
|
2015-04-02 08:33:36 +08:00
|
|
|
void C::g() {}
|
2015-02-21 04:31:18 +08:00
|
|
|
|
|
|
|
struct C2 : C {
|
|
|
|
virtual void f();
|
2015-04-02 08:33:36 +08:00
|
|
|
void g();
|
2015-02-21 04:31:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void C2::f() {}
|
2015-04-02 08:33:36 +08:00
|
|
|
void C2::g() {}
|
2015-02-21 04:31:18 +08:00
|
|
|
|
|
|
|
struct D {
|
|
|
|
virtual void f() {}
|
2015-04-02 08:33:36 +08:00
|
|
|
void g() {}
|
2015-02-21 04:31:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct D2 : D {
|
|
|
|
virtual void f() {}
|
2015-04-02 08:33:36 +08:00
|
|
|
void g() {}
|
2015-02-21 04:31:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct E {
|
|
|
|
virtual void f() {}
|
2015-04-02 08:33:36 +08:00
|
|
|
void g() {}
|
2015-02-21 04:31:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct E2 : virtual E {
|
|
|
|
virtual void f() {}
|
2015-04-02 08:33:36 +08:00
|
|
|
void g() {}
|
2015-02-21 04:31:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
A *a = new A;
|
|
|
|
break_optimization(a);
|
|
|
|
a->f();
|
2015-04-02 08:33:36 +08:00
|
|
|
a->g();
|
2015-02-21 04:31:18 +08:00
|
|
|
a = new A2;
|
|
|
|
break_optimization(a);
|
|
|
|
a->f();
|
2015-04-02 08:33:36 +08:00
|
|
|
a->g();
|
2015-02-21 04:31:18 +08:00
|
|
|
|
|
|
|
B *b = new B;
|
|
|
|
break_optimization(b);
|
|
|
|
b->f();
|
2015-04-02 08:33:36 +08:00
|
|
|
b->g();
|
2015-02-21 04:31:18 +08:00
|
|
|
b = new B2;
|
|
|
|
break_optimization(b);
|
|
|
|
b->f();
|
2015-04-02 08:33:36 +08:00
|
|
|
b->g();
|
2015-02-21 04:31:18 +08:00
|
|
|
|
|
|
|
C *c = new C;
|
|
|
|
break_optimization(c);
|
|
|
|
c->f();
|
2015-04-02 08:33:36 +08:00
|
|
|
c->g();
|
2015-02-21 04:31:18 +08:00
|
|
|
c = new C2;
|
|
|
|
break_optimization(c);
|
|
|
|
c->f();
|
2015-04-02 08:33:36 +08:00
|
|
|
c->g();
|
2015-02-21 04:31:18 +08:00
|
|
|
|
|
|
|
D *d = new D;
|
|
|
|
break_optimization(d);
|
|
|
|
d->f();
|
2015-04-02 08:33:36 +08:00
|
|
|
d->g();
|
2015-02-21 04:31:18 +08:00
|
|
|
d = new D2;
|
|
|
|
break_optimization(d);
|
|
|
|
d->f();
|
2015-04-02 08:33:36 +08:00
|
|
|
d->g();
|
2015-02-21 04:31:18 +08:00
|
|
|
|
|
|
|
E *e = new E;
|
|
|
|
break_optimization(e);
|
|
|
|
e->f();
|
2015-04-02 08:33:36 +08:00
|
|
|
e->g();
|
2015-02-21 04:31:18 +08:00
|
|
|
e = new E2;
|
|
|
|
break_optimization(e);
|
|
|
|
e->f();
|
2015-04-02 08:33:36 +08:00
|
|
|
e->g();
|
2015-02-21 04:31:18 +08:00
|
|
|
}
|