brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · b8520d8 Raw
75 lines · cpp
1// RUN: %clangxx_cfi -o %t1 %s2// RUN: %expect_crash %run %t1 2>&1 | FileCheck --check-prefix=CFI %s3// RUN: %expect_crash %run %t1 x 2>&1 | FileCheck --check-prefix=CFI %s4 5// RUN: %clangxx_cfi -DB32 -o %t2 %s6// RUN: %expect_crash %run %t2 2>&1 | FileCheck --check-prefix=CFI %s7// RUN: %expect_crash %run %t2 x 2>&1 | FileCheck --check-prefix=CFI %s8 9// RUN: %clangxx_cfi -DB64 -o %t3 %s10// RUN: %expect_crash %run %t3 2>&1 | FileCheck --check-prefix=CFI %s11// RUN: %expect_crash %run %t3 x 2>&1 | FileCheck --check-prefix=CFI %s12 13// RUN: %clangxx_cfi -DBM -o %t4 %s14// RUN: %expect_crash %run %t4 2>&1 | FileCheck --check-prefix=CFI %s15// RUN: %expect_crash %run %t4 x 2>&1 | FileCheck --check-prefix=CFI %s16 17// RUN: %clangxx -o %t5 %s18// RUN: %run %t5 2>&1 | FileCheck --check-prefix=NCFI %s19// RUN: %run %t5 x 2>&1 | FileCheck --check-prefix=NCFI %s20 21// RUN: %clangxx_cfi_diag -o %t6 %s22// RUN: %run %t6 2>&1 | FileCheck --check-prefix=CFI-DIAG2 %s23// RUN: %run %t6 x 2>&1 | FileCheck --check-prefix=CFI-DIAG1 %s24 25// Tests that the CFI mechanism is sensitive to multiple inheritance and only26// permits calls via virtual tables for the correct base class.27 28// REQUIRES: cxxabi29 30#include <stdio.h>31#include "utils.h"32 33struct A {34  virtual void f() = 0;35};36 37struct B {38  virtual void g() = 0;39};40 41struct C : A, B {42  virtual void f(), g();43};44 45void C::f() {}46void C::g() {}47 48int main(int argc, char **argv) {49  create_derivers<A>();50  create_derivers<B>();51 52  C *c = new C;53  break_optimization(c);54 55  // CFI: 156  // NCFI: 157  fprintf(stderr, "1\n");58 59  if (argc > 1) {60    A *a = c;61    // CFI-DIAG1: runtime error: control flow integrity check for type 'B' failed during cast to unrelated type62    // CFI-DIAG1-NEXT: note: vtable is of type '{{(struct )?}}C'63    ((B *)a)->g(); // UB here64  } else {65    // CFI-DIAG2: runtime error: control flow integrity check for type 'A' failed during cast to unrelated type66    // CFI-DIAG2-NEXT: note: vtable is of type '{{(struct )?}}C'67    B *b = c;68    ((A *)b)->f(); // UB here69  }70 71  // CFI-NOT: {{^2$}}72  // NCFI: {{^2$}}73  fprintf(stderr, "2\n");74}75