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