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
11struct A {
12 virtual void f();
13};
14
15void *create_B();
16
17#ifdef SHARED_LIB
18
19struct B {
20 virtual void f();
21};
22void B::f() {}
23
24void *create_B() {
25 return (void *)(new B());
26}
27
28#else
29
30void A::f() {}
31
32int 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