brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · b61adb1 Raw
60 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 mechanism crashes the program when making a non-virtual20// call to an object of the wrong class, by casting a pointer to such an object21// and attempting to make a call through it.22 23// REQUIRES: cxxabi24 25#include <stdio.h>26#include "utils.h"27 28struct A {29  virtual void v();30};31 32void A::v() {}33 34struct B {35  void f();36  virtual void g();37};38 39void B::f() {}40void B::g() {}41 42int main() {43  create_derivers<B>();44 45  A *a = new A;46  break_optimization(a);47 48  // CFI: 149  // NCFI: 150  fprintf(stderr, "1\n");51 52  // CFI-DIAG: runtime error: control flow integrity check for type 'B' failed during non-virtual call53  // CFI-DIAG-NEXT: note: vtable is of type '{{(struct )?}}A'54  ((B *)a)->f(); // UB here55 56  // CFI-NOT: {{^2$}}57  // NCFI: {{^2$}}58  fprintf(stderr, "2\n");59}60