Skip to content

Commit 99ebb81

Browse files
debuginfo: Added test cases for packed structs (/w drop)
1 parent 6230ec1 commit 99ebb81

File tree

3 files changed

+356
-0
lines changed

3 files changed

+356
-0
lines changed
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249
12+
13+
// compile-flags:-Z extra-debug-info
14+
// debugger:set print pretty off
15+
// debugger:break zzz
16+
// debugger:run
17+
// debugger:finish
18+
19+
// debugger:print packed
20+
// check:$1 = {x = 123, y = 234, z = 345}
21+
22+
// debugger:print packedInPacked
23+
// check:$2 = {a = 1111, b = {x = 2222, y = 3333, z = 4444}, c = 5555, d = {x = 6666, y = 7777, z = 8888}}
24+
25+
// debugger:print packedInUnpacked
26+
// check:$3 = {a = -1111, b = {x = -2222, y = -3333, z = -4444}, c = -5555, d = {x = -6666, y = -7777, z = -8888}}
27+
28+
// debugger:print unpackedInPacked
29+
// check:$4 = {a = 987, b = {x = 876, y = 765, z = 654}, c = {x = 543, y = 432, z = 321}, d = 210}
30+
31+
32+
// debugger:print packedInPackedWithDrop
33+
// check:$5 = {a = 11, b = {x = 22, y = 33, z = 44}, c = 55, d = {x = 66, y = 77, z = 88}}
34+
35+
// debugger:print packedInUnpackedWithDrop
36+
// check:$6 = {a = -11, b = {x = -22, y = -33, z = -44}, c = -55, d = {x = -66, y = -77, z = -88}}
37+
38+
// debugger:print unpackedInPackedWithDrop
39+
// check:$7 = {a = 98, b = {x = 87, y = 76, z = 65}, c = {x = 54, y = 43, z = 32}, d = 21}
40+
41+
// debugger:print deeplyNested
42+
// check:$8 = {a = {a = 1, b = {x = 2, y = 3, z = 4}, c = 5, d = {x = 6, y = 7, z = 8}}, b = {a = 9, b = {x = 10, y = 11, z = 12}, c = {x = 13, y = 14, z = 15}, d = 16}, c = {a = 17, b = {x = 18, y = 19, z = 20}, c = 21, d = {x = 22, y = 23, z = 24}}, d = {a = 25, b = {x = 26, y = 27, z = 28}, c = 29, d = {x = 30, y = 31, z = 32}}, e = {a = 33, b = {x = 34, y = 35, z = 36}, c = {x = 37, y = 38, z = 39}, d = 40}, f = {a = 41, b = {x = 42, y = 43, z = 44}, c = 45, d = {x = 46, y = 47, z = 48}}}
43+
44+
#[packed]
45+
struct Packed {
46+
x: i16,
47+
y: i32,
48+
z: i64
49+
}
50+
51+
impl Drop for Packed {
52+
fn drop(&self) {}
53+
}
54+
55+
#[packed]
56+
struct PackedInPacked {
57+
a: i32,
58+
b: Packed,
59+
c: i64,
60+
d: Packed
61+
}
62+
63+
struct PackedInUnpacked {
64+
a: i32,
65+
b: Packed,
66+
c: i64,
67+
d: Packed
68+
}
69+
70+
struct Unpacked {
71+
x: i64,
72+
y: i32,
73+
z: i16
74+
}
75+
76+
impl Drop for Unpacked {
77+
fn drop(&self) {}
78+
}
79+
80+
#[packed]
81+
struct UnpackedInPacked {
82+
a: i16,
83+
b: Unpacked,
84+
c: Unpacked,
85+
d: i64
86+
}
87+
88+
#[packed]
89+
struct PackedInPackedWithDrop {
90+
a: i32,
91+
b: Packed,
92+
c: i64,
93+
d: Packed
94+
}
95+
96+
impl Drop for PackedInPackedWithDrop {
97+
fn drop(&self) {}
98+
}
99+
100+
struct PackedInUnpackedWithDrop {
101+
a: i32,
102+
b: Packed,
103+
c: i64,
104+
d: Packed
105+
}
106+
107+
impl Drop for PackedInUnpackedWithDrop {
108+
fn drop(&self) {}
109+
}
110+
111+
#[packed]
112+
struct UnpackedInPackedWithDrop {
113+
a: i16,
114+
b: Unpacked,
115+
c: Unpacked,
116+
d: i64
117+
}
118+
119+
impl Drop for UnpackedInPackedWithDrop {
120+
fn drop(&self) {}
121+
}
122+
123+
struct DeeplyNested {
124+
a: PackedInPacked,
125+
b: UnpackedInPackedWithDrop,
126+
c: PackedInUnpacked,
127+
d: PackedInUnpackedWithDrop,
128+
e: UnpackedInPacked,
129+
f: PackedInPackedWithDrop
130+
}
131+
132+
fn main() {
133+
let packed = Packed { x: 123, y: 234, z: 345 };
134+
135+
let packedInPacked = PackedInPacked {
136+
a: 1111,
137+
b: Packed { x: 2222, y: 3333, z: 4444 },
138+
c: 5555,
139+
d: Packed { x: 6666, y: 7777, z: 8888 }
140+
};
141+
142+
let packedInUnpacked = PackedInUnpacked {
143+
a: -1111,
144+
b: Packed { x: -2222, y: -3333, z: -4444 },
145+
c: -5555,
146+
d: Packed { x: -6666, y: -7777, z: -8888 }
147+
};
148+
149+
let unpackedInPacked = UnpackedInPacked {
150+
a: 987,
151+
b: Unpacked { x: 876, y: 765, z: 654 },
152+
c: Unpacked { x: 543, y: 432, z: 321 },
153+
d: 210
154+
};
155+
156+
let packedInPackedWithDrop = PackedInPackedWithDrop {
157+
a: 11,
158+
b: Packed { x: 22, y: 33, z: 44 },
159+
c: 55,
160+
d: Packed { x: 66, y: 77, z: 88 }
161+
};
162+
163+
let packedInUnpackedWithDrop = PackedInUnpackedWithDrop {
164+
a: -11,
165+
b: Packed { x: -22, y: -33, z: -44 },
166+
c: -55,
167+
d: Packed { x: -66, y: -77, z: -88 }
168+
};
169+
170+
let unpackedInPackedWithDrop = UnpackedInPackedWithDrop {
171+
a: 98,
172+
b: Unpacked { x: 87, y: 76, z: 65 },
173+
c: Unpacked { x: 54, y: 43, z: 32 },
174+
d: 21
175+
};
176+
177+
let deeplyNested = DeeplyNested {
178+
a: PackedInPacked {
179+
a: 1,
180+
b: Packed { x: 2, y: 3, z: 4 },
181+
c: 5,
182+
d: Packed { x: 6, y: 7, z: 8 }
183+
},
184+
b: UnpackedInPackedWithDrop {
185+
a: 9,
186+
b: Unpacked { x: 10, y: 11, z: 12 },
187+
c: Unpacked { x: 13, y: 14, z: 15 },
188+
d: 16
189+
},
190+
c: PackedInUnpacked {
191+
a: 17,
192+
b: Packed { x: 18, y: 19, z: 20 },
193+
c: 21,
194+
d: Packed { x: 22, y: 23, z: 24 }
195+
},
196+
d: PackedInUnpackedWithDrop {
197+
a: 25,
198+
b: Packed { x: 26, y: 27, z: 28 },
199+
c: 29,
200+
d: Packed { x: 30, y: 31, z: 32 }
201+
},
202+
e: UnpackedInPacked {
203+
a: 33,
204+
b: Unpacked { x: 34, y: 35, z: 36 },
205+
c: Unpacked { x: 37, y: 38, z: 39 },
206+
d: 40
207+
},
208+
f: PackedInPackedWithDrop {
209+
a: 41,
210+
b: Packed { x: 42, y: 43, z: 44 },
211+
c: 45,
212+
d: Packed { x: 46, y: 47, z: 48 }
213+
}
214+
};
215+
216+
zzz();
217+
}
218+
219+
fn zzz() {()}

