auto merge of #16584 : luqmana/rust/psfo, r=alexcrichton

Fixes #16574.
This commit is contained in:
bors 2014-08-19 23:56:02 +00:00
commit a6758e344b
4 changed files with 56 additions and 4 deletions

View File

@ -176,11 +176,15 @@ fn classify_ty(ty: Type) -> Vec<RegClass> {
}
fn classify_struct(tys: &[Type],
cls: &mut [RegClass], i: uint,
off: uint) {
cls: &mut [RegClass],
i: uint,
off: uint,
packed: bool) {
let mut field_off = off;
for ty in tys.iter() {
field_off = align(field_off, *ty);
if !packed {
field_off = align(field_off, *ty);
}
classify(*ty, cls, i, field_off);
field_off += ty_size(*ty);
}
@ -219,7 +223,7 @@ fn classify_ty(ty: Type) -> Vec<RegClass> {
unify(cls, ix + off / 8u, SSEDs);
}
Struct => {
classify_struct(ty.field_types().as_slice(), cls, ix, off);
classify_struct(ty.field_types().as_slice(), cls, ix, off, ty.is_packed());
}
Array => {
let len = ty.array_length();

View File

@ -0,0 +1,7 @@
-include ../tools.mk
all:
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
$(RUSTC) test.rs -L $(TMPDIR)
$(call RUN,test) || exit 1

View File

@ -0,0 +1,11 @@
// Pragma needed cause of gcc bug on windows: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991
#pragma pack(1)
struct __attribute__((packed)) Foo {
char a;
short b;
char c;
};
struct Foo foo(struct Foo foo) {
return foo;
}

View File

@ -0,0 +1,30 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[packed]
#[deriving(PartialEq, Show)]
struct Foo {
a: i8,
b: i16,
c: i8
}
#[link(name = "test", kind = "static")]
extern {
fn foo(f: Foo) -> Foo;
}
fn main() {
unsafe {
let a = Foo { a: 1, b: 2, c: 3 };
let b = foo(a);
assert_eq!(a, b);
}
}