Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / dtor-vtable.cpp
blob4c6c66d9b3be3c8ef9bbb74769463c2e5df139d1
1 // RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t
3 // RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t
5 // RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t
7 // RUN: %clangxx_msan %s -DVPTRA=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t
9 // RUN: %clangxx_msan %s -DVPTRCA=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t
11 // RUN: %clangxx_msan %s -DVPTRCB=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t
13 // RUN: %clangxx_msan %s -DVPTRC=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t
15 // Expected to quit due to invalid access when invoking
16 // function using vtable.
18 #include <sanitizer/msan_interface.h>
19 #include <stdio.h>
20 #include <assert.h>
22 class A {
23 public:
24 int x;
25 ~A() {}
26 virtual void A_Foo() {}
29 class B {
30 public:
31 int y;
32 ~B() {}
33 virtual void B_Foo() {}
36 class C : public A, public B {
37 public:
38 int z;
39 ~C() {}
40 virtual void C_Foo() {}
43 int main() {
44 A *a = new A();
45 a->~A();
47 // Shouldn't be allowed to invoke function via vtable.
48 #ifdef VPTRA
49 a->A_Foo();
50 #endif
52 C *c = new C();
53 c->~C();
55 #ifdef VPTRCA
56 c->A_Foo();
57 #endif
59 #ifdef VPTRCB
60 c->B_Foo();
61 #endif
63 #ifdef VPTRC
64 c->C_Foo();
65 #endif
67 return 0;