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