]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/test/cfi/cross-dso/icall/icall-from-dso.cpp
New upstream version 1.12.0+dfsg1
[rustc.git] / src / compiler-rt / test / cfi / cross-dso / icall / icall-from-dso.cpp
CommitLineData
3157f602
XL
1// RUN: %clangxx_cfi_dso -DSHARED_LIB %s -fPIC -shared -o %t-so.so
2// RUN: %clangxx_cfi_dso %s -o %t %t-so.so && %expect_crash %t 2>&1 | FileCheck %s
3
5bcae85e
SL
4// RUN: %clangxx_cfi_dso_diag -g -DSHARED_LIB %s -fPIC -shared -o %t2-so.so
5// RUN: %clangxx_cfi_dso_diag -g %s -o %t2 %t2-so.so && %t2 2>&1 | FileCheck %s --check-prefix=CFI-DIAG
6
3157f602
XL
7#include <stdio.h>
8
9#ifdef SHARED_LIB
10void g();
11void f() {
5bcae85e 12 // CHECK-DIAG: =1=
3157f602
XL
13 // CHECK: =1=
14 fprintf(stderr, "=1=\n");
15 ((void (*)(void))g)();
5bcae85e 16 // CHECK-DIAG: =2=
3157f602
XL
17 // CHECK: =2=
18 fprintf(stderr, "=2=\n");
5bcae85e
SL
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
3157f602 21 ((void (*)(int))g)(42); // UB here
5bcae85e 22 // CHECK-DIAG: =3=
3157f602
XL
23 // CHECK-NOT: =3=
24 fprintf(stderr, "=3=\n");
25}
26#else
27void f();
28void g() {
29}
30
31int main() {
32 f();
33}
34#endif