src/test/debug-info/packed-struct.rs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249
12+
13+
// compile-flags:-Z extra-debug-info
14+
// debugger:set print pretty off
15+
// debugger:break zzz
16+
// debugger:run
17+
// debugger:finish
18+
19+
// debugger:print packed
20+
// check:$1 = {x = 123, y = 234, z = 345}
21+
22+
// debugger:print packedInPacked
23+
// check:$2 = {a = 1111, b = {x = 2222, y = 3333, z = 4444}, c = 5555, d = {x = 6666, y = 7777, z = 8888}}
24+
25+
// debugger:print packedInUnpacked
26+
// check:$3 = {a = -1111, b = {x = -2222, y = -3333, z = -4444}, c = -5555, d = {x = -6666, y = -7777, z = -8888}}
27+
28+
// debugger:print unpackedInPacked
29+
// check:$4 = {a = 987, b = {x = 876, y = 765, z = 654, w = 543}, c = {x = 432, y = 321, z = 210, w = 109}, d = -98}
30+
31+
// debugger:print sizeof(packed)
32+
// check:$5 = 14
33+
34+
// debugger:print sizeof(packedInPacked)
35+
// check:$6 = 40
36+
37+
// debugger:print sizeof(packedInUnpacked)
38+
// check:$7 = 48
39+
40+
// debugger:print sizeof(unpackedInPacked)
41+
// check:$8 = 58
42+
43+
44+
45+
#[packed]
46+
struct Packed {
47+
x: i16,
48+
y: i32,
49+
z: i64
50+
}
51+
52+
#[packed]
53+
struct PackedInPacked {
54+
a: i32,
55+
b: Packed,
56+
c: i64,
57+
d: Packed
58+
}
59+
60+
// layout: aaaa bbbb bbbb bbbb bb.. .... cccc cccc dddd dddd dddd dd..
61+
struct PackedInUnpacked {
62+
a: i32,
63+
b: Packed,
64+
c: i64,
65+
d: Packed
66+
}
67+
68+
// layout: xx.. yyyy zz.. .... wwww wwww
69+
struct Unpacked {
70+
x: i16,
71+
y: i32,
72+
z: i16,
73+
w: i64
74+
}
75+
76+
// layout: aabb bbbb bbbb bbbb bbbb bbbb bbcc cccc cccc cccc cccc cccc ccdd dddd dd
77+
#[packed]
78+
struct UnpackedInPacked {
79+
a: i16,
80+
b: Unpacked,
81+
c: Unpacked,
82+
d: i64
83+
}
84+
85+
fn main() {
86+
let packed = Packed { x: 123, y: 234, z: 345 };
87+
88+
let packedInPacked = PackedInPacked {
89+
a: 1111,
90+
b: Packed { x: 2222, y: 3333, z: 4444 },
91+
c: 5555,
92+
d: Packed { x: 6666, y: 7777, z: 8888 }
93+
};
94+
95+
let packedInUnpacked = PackedInUnpacked {
96+
a: -1111,
97+
b: Packed { x: -2222, y: -3333, z: -4444 },
98+
c: -5555,
99+
d: Packed { x: -6666, y: -7777, z: -8888 }
100+
};
101+
102+
let unpackedInPacked = UnpackedInPacked {
103+
a: 987,
104+
b: Unpacked { x: 876, y: 765, z: 654, w: 543 },
105+
c: Unpacked { x: 432, y: 321, z: 210, w: 109 },
106+
d: -98
107+
};
108+
109+
zzz();
110+
}
111+
112+
fn zzz() {()}

