brintos

brintos / llvm-project-archived public Read only

0
0
Text · 974 B · b4ee48d Raw
31 lines · cpp
1// RUN: mkdir -p %t.dir && cd %t.dir2// RUN: %clangxx_cfi_dso -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so3// RUN: %clangxx_cfi_dso %s -o %t.dir/exe %ld_flags_rpath_exe && %expect_crash %t.dir/exe 2>&1 | FileCheck %s4 5// RUN: %clangxx_cfi_dso_diag -g -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so6// RUN: %clangxx_cfi_dso_diag -g %s -o %t.dir/exe %ld_flags_rpath_exe && %t.dir/exe 2>&1 | FileCheck %s --check-prefix=CFI-DIAG7 8#include <stdio.h>9 10#ifdef SHARED_LIB11void f() {12}13#else14void f();15int main() {16  // CHECK-DIAG: =1=17  // CHECK: =1=18  fprintf(stderr, "=1=\n");19  ((void (*)(void))f)();20  // CHECK-DIAG: =2=21  // CHECK: =2=22  fprintf(stderr, "=2=\n");23  // CFI-DIAG: runtime error: control flow integrity check for type 'void (int)' failed during indirect function call24  // CFI-DIAG-NEXT: note: f() defined here25  ((void (*)(int))f)(42); // UB here26  // CHECK-DIAG: =3=27  // CHECK-NOT: =3=28  fprintf(stderr, "=3=\n");29}30#endif31