about summary refs log tree commit diff
path: root/tests/ui/abi/numbers-arithmetic/float-struct.rs
blob: a958dc272722fb2e3e4f0f483b418fd3cb32dca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//@ run-pass

use std::fmt::Debug;
use std::hint::black_box;

#[repr(C)]
#[derive(Copy, Clone, PartialEq, Debug, Default)]
struct Regular(f32, f64);

#[repr(C, packed)]
#[derive(Copy, Clone, PartialEq, Debug, Default)]
struct Packed(f32, f64);

#[repr(C, align(64))]
#[derive(Copy, Clone, PartialEq, Debug, Default)]
struct AlignedF32(f32);

#[repr(C)]
#[derive(Copy, Clone, PartialEq, Debug, Default)]
struct Aligned(f64, AlignedF32);

#[inline(never)]
extern "C" fn read<T: Copy>(x: &T) -> T {
    *black_box(x)
}

#[inline(never)]
extern "C" fn write<T: Copy>(x: T, dest: &mut T) {
    *dest = black_box(x)
}

#[track_caller]
fn check<T: Copy + PartialEq + Debug + Default>(x: T) {
    assert_eq!(read(&x), x);
    let mut out = T::default();
    write(x, &mut out);
    assert_eq!(out, x);
}

fn main() {
    check(Regular(1.0, 2.0));
    check(Packed(3.0, 4.0));
    check(Aligned(5.0, AlignedF32(6.0)));
}