annotate compiler-rt/test/msan/dtor-vtable.cpp @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
1 // RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t
150
anatofuz
parents:
diff changeset
2
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
3 // RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t
150
anatofuz
parents:
diff changeset
4
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
5 // RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t
150
anatofuz
parents:
diff changeset
6
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
7 // RUN: %clangxx_msan %s -DVPTRA=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t
150
anatofuz
parents:
diff changeset
8
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
9 // RUN: %clangxx_msan %s -DVPTRCA=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t
150
anatofuz
parents:
diff changeset
10
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
11 // RUN: %clangxx_msan %s -DVPTRCB=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t
150
anatofuz
parents:
diff changeset
12
236
c4bab56944e8 LLVM 16
kono
parents: 150
diff changeset
13 // RUN: %clangxx_msan %s -DVPTRC=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t
150
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 // Expected to quit due to invalid access when invoking
anatofuz
parents:
diff changeset
16 // function using vtable.
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 #include <sanitizer/msan_interface.h>
anatofuz
parents:
diff changeset
19 #include <stdio.h>
anatofuz
parents:
diff changeset
20 #include <assert.h>
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 class A {
anatofuz
parents:
diff changeset
23 public:
anatofuz
parents:
diff changeset
24 int x;
anatofuz
parents:
diff changeset
25 ~A() {}
anatofuz
parents:
diff changeset
26 virtual void A_Foo() {}
anatofuz
parents:
diff changeset
27 };
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 class B {
anatofuz
parents:
diff changeset
30 public:
anatofuz
parents:
diff changeset
31 int y;
anatofuz
parents:
diff changeset
32 ~B() {}
anatofuz
parents:
diff changeset
33 virtual void B_Foo() {}
anatofuz
parents:
diff changeset
34 };
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 class C : public A, public B {
anatofuz
parents:
diff changeset
37 public:
anatofuz
parents:
diff changeset
38 int z;
anatofuz
parents:
diff changeset
39 ~C() {}
anatofuz
parents:
diff changeset
40 virtual void C_Foo() {}
anatofuz
parents:
diff changeset
41 };
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 int main() {
anatofuz
parents:
diff changeset
44 A *a = new A();
anatofuz
parents:
diff changeset
45 a->~A();
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 // Shouldn't be allowed to invoke function via vtable.
anatofuz
parents:
diff changeset
48 #ifdef VPTRA
anatofuz
parents:
diff changeset
49 a->A_Foo();
anatofuz
parents:
diff changeset
50 #endif
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 C *c = new C();
anatofuz
parents:
diff changeset
53 c->~C();
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 #ifdef VPTRCA
anatofuz
parents:
diff changeset
56 c->A_Foo();
anatofuz
parents:
diff changeset
57 #endif
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 #ifdef VPTRCB
anatofuz
parents:
diff changeset
60 c->B_Foo();
anatofuz
parents:
diff changeset
61 #endif
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 #ifdef VPTRC
anatofuz
parents:
diff changeset
64 c->C_Foo();
anatofuz
parents:
diff changeset
65 #endif
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 return 0;
anatofuz
parents:
diff changeset
68 }