1 // RUN: %clangxx_cfi -o %t %s
2 // RUN: not --crash %t 2>&1 | FileCheck --check-prefix=CFI %s
3 
4 // RUN: %clangxx -o %t %s
5 // RUN: %t 2>&1 | FileCheck --check-prefix=NCFI %s
6 
7 // Tests that the CFI enforcement also applies to virtual destructor calls made
8 // via 'delete'.
9 
10 #include <stdio.h>
11 
12 struct A {
13   virtual ~A();
14 };
15 
16 A::~A() {}
17 
18 struct B {
19   virtual ~B();
20 };
21 
22 B::~B() {}
23 
24 int main() {
25   A *a = new A;
26 
27   // CFI: 1
28   // NCFI: 1
29   fprintf(stderr, "1\n");
30 
31   delete (B *)a; // UB here
32 
33   // CFI-NOT: 2
34   // NCFI: 2
35   fprintf(stderr, "2\n");
36 }
37