auto merge of #5726 : brson/rust/struct-return, r=brson

r? @nikomatsakis

This doesn't completely fix the x86 ABI for structs, but it does fix some cases. On linux, structs appear to be returned correctly now. On windows, structs are only returned by pointer when they are greater than 8 bytes. That scenario works now.

In the case where the struct is less than 8 bytes our generated code looks peculiar. When returning a pair of u16, C packs both variables into %eax to return them. Our generated code though expects to find one of the pair in %ax and the other in %dx. Similar for u8. I haven't looked into it yet.

There appears to also be struct passing problems on linux, where my `extern-pass-TwoU8s` and `extern-pass-TwoU16s` tests are failing.
This commit is contained in:
bors 2013-04-17 18:45:58 -07:00
commit fdb4ef321e
21 changed files with 484 additions and 158 deletions

View file

@ -0,0 +1,32 @@
// Copyright 2012 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.
// Test a foreign function that accepts and returns a struct
// by value.
// xfail-test #5744
#[deriving(Eq)]
struct TwoU16s {
one: u16, two: u16
}
pub extern {
pub fn rust_dbg_extern_identity_TwoU16s(v: TwoU16s) -> TwoU16s;
}
pub fn main() {
unsafe {
let x = TwoU16s {one: 22, two: 23};
let y = rust_dbg_extern_identity_TwoU16s(x);
assert!(x == y);
}
}

View file

@ -0,0 +1,30 @@
// Copyright 2012 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.
// Test a foreign function that accepts and returns a struct
// by value.
#[deriving(Eq)]
struct TwoU32s {
one: u32, two: u32
}
pub extern {
pub fn rust_dbg_extern_identity_TwoU32s(v: TwoU32s) -> TwoU32s;
}
pub fn main() {
unsafe {
let x = TwoU32s {one: 22, two: 23};
let y = rust_dbg_extern_identity_TwoU32s(x);
assert!(x == y);
}
}

View file

@ -10,8 +10,6 @@
// Test that we ignore modes when calling extern functions.
// xfail-test --- broken on 32-bit ABIs! (#5347)
#[deriving(Eq)]
struct TwoU64s {
one: u64, two: u64

View file

@ -11,7 +11,7 @@
// Test a foreign function that accepts and returns a struct
// by value.
// xfail-test --- broken on 32-bit ABIs! (#5347)
// xfail-fast This works standalone on windows but not with check-fast. don't know why
#[deriving(Eq)]
struct TwoU64s {

View file

@ -0,0 +1,32 @@
// Copyright 2012 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.
// Test a foreign function that accepts and returns a struct
// by value.
// xfail-test #5744
#[deriving(Eq)]
struct TwoU8s {
one: u8, two: u8
}
pub extern {
pub fn rust_dbg_extern_identity_TwoU8s(v: TwoU8s) -> TwoU8s;
}
pub fn main() {
unsafe {
let x = TwoU8s {one: 22, two: 23};
let y = rust_dbg_extern_identity_TwoU8s(x);
assert!(x == y);
}
}

View file

@ -0,0 +1,27 @@
// Copyright 2012 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.
// xfail-win32 #5745
struct TwoU16s {
one: u16, two: u16
}
pub extern {
pub fn rust_dbg_extern_return_TwoU16s() -> TwoU16s;
}
pub fn main() {
unsafe {
let y = rust_dbg_extern_return_TwoU16s();
assert!(y.one == 10);
assert!(y.two == 20);
}
}

View file

@ -0,0 +1,25 @@
// Copyright 2012 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.
struct TwoU32s {
one: u32, two: u32
}
pub extern {
pub fn rust_dbg_extern_return_TwoU32s() -> TwoU32s;
}
pub fn main() {
unsafe {
let y = rust_dbg_extern_return_TwoU32s();
assert!(y.one == 10);
assert!(y.two == 20);
}
}

View file

@ -0,0 +1,25 @@
// Copyright 2012 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.
struct TwoU64s {
one: u64, two: u64
}
pub extern {
pub fn rust_dbg_extern_return_TwoU64s() -> TwoU64s;
}
pub fn main() {
unsafe {
let y = rust_dbg_extern_return_TwoU64s();
assert!(y.one == 10);
assert!(y.two == 20);
}
}

View file

@ -0,0 +1,27 @@
// Copyright 2012 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.
// xfail-win32 #5745
struct TwoU8s {
one: u8, two: u8
}
pub extern {
pub fn rust_dbg_extern_return_TwoU8s() -> TwoU8s;
}
pub fn main() {
unsafe {
let y = rust_dbg_extern_return_TwoU8s();
assert!(y.one == 10);
assert!(y.two == 20);
}
}