Skip to content

Commit 18c779b

Browse files
committed
---
yaml --- r: 15659 b: refs/heads/try c: bbc4a74 h: refs/heads/master i: 15657: 0b4cd38 15655: 24b3a6c v: v3
1 parent 4538420 commit 18c779b

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 8e15640adacd1f0cab8617d62f445024915e5214
5+
refs/heads/try: bbc4a74dc685a570ebdf53849e8cc2220ed1d586
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rt/rust_shape.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ rust_alignof<double>() {
123123
return 4;
124124
}
125125

126+
// Issue #2303
127+
// On 32-bit x86 the alignment of 64-bit ints in structures is 4 bytes
128+
// Which is different from the preferred 8-byte alignment reported
129+
// by __alignof__ (at least on gcc).
130+
#ifdef __i386__
131+
template<>
132+
inline size_t
133+
rust_alignof<uint64_t>() {
134+
return 4;
135+
}
136+
#endif
137+
126138

127139
// Utility classes
128140

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// xfail-pretty
2+
// Issue #2303
3+
4+
// This is the type with the questionable alignment
5+
type inner = {
6+
c64: u64
7+
};
8+
9+
// This is the type that contains the type with the
10+
// questionable alignment, for testing
11+
type outer = {
12+
c8: u8,
13+
t: inner
14+
};
15+
16+
#[cfg(target_arch = "x86")]
17+
fn main() {
18+
19+
let x = {c8: 22u8, t: {c64: 44u64}};
20+
21+
// Send it through the shape code
22+
let y = #fmt["%?", x];
23+
24+
#debug("align inner = %?", sys::align_of::<inner>()); // 8
25+
#debug("size outer = %?", sys::size_of::<outer>()); // 12
26+
#debug("y = %s", y); // (22, (0))
27+
28+
// per clang/gcc the alignment of `inner` is 4 on x86.
29+
// we say it's 8
30+
//assert sys::align_of::<inner>() == 4u; // fails
31+
32+
// per clang/gcc the size of `outer` should be 12
33+
// because `inner`s alignment was 4.
34+
// LLVM packs the struct the way clang likes, despite
35+
// our intents regarding the alignment of `inner` and
36+
// we end up with the same size `outer` as clang
37+
assert sys::size_of::<outer>() == 12u; // passes
38+
39+
// But now our shape code doesn't find the inner struct
40+
// We print (22, (0))
41+
assert y == "(22, (44))"; // fails
42+
}
43+
44+
#[cfg(target_arch = "x86_64")]
45+
fn main() { }

0 commit comments

Comments
 (0)