1 // RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-passes -std=c++20 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s --implicit-check-not "call void @__sanitizer_dtor_callback"
2 // RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-passes -std=c++20 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s --implicit-check-not "call void @__sanitizer_dtor_callback"
3 
4 struct Empty {};
5 
6 struct EmptyNonTrivial {
7   ~EmptyNonTrivial();
8 };
9 
10 struct Trivial {
11   int a;
12   char c;
13 };
14 static_assert(sizeof(Trivial) == 8);
15 
16 struct NonTrivial {
17   int a;
18   char c;
19   ~NonTrivial();
20 };
21 static_assert(sizeof(NonTrivial) == 8);
22 
23 namespace T0 {
24 struct Struct {
25   Trivial f1;
26   int f2;
27   char f3;
~StructT0::Struct28   ~Struct(){};
29 } var;
30 static_assert(sizeof(Struct) == 16);
31 } // namespace T0
32 // CHECK-LABEL: define {{.*}} @_ZN2T06StructD2Ev(
33 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
34 // CHECK-NEXT:    ret void
35 
36 namespace empty {
37 namespace T1 {
38 struct Struct {
39   NonTrivial nt;
40   Trivial f1;
41   int f2;
42   char f3;
43 } var;
44 static_assert(sizeof(Struct) == 24);
45 } // namespace T1
46 // CHECK-LABEL: define {{.*}} @_ZN5empty2T16StructD2Ev(
47 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
48 // CHECK-NEXT:    ret void
49 
50 namespace T2 {
51 struct Struct {
52   Trivial f1;
53   NonTrivial nt;
54   int f2;
55   char f3;
56 } var;
57 static_assert(sizeof(Struct) == 24);
58 } // namespace T2
59 // CHECK-LABEL: define {{.*}} @_ZN5empty2T26StructD2Ev(
60 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
61 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
62 // CHECK-NEXT:    ret void
63 
64 namespace T3 {
65 struct Struct {
66   Trivial f1;
67   int f2;
68   NonTrivial nt;
69   char f3;
70 } var;
71 static_assert(sizeof(Struct) == 24);
72 } // namespace T3
73 // CHECK-LABEL: define {{.*}} @_ZN5empty2T36StructD2Ev(
74 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
75 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 1)
76 // CHECK-NEXT:    ret void
77 
78 namespace T4 {
79 struct Struct {
80   Trivial f1;
81   int f2;
82   char f3;
83   NonTrivial nt;
84 } var;
85 static_assert(sizeof(Struct) == 24);
86 } // namespace T4
87 // CHECK-LABEL: define {{.*}} @_ZN5empty2T46StructD2Ev(
88 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 16)
89 // CHECK-NEXT:    ret void
90 
91 namespace T5 {
92 struct Struct {
93   [[no_unique_address]] Empty e;
94   NonTrivial nt;
95   Trivial f1;
96   int f2;
97   char f3;
98 } var;
99 static_assert(sizeof(Struct) == 24);
100 } // namespace T5
101 // CHECK-LABEL: define {{.*}} @_ZN5empty2T56StructD2Ev(
102 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
103 // CHECK-NEXT:    ret void
104 
105 namespace T6 {
106 struct Struct {
107   NonTrivial nt;
108   [[no_unique_address]] Empty e;
109   Trivial f1;
110   int f2;
111   char f3;
112 } var;
113 static_assert(sizeof(Struct) == 24);
114 } // namespace T6
115 // CHECK-LABEL: define {{.*}} @_ZN5empty2T66StructD2Ev(
116 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
117 // CHECK-NEXT:    ret void
118 
119 namespace T7 {
120 struct Struct {
121   Trivial f1;
122   NonTrivial nt;
123   [[no_unique_address]] Empty e;
124   int f2;
125   char f3;
126 } var;
127 static_assert(sizeof(Struct) == 24);
128 } // namespace T7
129 // CHECK-LABEL: define {{.*}} @_ZN5empty2T76StructD2Ev(
130 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
131 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
132 // CHECK-NEXT:    ret void
133 
134 namespace T8 {
135 struct Struct {
136   Trivial f1;
137   [[no_unique_address]] Empty e;
138   NonTrivial nt;
139   int f2;
140   char f3;
141 } var;
142 static_assert(sizeof(Struct) == 24);
143 } // namespace T8
144 // CHECK-LABEL: define {{.*}} @_ZN5empty2T86StructD2Ev(
145 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
146 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
147 // CHECK-NEXT:    ret void
148 
149 namespace T9 {
150 struct Struct {
151   Trivial f1;
152   int f2;
153   NonTrivial nt;
154   [[no_unique_address]] Empty e;
155   char f3;
156 } var;
157 static_assert(sizeof(Struct) == 24);
158 } // namespace T9
159 // CHECK-LABEL: define {{.*}} @_ZN5empty2T96StructD2Ev(
160 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
161 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 1)
162 // CHECK-NEXT:    ret void
163 
164 namespace T10 {
165 struct Struct {
166   Trivial f1;
167   int f2;
168   [[no_unique_address]] Empty e;
169   NonTrivial nt;
170   char f3;
171 } var;
172 static_assert(sizeof(Struct) == 24);
173 } // namespace T10
174 // CHECK-LABEL: define {{.*}} @_ZN5empty3T106StructD2Ev(
175 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
176 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 1)
177 // CHECK-NEXT:    ret void
178 
179 namespace T11 {
180 struct Struct {
181   Trivial f1;
182   int f2;
183   char f3;
184   NonTrivial nt;
185   [[no_unique_address]] Empty e;
186 } var;
187 static_assert(sizeof(Struct) == 24);
188 } // namespace T11
189 // CHECK-LABEL: define {{.*}} @_ZN5empty3T116StructD2Ev(
190 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 16)
191 // CHECK-NEXT:    ret void
192 
193 namespace T12 {
194 struct Struct {
195   Trivial f1;
196   int f2;
197   char f3;
198   [[no_unique_address]] Empty e;
199   NonTrivial nt;
200 } var;
201 static_assert(sizeof(Struct) == 24);
202 } // namespace T12
203 } // namespace empty
204 // CHECK-LABEL: define {{.*}} @_ZN5empty3T126StructD2Ev(
205 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 16)
206 // CHECK-NEXT:    ret void
207 
208 namespace empty_non_trivial {
209 namespace T1 {
210 struct Struct {
211   NonTrivial nt;
212   Trivial f1;
213   int f2;
214   char f3;
215 } var;
216 static_assert(sizeof(Struct) == 24);
217 } // namespace T1
218 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial2T16StructD2Ev(
219 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
220 // CHECK-NEXT:    ret void
221 
222 namespace T2 {
223 struct Struct {
224   Trivial f1;
225   NonTrivial nt;
226   int f2;
227   char f3;
228 } var;
229 static_assert(sizeof(Struct) == 24);
230 } // namespace T2
231 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial2T26StructD2Ev(
232 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
233 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
234 // CHECK-NEXT:    ret void
235 
236 namespace T3 {
237 struct Struct {
238   Trivial f1;
239   int f2;
240   NonTrivial nt;
241   char f3;
242 } var;
243 static_assert(sizeof(Struct) == 24);
244 } // namespace T3
245 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial2T36StructD2Ev(
246 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
247 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 1)
248 // CHECK-NEXT:    ret void
249 
250 namespace T4 {
251 struct Struct {
252   Trivial f1;
253   int f2;
254   char f3;
255   NonTrivial nt;
256 } var;
257 static_assert(sizeof(Struct) == 24);
258 } // namespace T4
259 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial2T46StructD2Ev(
260 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 16)
261 // CHECK-NEXT:    ret void
262 
263 namespace T5 {
264 struct Struct {
265   [[no_unique_address]] EmptyNonTrivial e;
266   NonTrivial nt;
267   Trivial f1;
268   int f2;
269   char f3;
270 } var;
271 static_assert(sizeof(Struct) == 24);
272 } // namespace T5
273 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial2T56StructD2Ev(
274 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
275 // CHECK-NEXT:    ret void
276 
277 namespace T6 {
278 struct Struct {
279   NonTrivial nt;
280   [[no_unique_address]] EmptyNonTrivial e;
281   Trivial f1;
282   int f2;
283   char f3;
284 } var;
285 static_assert(sizeof(Struct) == 24);
286 } // namespace T6
287 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial2T66StructD2Ev(
288 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 13)
289 // CHECK-NEXT:    ret void
290 
291 namespace T7 {
292 struct Struct {
293   Trivial f1;
294   NonTrivial nt;
295   [[no_unique_address]] EmptyNonTrivial e;
296   int f2;
297   char f3;
298 } var;
299 static_assert(sizeof(Struct) == 24);
300 } // namespace T7
301 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial2T76StructD2Ev(
302 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
303 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
304 // CHECK-NEXT:    ret void
305 
306 namespace T8 {
307 struct Struct {
308   Trivial f1;
309   [[no_unique_address]] EmptyNonTrivial e;
310   NonTrivial nt;
311   int f2;
312   char f3;
313 } var;
314 static_assert(sizeof(Struct) == 24);
315 } // namespace T8
316 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial2T86StructD2Ev(
317 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 8)
318 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 5)
319 // CHECK-NEXT:    ret void
320 
321 namespace T9 {
322 struct Struct {
323   Trivial f1;
324   int f2;
325   NonTrivial nt;
326   [[no_unique_address]] EmptyNonTrivial e;
327   char f3;
328 } var;
329 static_assert(sizeof(Struct) == 24);
330 } // namespace T9
331 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial2T96StructD2Ev(
332 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
333 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 1)
334 // CHECK-NEXT:    ret void
335 
336 namespace T10 {
337 struct Struct {
338   Trivial f1;
339   int f2;
340   [[no_unique_address]] EmptyNonTrivial e;
341   NonTrivial nt;
342   char f3;
343 } var;
344 static_assert(sizeof(Struct) == 24);
345 } // namespace T10
346 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial3T106StructD2Ev(
347 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 12)
348 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 1)
349 // CHECK-NEXT:    ret void
350 
351 namespace T11 {
352 struct Struct {
353   Trivial f1;
354   int f2;
355   char f3;
356   NonTrivial nt;
357   [[no_unique_address]] EmptyNonTrivial e;
358 } var;
359 static_assert(sizeof(Struct) == 24);
360 } // namespace T11
361 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial3T116StructD2Ev(
362 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 16)
363 // CHECK-NEXT:    ret void
364 
365 namespace T12 {
366 struct Struct {
367   Trivial f1;
368   int f2;
369   char f3;
370   [[no_unique_address]] EmptyNonTrivial e;
371   NonTrivial nt;
372 } var;
373 static_assert(sizeof(Struct) == 24);
374 } // namespace T12
375 } // namespace empty_non_trivial
376 // CHECK-LABEL: define {{.*}} @_ZN17empty_non_trivial3T126StructD2Ev(
377 // CHECK:         call void @__sanitizer_dtor_callback(i8* {{.*}}, i64 16)
378 // CHECK:         ret void
379