ms-vtordisp-local.cpp
7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// RUN: %clang_cc1 -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm-only -triple x86_64-pc-win32 -fdump-record-layouts -fsyntax-only %s 2>&1 | FileCheck %s
struct Base {
virtual ~Base() {}
virtual void BaseFunc() {}
};
#pragma vtordisp(0)
struct Container {
static void f() try {
#pragma vtordisp(2)
struct HasVtorDisp : virtual Base {
virtual ~HasVtorDisp() {}
virtual void Func() {}
};
int x[sizeof(HasVtorDisp)];
// HasVtorDisp: vtordisp because of pragma right before it.
//
// CHECK: *** Dumping AST Record Layout
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct HasVtorDisp
// CHECK-NEXT: 0 | (HasVtorDisp vftable pointer)
// CHECK-NEXT: 8 | (HasVtorDisp vbtable pointer)
// CHECK-NEXT: 20 | (vtordisp for vbase Base)
// CHECK-NEXT: 24 | struct Base (virtual base)
// CHECK-NEXT: 24 | (Base vftable pointer)
// CHECK-NEXT: | [sizeof=32, align=8,
// CHECK-NEXT: | nvsize=16, nvalign=8]
} catch (...) {
}
};
struct NoVtorDisp1 : virtual Base {
virtual ~NoVtorDisp1() {}
virtual void Func() {}
};
int x1[sizeof(NoVtorDisp1)];
// NoVtroDisp1: no vtordisp because of pragma disabling it.
//
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct NoVtorDisp1
// CHECK-NEXT: 0 | (NoVtorDisp1 vftable pointer)
// CHECK-NEXT: 8 | (NoVtorDisp1 vbtable pointer)
// CHECK-NEXT: 16 | struct Base (virtual base)
// CHECK-NEXT: 16 | (Base vftable pointer)
// CHECK-NEXT: | [sizeof=24, align=8,
// CHECK-NEXT: | nvsize=16, nvalign=8]
struct Container2 {
static void f1() {
// Local pragma #1 - must be disabled on exit from f1().
#pragma vtordisp(push, 2)
struct HasVtorDisp1 : virtual Base {
virtual ~HasVtorDisp1() {}
virtual void Func() {}
};
int x2[sizeof(HasVtorDisp1)];
// HasVtorDisp1: vtordisp because of pragma right before it.
//
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct HasVtorDisp1
// CHECK-NEXT: 0 | (HasVtorDisp1 vftable pointer)
// CHECK-NEXT: 8 | (HasVtorDisp1 vbtable pointer)
// CHECK-NEXT: 20 | (vtordisp for vbase Base)
// CHECK-NEXT: 24 | struct Base (virtual base)
// CHECK-NEXT: 24 | (Base vftable pointer)
// CHECK-NEXT: | [sizeof=32, align=8,
// CHECK-NEXT: | nvsize=16, nvalign=8]
struct InnerContainer {
static void g1() {
struct HasVtorDisp2 : virtual Base {
virtual ~HasVtorDisp2() {}
virtual void Func() {}
};
int x3[sizeof(HasVtorDisp2)];
// HasVtorDisp2: vtordisp because of vtordisp(2) in f1().
//
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct HasVtorDisp2
// CHECK-NEXT: 0 | (HasVtorDisp2 vftable pointer)
// CHECK-NEXT: 8 | (HasVtorDisp2 vbtable pointer)
// CHECK-NEXT: 20 | (vtordisp for vbase Base)
// CHECK-NEXT: 24 | struct Base (virtual base)
// CHECK-NEXT: 24 | (Base vftable pointer)
// CHECK-NEXT: | [sizeof=32, align=8,
// CHECK-NEXT: | nvsize=16, nvalign=8]
// Local pragma #2 - must be disabled on exit from g1().
#pragma vtordisp(push, 0)
struct NoVtorDisp2 : virtual Base {
virtual ~NoVtorDisp2() {}
virtual void Func() {}
};
int x4[sizeof(NoVtorDisp2)];
// NoVtroDisp2: no vtordisp because of vtordisp(0) in g1().
//
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct NoVtorDisp2
// CHECK-NEXT: 0 | (NoVtorDisp2 vftable pointer)
// CHECK-NEXT: 8 | (NoVtorDisp2 vbtable pointer)
// CHECK-NEXT: 16 | struct Base (virtual base)
// CHECK-NEXT: 16 | (Base vftable pointer)
// CHECK-NEXT: | [sizeof=24, align=8,
// CHECK-NEXT: | nvsize=16, nvalign=8]
}
static void g2() {
struct HasVtorDisp3 : virtual Base {
virtual ~HasVtorDisp3() {}
virtual void Func() {}
};
int x5[sizeof(HasVtorDisp3)];
// HasVtorDisp3: vtordisp because of vtordisp(2) in f1(),
// local vtordisp(0) in g1() is disabled.
//
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct HasVtorDisp3
// CHECK-NEXT: 0 | (HasVtorDisp3 vftable pointer)
// CHECK-NEXT: 8 | (HasVtorDisp3 vbtable pointer)
// CHECK-NEXT: 20 | (vtordisp for vbase Base)
// CHECK-NEXT: 24 | struct Base (virtual base)
// CHECK-NEXT: 24 | (Base vftable pointer)
// CHECK-NEXT: | [sizeof=32, align=8,
// CHECK-NEXT: | nvsize=16, nvalign=8]
}
};
struct HasVtorDisp4 : virtual Base {
virtual ~HasVtorDisp4() {}
virtual void Func() {}
};
int x6[sizeof(HasVtorDisp4)];
// HasVtorDisp4: vtordisp because of vtordisp(2) in f1(),
// local vtordisp(0) in g1() is disabled,
// g2() has no pragmas - stack is not affected.
//
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct HasVtorDisp4
// CHECK-NEXT: 0 | (HasVtorDisp4 vftable pointer)
// CHECK-NEXT: 8 | (HasVtorDisp4 vbtable pointer)
// CHECK-NEXT: 20 | (vtordisp for vbase Base)
// CHECK-NEXT: 24 | struct Base (virtual base)
// CHECK-NEXT: 24 | (Base vftable pointer)
// CHECK-NEXT: | [sizeof=32, align=8,
// CHECK-NEXT: | nvsize=16, nvalign=8]
InnerContainer::g1();
InnerContainer::g2();
}
static void f2() {
struct NoVtorDisp3 : virtual Base {
virtual ~NoVtorDisp3() {}
virtual void Func() {}
};
int x7[sizeof(NoVtorDisp3)];
// NoVtroDisp3: no vtordisp because of global pragma (0),
// local vtordisp(2) is disabled on exit from f1().
//
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct NoVtorDisp3
// CHECK-NEXT: 0 | (NoVtorDisp3 vftable pointer)
// CHECK-NEXT: 8 | (NoVtorDisp3 vbtable pointer)
// CHECK-NEXT: 16 | struct Base (virtual base)
// CHECK-NEXT: 16 | (Base vftable pointer)
// CHECK-NEXT: | [sizeof=24, align=8,
// CHECK-NEXT: | nvsize=16, nvalign=8]
}
};
struct Container3 {
#pragma vtordisp(2)
struct HasVtorDisp5 : virtual Base {
virtual ~HasVtorDisp5() {}
virtual void Func() {}
};
int x8[sizeof(HasVtorDisp5)];
// HasVtorDisp5: vtordisp because of pragma right before it.
//
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct Container3::HasVtorDisp5
// CHECK-NEXT: 0 | (HasVtorDisp5 vftable pointer)
// CHECK-NEXT: 8 | (HasVtorDisp5 vbtable pointer)
// CHECK-NEXT: 20 | (vtordisp for vbase Base)
// CHECK-NEXT: 24 | struct Base (virtual base)
// CHECK-NEXT: 24 | (Base vftable pointer)
// CHECK-NEXT: | [sizeof=32, align=8,
// CHECK-NEXT: | nvsize=16, nvalign=8]
};
int main() {
Container::f();
Container2::f1();
Container2::f2();
Container3 cont3;
return 0;
};