1 // RUN: %clangxx_cfi -o %t1 %s
2 // RUN: %expect_crash %run %t1 2>&1 | FileCheck --check-prefix=CFI %s
3 // RUN: %expect_crash %run %t1 x 2>&1 | FileCheck --check-prefix=CFI %s
5 // RUN: %clangxx_cfi -DB32 -o %t2 %s
6 // RUN: %expect_crash %run %t2 2>&1 | FileCheck --check-prefix=CFI %s
7 // RUN: %expect_crash %run %t2 x 2>&1 | FileCheck --check-prefix=CFI %s
9 // RUN: %clangxx_cfi -DB64 -o %t3 %s
10 // RUN: %expect_crash %run %t3 2>&1 | FileCheck --check-prefix=CFI %s
11 // RUN: %expect_crash %run %t3 x 2>&1 | FileCheck --check-prefix=CFI %s
13 // RUN: %clangxx_cfi -DBM -o %t4 %s
14 // RUN: %expect_crash %run %t4 2>&1 | FileCheck --check-prefix=CFI %s
15 // RUN: %expect_crash %run %t4 x 2>&1 | FileCheck --check-prefix=CFI %s
17 // RUN: %clangxx -o %t5 %s
18 // RUN: %run %t5 2>&1 | FileCheck --check-prefix=NCFI %s
19 // RUN: %run %t5 x 2>&1 | FileCheck --check-prefix=NCFI %s
21 // RUN: %clangxx_cfi_diag -o %t6 %s
22 // RUN: %run %t6 2>&1 | FileCheck --check-prefix=CFI-DIAG2 %s
23 // RUN: %run %t6 x 2>&1 | FileCheck --check-prefix=CFI-DIAG1 %s
25 // Tests that the CFI mechanism is sensitive to multiple inheritance and only
26 // permits calls via virtual tables for the correct base class.
42 virtual void f(), g();
48 int main(int argc
, char **argv
) {
53 break_optimization(c
);
57 fprintf(stderr
, "1\n");
61 // CFI-DIAG1: runtime error: control flow integrity check for type 'B' failed during cast to unrelated type
62 // CFI-DIAG1-NEXT: note: vtable is of type '{{(struct )?}}C'
63 ((B
*)a
)->g(); // UB here
65 // CFI-DIAG2: runtime error: control flow integrity check for type 'A' failed during cast to unrelated type
66 // CFI-DIAG2-NEXT: note: vtable is of type '{{(struct )?}}C'
68 ((A
*)b
)->f(); // UB here
73 fprintf(stderr
, "2\n");