• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: windows-msvc
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 };
f()22 void B::f() {}
23 
create_B()24 void *create_B() {
25   return (void *)(new B());
26 }
27 
28 #else
29 
f()30 void A::f() {}
31 
main(int argc,char * argv[])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
36   // CHECK: check failed in {{.*}}, vtable located in {{.*}}libtarget_uninstrumented.cpp.dynamic.so
37   A *a = (A *)p;
38   memset(p, 0, sizeof(A));
39 
40   // CHECK: runtime error: control flow integrity check for type 'A' failed during cast to unrelated type
41   // CHECK: invalid vtable
42   // CHECK: check failed in {{.*}}, vtable located in (unknown)
43   a = (A *)p;
44   // CHECK: done
45   fprintf(stderr, "done %p\n", a);
46 }
47 #endif
48