Skip to content

Commit a6758e3

Browse files
committed
auto merge of #16584 : luqmana/rust/psfo, r=alexcrichton
Fixes #16574.
2 parents 0600a3b + 7382554 commit a6758e3

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

src/librustc/middle/trans/cabi_x86_64.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,15 @@ fn classify_ty(ty: Type) -> Vec<RegClass> {
176176
}
177177

178178
fn classify_struct(tys: &[Type],
179-
cls: &mut [RegClass], i: uint,
180-
off: uint) {
179+
cls: &mut [RegClass],
180+
i: uint,
181+
off: uint,
182+
packed: bool) {
181183
let mut field_off = off;
182184
for ty in tys.iter() {
183-
field_off = align(field_off, *ty);
185+
if !packed {
186+
field_off = align(field_off, *ty);
187+
}
184188
classify(*ty, cls, i, field_off);
185189
field_off += ty_size(*ty);
186190
}
@@ -219,7 +223,7 @@ fn classify_ty(ty: Type) -> Vec<RegClass> {
219223
unify(cls, ix + off / 8u, SSEDs);
220224
}
221225
Struct => {
222-
classify_struct(ty.field_types().as_slice(), cls, ix, off);
226+
classify_struct(ty.field_types().as_slice(), cls, ix, off, ty.is_packed());
223227
}
224228
Array => {
225229
let len = ty.array_length();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
5+
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
6+
$(RUSTC) test.rs -L $(TMPDIR)
7+
$(call RUN,test) || exit 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Pragma needed cause of gcc bug on windows: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991
2+
#pragma pack(1)
3+
struct __attribute__((packed)) Foo {
4+
char a;
5+
short b;
6+
char c;
7+
};
8+
9+
struct Foo foo(struct Foo foo) {
10+
return foo;
11+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2014 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+
#[packed]
12+
#[deriving(PartialEq, Show)]
13+
struct Foo {
14+
a: i8,
15+
b: i16,
16+
c: i8
17+
}
18+
19+
#[link(name = "test", kind = "static")]
20+
extern {
21+
fn foo(f: Foo) -> Foo;
22+
}
23+
24+
fn main() {
25+
unsafe {
26+
let a = Foo { a: 1, b: 2, c: 3 };
27+
let b = foo(a);
28+
assert_eq!(a, b);
29+
}
30+
}

0 commit comments

Comments
 (0)