1 // RUN: %clang_cc1 -fsanitize=memory -O0 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -fsanitize=memory -O1 -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
3 
4 template <class T>
5 class Vector {
6 public:
7   int size;
8   ~Vector() {
9     size += 1;
10   }
11 };
12 
13 struct Base {
14   int b1;
15   double b2;
16   Base() {
17     b1 = 5;
18     b2 = 10.989;
19   }
20   virtual ~Base() {}
21 };
22 
23 struct VirtualBase {
24   int vb1;
25   int vb2;
26   VirtualBase() {
27     vb1 = 10;
28     vb2 = 11;
29   }
30   virtual ~VirtualBase() {}
31 };
32 
33 struct Derived : public Base, public virtual VirtualBase {
34   int d1;
35   Vector<int> v;
36   int d2;
37   Derived() {
38     d1 = 10;
39   }
40   ~Derived() {}
41 };
42 
43 Derived d;
44 
45 // Destruction order:
46 // Derived: int, Vector, Base, VirtualBase
47 
48 // CHECK-LABEL: define {{.*}}ZN7DerivedD1Ev
49 // CHECK: call void {{.*}}ZN11VirtualBaseD2Ev
50 // CHECK: ret void
51 
52 // CHECK-LABEL: define {{.*}}ZN7DerivedD0Ev
53 // CHECK: ret void
54 
55 // CHECK-LABEL: define {{.*}}ZN11VirtualBaseD1Ev
56 // CHECK: ret void
57 
58 // CHECK-LABEL: define {{.*}}ZN11VirtualBaseD0Ev
59 // CHECK: ret void
60 
61 // poison 2 ints
62 // CHECK-LABEL: define {{.*}}ZN11VirtualBaseD2Ev
63 // CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 8)
64 // CHECK: ret void
65 
66 // poison int and double
67 // CHECK-LABEL: define {{.*}}ZN4BaseD2Ev
68 // CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 16)
69 // CHECK: ret void
70 
71 // poison int, ignore vector, poison int
72 // CHECK-LABEL: define {{.*}}ZN7DerivedD2Ev
73 // CHECK: call void {{.*}}ZN6VectorIiED1Ev
74 // CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
75 // CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
76 // CHECK: call void {{.*}}ZN4BaseD2Ev
77 // CHECK: ret void
78 
79 // poison int
80 // CHECK-LABEL: define {{.*}}ZN6VectorIiED2Ev
81 // CHECK: call void {{.*}}sanitizer_dtor_callback({{.*}}, i64 4)
82 // CHECK: ret void
83