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 g(); |
11 | void f() { |
12 | // CHECK-DIAG: =1= |
13 | // CHECK: =1= |
14 | fprintf(stderr, "=1=\n" ); |
15 | ((void (*)(void))g)(); |
16 | // CHECK-DIAG: =2= |
17 | // CHECK: =2= |
18 | fprintf(stderr, "=2=\n" ); |
19 | // CFI-DIAG: runtime error: control flow integrity check for type 'void (int)' failed during indirect function call |
20 | // CFI-DIAG-NEXT: note: g() defined here |
21 | ((void (*)(int))g)(42); // UB here |
22 | // CHECK-DIAG: =3= |
23 | // CHECK-NOT: =3= |
24 | fprintf(stderr, "=3=\n" ); |
25 | } |
26 | #else |
27 | void f(); |
28 | void g() { |
29 | } |
30 | |
31 | int main() { |
32 | f(); |
33 | } |
34 | #endif |
35 | |