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