1*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi_dso -DSHARED_LIB %s -fPIC -shared -o %t-so.so 2*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi_dso %s -o %t %t-so.so && %expect_crash %t 2>&1 | FileCheck %s 3*7c3d14c8STreehugger Robot 4*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi_dso_diag -g -DSHARED_LIB %s -fPIC -shared -o %t2-so.so 5*7c3d14c8STreehugger Robot // RUN: %clangxx_cfi_dso_diag -g %s -o %t2 %t2-so.so && %t2 2>&1 | FileCheck %s --check-prefix=CFI-DIAG 6*7c3d14c8STreehugger Robot 7*7c3d14c8STreehugger Robot #include <stdio.h> 8*7c3d14c8STreehugger Robot 9*7c3d14c8STreehugger Robot #ifdef SHARED_LIB f()10*7c3d14c8STreehugger Robotvoid f() { 11*7c3d14c8STreehugger Robot } 12*7c3d14c8STreehugger Robot #else 13*7c3d14c8STreehugger Robot void f(); main()14*7c3d14c8STreehugger Robotint main() { 15*7c3d14c8STreehugger Robot // CHECK-DIAG: =1= 16*7c3d14c8STreehugger Robot // CHECK: =1= 17*7c3d14c8STreehugger Robot fprintf(stderr, "=1=\n"); 18*7c3d14c8STreehugger Robot ((void (*)(void))f)(); 19*7c3d14c8STreehugger Robot // CHECK-DIAG: =2= 20*7c3d14c8STreehugger Robot // CHECK: =2= 21*7c3d14c8STreehugger Robot fprintf(stderr, "=2=\n"); 22*7c3d14c8STreehugger Robot // CFI-DIAG: runtime error: control flow integrity check for type 'void (int)' failed during indirect function call 23*7c3d14c8STreehugger Robot // CFI-DIAG-NEXT: note: f() defined here 24*7c3d14c8STreehugger Robot ((void (*)(int))f)(42); // UB here 25*7c3d14c8STreehugger Robot // CHECK-DIAG: =3= 26*7c3d14c8STreehugger Robot // CHECK-NOT: =3= 27*7c3d14c8STreehugger Robot fprintf(stderr, "=3=\n"); 28*7c3d14c8STreehugger Robot } 29*7c3d14c8STreehugger Robot #endif 30