brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · defa4ce Raw
57 lines · cpp
1// RUN: %clangxx_cfi -o %t1 %s2// RUN: %expect_crash %run %t1 2>&1 | FileCheck --check-prefix=CFI %s3 4// RUN: %clangxx_cfi -DB32 -o %t2 %s5// RUN: %expect_crash %run %t2 2>&1 | FileCheck --check-prefix=CFI %s6 7// RUN: %clangxx_cfi -DB64 -o %t3 %s8// RUN: %expect_crash %run %t3 2>&1 | FileCheck --check-prefix=CFI %s9 10// RUN: %clangxx_cfi -DBM -o %t4 %s11// RUN: %expect_crash %run %t4 2>&1 | FileCheck --check-prefix=CFI %s12 13// RUN: %clangxx -o %t5 %s14// RUN: %run %t5 2>&1 | FileCheck --check-prefix=NCFI %s15 16// RUN: %clangxx_cfi_diag -o %t6 %s17// RUN: %run %t6 2>&1 | FileCheck --check-prefix=CFI-DIAG %s18 19// Tests that the CFI enforcement also applies to virtual destructor calls made20// via 'delete'.21 22// REQUIRES: cxxabi23 24#include <stdio.h>25#include "utils.h"26 27struct A {28  virtual ~A();29};30 31A::~A() {}32 33struct B {34  virtual ~B();35};36 37B::~B() {}38 39int main() {40  create_derivers<B>();41 42  A *a = new A;43  break_optimization(a);44 45  // CFI: 146  // NCFI: 147  fprintf(stderr, "1\n");48 49  // CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during virtual call50  // CFI-DIAG-NEXT: note: vtable is of type '{{(struct )?}}A'51  delete (B *)a; // UB here52 53  // CFI-NOT: {{^2$}}54  // NCFI: {{^2$}}55  fprintf(stderr, "2\n");56}57