1*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi_dso -DSHARED_LIB %s -fPIC -shared -o %t1-so.so 2*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi_dso %s -o %t1 %t1-so.so 3*7c3d14c8STreehugger Robot // RUN: %t1 2>&1 | FileCheck --check-prefix=CFI %s 4*7c3d14c8STreehugger Robot 5*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi_dso -DB32 -DSHARED_LIB %s -fPIC -shared -o %t2-so.so 6*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi_dso -DB32 %s -o %t2 %t2-so.so 7*7c3d14c8STreehugger Robot // RUN: %t2 2>&1 | FileCheck --check-prefix=CFI %s 8*7c3d14c8STreehugger Robot 9*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi_dso -DB64 -DSHARED_LIB %s -fPIC -shared -o %t3-so.so 10*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi_dso -DB64 %s -o %t3 %t3-so.so 11*7c3d14c8STreehugger Robot // RUN: %t3 2>&1 | FileCheck --check-prefix=CFI %s 12*7c3d14c8STreehugger Robot 13*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi_dso -DBM -DSHARED_LIB %s -fPIC -shared -o %t4-so.so 14*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi_dso -DBM %s -o %t4 %t4-so.so 15*7c3d14c8STreehugger Robot // RUN: %t4 2>&1 | FileCheck --check-prefix=CFI %s 16*7c3d14c8STreehugger Robot 17*7c3d14c8STreehugger Robot // RUN: %clangxx -DBM -DSHARED_LIB %s -fPIC -shared -o %t5-so.so 18*7c3d14c8STreehugger Robot // RUN: %clangxx -DBM %s -o %t5 %t5-so.so 19*7c3d14c8STreehugger Robot // RUN: %t5 2>&1 | FileCheck --check-prefix=NCFI %s 20*7c3d14c8STreehugger Robot // RUN: %t5 x 2>&1 | FileCheck --check-prefix=NCFI %s 21*7c3d14c8STreehugger Robot 22*7c3d14c8STreehugger Robot // Tests that the CFI mechanism crashes the program when making a virtual call 23*7c3d14c8STreehugger Robot // to an object of the wrong class but with a compatible vtable, by casting a 24*7c3d14c8STreehugger Robot // pointer to such an object and attempting to make a call through it. 25*7c3d14c8STreehugger Robot 26*7c3d14c8STreehugger Robot // REQUIRES: cxxabi 27*7c3d14c8STreehugger Robot 28*7c3d14c8STreehugger Robot #include <stdio.h> 29*7c3d14c8STreehugger Robot #include <string.h> 30*7c3d14c8STreehugger Robot 31*7c3d14c8STreehugger Robot struct A { 32*7c3d14c8STreehugger Robot virtual void f(); 33*7c3d14c8STreehugger Robot }; 34*7c3d14c8STreehugger Robot 35*7c3d14c8STreehugger Robot A *create_B(); 36*7c3d14c8STreehugger Robot 37*7c3d14c8STreehugger Robot #ifdef SHARED_LIB 38*7c3d14c8STreehugger Robot 39*7c3d14c8STreehugger Robot #include "../utils.h" 40*7c3d14c8STreehugger Robot struct B : public A { 41*7c3d14c8STreehugger Robot virtual void f(); 42*7c3d14c8STreehugger Robot }; f()43*7c3d14c8STreehugger Robotvoid B::f() {} 44*7c3d14c8STreehugger Robot create_B()45*7c3d14c8STreehugger RobotA *create_B() { 46*7c3d14c8STreehugger Robot create_derivers<B>(); 47*7c3d14c8STreehugger Robot return new B(); 48*7c3d14c8STreehugger Robot } 49*7c3d14c8STreehugger Robot 50*7c3d14c8STreehugger Robot #else 51*7c3d14c8STreehugger Robot f()52*7c3d14c8STreehugger Robotvoid A::f() {} 53*7c3d14c8STreehugger Robot main(int argc,char * argv[])54*7c3d14c8STreehugger Robotint main(int argc, char *argv[]) { 55*7c3d14c8STreehugger Robot A *a = create_B(); 56*7c3d14c8STreehugger Robot 57*7c3d14c8STreehugger Robot // CFI: =1= 58*7c3d14c8STreehugger Robot // NCFI: =1= 59*7c3d14c8STreehugger Robot fprintf(stderr, "=1=\n"); 60*7c3d14c8STreehugger Robot a->f(); // OK 61*7c3d14c8STreehugger Robot // CFI: =2= 62*7c3d14c8STreehugger Robot // NCFI: =2= 63*7c3d14c8STreehugger Robot fprintf(stderr, "=2=\n"); 64*7c3d14c8STreehugger Robot } 65*7c3d14c8STreehugger Robot #endif 66