1 // RUN: %clangxx -g -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so 2 // RUN: %clangxx_cfi_diag -g %s -o %t %ld_flags_rpath_exe 3 // RUN: %run %t 2>&1 | FileCheck %s 4 5 // REQUIRES: cxxabi 6 // UNSUPPORTED: win32 7 8 #include <stdio.h> 9 #include <string.h> 10 11 struct A { 12 virtual void f(); 13 }; 14 15 void *create_B(); 16 17 #ifdef SHARED_LIB 18 19 struct B { 20 virtual void f(); 21 }; 22 void B::f() {} 23 24 void *create_B() { 25 return (void *)(new B()); 26 } 27 28 #else 29 30 void A::f() {} 31 32 int main(int argc, char *argv[]) { 33 void *p = create_B(); 34 // CHECK: runtime error: control flow integrity check for type 'A' failed during cast to unrelated type 35 // CHECK: invalid vtable in module {{.*}}libtarget_uninstrumented.cpp.dynamic.so 36 A *a = (A *)p; 37 memset(p, 0, sizeof(A)); 38 // CHECK: runtime error: control flow integrity check for type 'A' failed during cast to unrelated type 39 // CHECK-NOT: invalid vtable in module 40 // CHECK: invalid vtable 41 a = (A *)p; 42 // CHECK: done 43 fprintf(stderr, "done %p\n", a); 44 } 45 #endif 46