1// XFAIL: *
2
3// RUN: %clangxx_cfi -o %t1 %s
4// RUN: %expect_crash %run %t1 2>&1 | FileCheck --check-prefix=CFI %s
5
6// RUN: %clangxx_cfi -DB32 -o %t2 %s
7// RUN: %expect_crash %run %t2 2>&1 | FileCheck --check-prefix=CFI %s
8
9// RUN: %clangxx_cfi -DB64 -o %t3 %s
10// RUN: %expect_crash %run %t3 2>&1 | FileCheck --check-prefix=CFI %s
11
12// RUN: %clangxx_cfi -DBM -o %t4 %s
13// RUN: %expect_crash %run %t4 2>&1 | FileCheck --check-prefix=CFI %s
14
15// RUN: %clangxx -o %t5 %s
16// RUN: %run %t5 2>&1 | FileCheck --check-prefix=NCFI %s
17
18// Tests that the CFI enforcement distinguishes between non-overriding siblings.
19// XFAILed as not implemented yet.
20
21#include <stdio.h>
22#include "utils.h"
23
24struct A {
25 virtual void f();
26};
27
28void A::f() {}
29
30struct B : A {
31 virtual void f();
32};
33
34void B::f() {}
35
36struct C : A {
37};
38
39int main() {
40 create_derivers<B>();
41
42 B *b = new B;
43 break_optimization(arg: b);
44
45 // CFI: 1
46 // NCFI: 1
47 fprintf(stderr, format: "1\n");
48
49 ((C *)b)->f(); // UB here
50
51 // CFI-NOT: 2
52 // NCFI: 2
53 fprintf(stderr, format: "2\n");
54}
55

source code of compiler-rt/test/cfi/sibling.cpp