From a5ddc009829bef149a9e2f127e80609589604443 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 1 Apr 2013 17:47:38 -0700 Subject: rustc: Use an out pointer to return structs in x86 C ABI. #5347 This Adds a bunch of tests for passing and returning structs of various sizes to C. It fixes the struct return rules on unix, and on windows for structs of size > 8 bytes. Struct passing on unix for structs under a certain size appears to still be broken. --- src/test/run-pass/extern-pass-TwoU16s.rs | 32 ++++++++++++++++++++++++++++ src/test/run-pass/extern-pass-TwoU32s.rs | 30 ++++++++++++++++++++++++++ src/test/run-pass/extern-pass-TwoU64s-ref.rs | 2 -- src/test/run-pass/extern-pass-TwoU64s.rs | 2 +- src/test/run-pass/extern-pass-TwoU8s.rs | 32 ++++++++++++++++++++++++++++ src/test/run-pass/extern-return-TwoU16s.rs | 27 +++++++++++++++++++++++ src/test/run-pass/extern-return-TwoU32s.rs | 25 ++++++++++++++++++++++ src/test/run-pass/extern-return-TwoU64s.rs | 25 ++++++++++++++++++++++ src/test/run-pass/extern-return-TwoU8s.rs | 27 +++++++++++++++++++++++ 9 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 src/test/run-pass/extern-pass-TwoU16s.rs create mode 100644 src/test/run-pass/extern-pass-TwoU32s.rs create mode 100644 src/test/run-pass/extern-pass-TwoU8s.rs create mode 100644 src/test/run-pass/extern-return-TwoU16s.rs create mode 100644 src/test/run-pass/extern-return-TwoU32s.rs create mode 100644 src/test/run-pass/extern-return-TwoU64s.rs create mode 100644 src/test/run-pass/extern-return-TwoU8s.rs (limited to 'src/test') 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 or the MIT license +// , 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 or the MIT license +// , 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 or the MIT license +// , 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 or the MIT license +// , 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 or the MIT license +// , 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 or the MIT license +// , 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 or the MIT license +// , 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); + } +} -- cgit 1.4.1-3-g733a5