diff options
| author | bors <bors@rust-lang.org> | 2013-04-17 18:45:58 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-04-17 18:45:58 -0700 |
| commit | fdb4ef321ed5eee681c2b723dcb157c280aa72f2 (patch) | |
| tree | 7f38fcabd13cba2ff4577b32360abe43720490fc /src/test | |
| parent | 68dea752967fa2c7e0c4b82f476086457c93fff7 (diff) | |
| parent | a5ddc009829bef149a9e2f127e80609589604443 (diff) | |
| download | rust-fdb4ef321ed5eee681c2b723dcb157c280aa72f2.tar.gz rust-fdb4ef321ed5eee681c2b723dcb157c280aa72f2.zip | |
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.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-pass/extern-pass-TwoU16s.rs | 32 | ||||
| -rw-r--r-- | src/test/run-pass/extern-pass-TwoU32s.rs | 30 | ||||
| -rw-r--r-- | src/test/run-pass/extern-pass-TwoU64s-ref.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/extern-pass-TwoU64s.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/extern-pass-TwoU8s.rs | 32 | ||||
| -rw-r--r-- | src/test/run-pass/extern-return-TwoU16s.rs | 27 | ||||
| -rw-r--r-- | src/test/run-pass/extern-return-TwoU32s.rs | 25 | ||||
| -rw-r--r-- | src/test/run-pass/extern-return-TwoU64s.rs | 25 | ||||
| -rw-r--r-- | src/test/run-pass/extern-return-TwoU8s.rs | 27 |
9 files changed, 199 insertions, 3 deletions
diff --git a/src/test/run-pass/extern-pass-TwoU16s.rs b/src/test/run-pass/extern-pass-TwoU16s.rs new file mode 100644 index 00000000000..f0343c4d2a2 --- /dev/null +++ b/src/test/run-pass/extern-pass-TwoU16s.rs @@ -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); + } +} + diff --git a/src/test/run-pass/extern-pass-TwoU32s.rs b/src/test/run-pass/extern-pass-TwoU32s.rs new file mode 100644 index 00000000000..16d14a96cfe --- /dev/null +++ b/src/test/run-pass/extern-pass-TwoU32s.rs @@ -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); + } +} + diff --git a/src/test/run-pass/extern-pass-TwoU64s-ref.rs b/src/test/run-pass/extern-pass-TwoU64s-ref.rs index 87bec86d8de..56d3f8ebbff 100644 --- a/src/test/run-pass/extern-pass-TwoU64s-ref.rs +++ b/src/test/run-pass/extern-pass-TwoU64s-ref.rs @@ -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 diff --git a/src/test/run-pass/extern-pass-TwoU64s.rs b/src/test/run-pass/extern-pass-TwoU64s.rs index fb91d5495e1..eb2e3b1158f 100644 --- a/src/test/run-pass/extern-pass-TwoU64s.rs +++ b/src/test/run-pass/extern-pass-TwoU64s.rs @@ -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 { diff --git a/src/test/run-pass/extern-pass-TwoU8s.rs b/src/test/run-pass/extern-pass-TwoU8s.rs new file mode 100644 index 00000000000..213e9a68a7f --- /dev/null +++ b/src/test/run-pass/extern-pass-TwoU8s.rs @@ -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); + } +} + diff --git a/src/test/run-pass/extern-return-TwoU16s.rs b/src/test/run-pass/extern-return-TwoU16s.rs new file mode 100644 index 00000000000..0ea649a65b0 --- /dev/null +++ b/src/test/run-pass/extern-return-TwoU16s.rs @@ -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); + } +} diff --git a/src/test/run-pass/extern-return-TwoU32s.rs b/src/test/run-pass/extern-return-TwoU32s.rs new file mode 100644 index 00000000000..9e374687855 --- /dev/null +++ b/src/test/run-pass/extern-return-TwoU32s.rs @@ -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); + } +} diff --git a/src/test/run-pass/extern-return-TwoU64s.rs b/src/test/run-pass/extern-return-TwoU64s.rs new file mode 100644 index 00000000000..250d3b8f562 --- /dev/null +++ b/src/test/run-pass/extern-return-TwoU64s.rs @@ -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); + } +} diff --git a/src/test/run-pass/extern-return-TwoU8s.rs b/src/test/run-pass/extern-return-TwoU8s.rs new file mode 100644 index 00000000000..9007d12a451 --- /dev/null +++ b/src/test/run-pass/extern-return-TwoU8s.rs @@ -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); + } +} |
