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
3 // RUN: %expect_crash %t 2>&1 | FileCheck --check-prefix=CFI %s
4 // RUN: %expect_crash %t x 2>&1 | FileCheck --check-prefix=CFI-CAST %s
6 // RUN: %clangxx_cfi_dso -DB32 -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
7 // RUN: %clangxx_cfi_dso -DB32 %s -o %t %ld_flags_rpath_exe
8 // RUN: %expect_crash %t 2>&1 | FileCheck --check-prefix=CFI %s
9 // RUN: %expect_crash %t x 2>&1 | FileCheck --check-prefix=CFI-CAST %s
11 // RUN: %clangxx_cfi_dso -DB64 -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
12 // RUN: %clangxx_cfi_dso -DB64 %s -o %t %ld_flags_rpath_exe
13 // RUN: %expect_crash %t 2>&1 | FileCheck --check-prefix=CFI %s
14 // RUN: %expect_crash %t x 2>&1 | FileCheck --check-prefix=CFI-CAST %s
16 // RUN: %clangxx_cfi_dso -DBM -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
17 // RUN: %clangxx_cfi_dso -DBM %s -o %t %ld_flags_rpath_exe
18 // RUN: %expect_crash %t 2>&1 | FileCheck --check-prefix=CFI %s
19 // RUN: %expect_crash %t x 2>&1 | FileCheck --check-prefix=CFI-CAST %s
21 // RUN: %clangxx -DBM -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
22 // RUN: %clangxx -DBM %s -o %t %ld_flags_rpath_exe
23 // RUN: %t 2>&1 | FileCheck --check-prefix=NCFI %s
24 // RUN: %t x 2>&1 | FileCheck --check-prefix=NCFI %s
26 // RUN: %clangxx -DBM -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
27 // RUN: %clangxx_cfi_dso -DBM %s -o %t %ld_flags_rpath_exe
28 // RUN: %t 2>&1 | FileCheck --check-prefix=NCFI %s
29 // RUN: %t x 2>&1 | FileCheck --check-prefix=NCFI %s
31 // RUN: %clangxx_cfi_dso_diag -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
32 // RUN: %clangxx_cfi_dso_diag %s -o %t %ld_flags_rpath_exe
33 // RUN: %t 2>&1 | FileCheck --check-prefix=CFI-DIAG-CALL %s
34 // RUN: %t x 2>&1 | FileCheck --check-prefix=CFI-DIAG-CALL --check-prefix=CFI-DIAG-CAST %s
36 // Tests that the CFI mechanism crashes the program when making a virtual call
37 // to an object of the wrong class but with a compatible vtable, by casting a
38 // pointer to such an object and attempting to make a call through it.
61 return (void *)(new B());
68 int main(int argc
, char *argv
[]) {
75 fprintf(stderr
, "=0=\n");
77 if (argc
> 1 && argv
[1][0] == 'x') {
79 // CFI-DIAG-CAST: runtime error: control flow integrity check for type 'A' failed during cast to unrelated type
80 // CFI-DIAG-CAST-NEXT: note: vtable is of type '{{(struct )?}}B'
83 // Invisible to CFI. Test virtual call later.
84 memcpy(&a
, &p
, sizeof(a
));
90 fprintf(stderr
, "=1=\n");
92 // CFI-DIAG-CALL: runtime error: control flow integrity check for type 'A' failed during virtual call
93 // CFI-DIAG-CALL-NEXT: note: vtable is of type '{{(struct )?}}B'
99 fprintf(stderr
, "=2=\n");