]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/struct-return.rs
rollup merge of #18007 : dotdash/arg_lifetime_end
[rust.git] / src / test / run-pass / struct-return.rs
1 // Copyright 2012-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 // ignore-lexer-test FIXME #15883
12
13 pub struct Quad { a: u64, b: u64, c: u64, d: u64 }
14 pub struct Floats { a: f64, b: u8, c: f64 }
15
16 mod rustrt {
17     use super::{Floats, Quad};
18
19     #[link(name = "rust_test_helpers")]
20     extern {
21         pub fn rust_dbg_abi_1(q: Quad) -> Quad;
22         pub fn rust_dbg_abi_2(f: Floats) -> Floats;
23     }
24 }
25
26 fn test1() {
27     unsafe {
28         let q = Quad { a: 0xaaaa_aaaa_aaaa_aaaa_u64,
29                  b: 0xbbbb_bbbb_bbbb_bbbb_u64,
30                  c: 0xcccc_cccc_cccc_cccc_u64,
31                  d: 0xdddd_dddd_dddd_dddd_u64 };
32         let qq = rustrt::rust_dbg_abi_1(q);
33         println!("a: {:x}", qq.a as uint);
34         println!("b: {:x}", qq.b as uint);
35         println!("c: {:x}", qq.c as uint);
36         println!("d: {:x}", qq.d as uint);
37         assert_eq!(qq.a, q.c + 1u64);
38         assert_eq!(qq.b, q.d - 1u64);
39         assert_eq!(qq.c, q.a + 1u64);
40         assert_eq!(qq.d, q.b - 1u64);
41     }
42 }
43
44 #[cfg(target_arch = "x86_64")]
45 fn test2() {
46     unsafe {
47         let f = Floats { a: 1.234567890e-15_f64,
48                  b: 0b_1010_1010_u8,
49                  c: 1.0987654321e-15_f64 };
50         let ff = rustrt::rust_dbg_abi_2(f);
51         println!("a: {}", ff.a as f64);
52         println!("b: {}", ff.b as uint);
53         println!("c: {}", ff.c as f64);
54         assert_eq!(ff.a, f.c + 1.0f64);
55         assert_eq!(ff.b, 0xff_u8);
56         assert_eq!(ff.c, f.a - 1.0f64);
57     }
58 }
59
60 #[cfg(any(target_arch = "x86", target_arch = "arm"))]
61 fn test2() {
62 }
63
64 pub fn main() {
65     test1();
66     test2();
67 }