src/test/debug-info/struct-with-destructor.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
// debugger:print withDestructor
2222
// check:$3 = {a = {x = 10, y = 20}, guard = -1}
2323

24+
// debugger:print nested
25+
// check:$4 = {a = {a = {x = 7890, y = 9870}}}
26+
27+
// debugger:print sizeof(nested)
28+
// check:$5 = 32
29+
30+
2431
struct NoDestructor {
2532
x : i32,
2633
y : i64
@@ -45,6 +52,18 @@ struct WithDestructorGuarded {
4552
guard: i64
4653
}
4754

55+
struct NestedInner {
56+
a: WithDestructor
57+
}
58+
59+
impl Drop for NestedInner {
60+
fn drop(&self) {}
61+
}
62+
63+
struct NestedOuter {
64+
a: NestedInner
65+
}
66+
4867

4968
// The compiler adds a 'destructed' boolean field to structs implementing Drop. This field is used
5069
// at runtime to prevent drop() to be executed more than once (see middle::trans::adt).
@@ -80,6 +99,12 @@ fn main() {
8099
guard: -1
81100
};
82101

102+
// expected layout = xxxx....yyyyyyyyD.......D...
103+
// <--WithDestructor------>
104+
// <-------NestedInner-------->
105+
// <-------NestedOuter-------->
106+
let nested = NestedOuter { a: NestedInner { a: WithDestructor { x: 7890, y: 9870 } } };
107+
83108
zzz();
84109
}
85110

0 commit comments

Comments
 (0)