Skip to content

Commit 452eddf

Browse files
committed
[NFC][CodeGen] Add sanitize-dtor-zero-size-field test
The test demonstrates invalid behaviour which will be fixed soon.
1 parent 5121400 commit 452eddf

File tree

1 file changed

+378
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)