Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / cfi / cross-dso / simple-pass.cpp
blob6ce64713a6e2ce846ff092c0727c39a2cce73f1b
1 // RUN: %clangxx_cfi_dso -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
2 // RUN: %clangxx_cfi_dso -g %s -o %t %ld_flags_rpath_exe
3 // RUN: %t 2>&1 | FileCheck --check-prefix=CFI %s
5 // RUN: %clangxx_cfi_dso -DB32 -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
6 // RUN: %clangxx_cfi_dso -DB32 %s -o %t %ld_flags_rpath_exe
7 // RUN: %t 2>&1 | FileCheck --check-prefix=CFI %s
9 // RUN: %clangxx_cfi_dso -DB64 -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
10 // RUN: %clangxx_cfi_dso -DB64 %s -o %t %ld_flags_rpath_exe
11 // RUN: %t 2>&1 | FileCheck --check-prefix=CFI %s
13 // RUN: %clangxx_cfi_dso -DBM -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
14 // RUN: %clangxx_cfi_dso -DBM %s -o %t %ld_flags_rpath_exe
15 // RUN: %t 2>&1 | FileCheck --check-prefix=CFI %s
17 // RUN: %clangxx -DBM -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
18 // RUN: %clangxx -DBM %s -o %t %ld_flags_rpath_exe
19 // RUN: %t 2>&1 | FileCheck --check-prefix=NCFI %s
20 // RUN: %t x 2>&1 | FileCheck --check-prefix=NCFI %s
22 // Tests that the CFI mechanism crashes the program when making a virtual call
23 // to an object of the wrong class but with a compatible vtable, by casting a
24 // pointer to such an object and attempting to make a call through it.
26 // REQUIRES: cxxabi
28 #include <stdio.h>
29 #include <string.h>
31 struct A {
32 virtual void f();
35 A *create_B();
37 #ifdef SHARED_LIB
39 #include "../utils.h"
40 struct B : public A {
41 virtual void f();
43 void B::f() {}
45 A *create_B() {
46 create_derivers<B>();
47 return new B();
50 #else
52 void A::f() {}
54 int main(int argc, char *argv[]) {
55 A *a = create_B();
57 // CFI: =1=
58 // NCFI: =1=
59 fprintf(stderr, "=1=\n");
60 a->f(); // OK
61 // CFI: =2=
62 // NCFI: =2=
63 fprintf(stderr, "=2=\n");
65 #endif