]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/stores.rs
Auto merge of #28569 - semarie:stdcpp-tests, r=alexcrichton
[rust.git] / src / test / codegen / stores.rs
1 // Copyright 2015 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 // compile-flags: -C no-prepopulate-passes
12
13 #![crate_type = "lib"]
14
15 pub struct Bytes {
16   a: u8,
17   b: u8,
18   c: u8,
19   d: u8,
20 }
21
22 // CHECK-LABEL: small_array_alignment
23 // The array is stored as i32, but its alignment is lower, go with 1 byte to avoid target
24 // dependent alignment
25 #[no_mangle]
26 pub fn small_array_alignment(x: &mut [i8; 4]) {
27 // CHECK: [[VAR:%[0-9]+]] = load {{(\[4 x i8\]\*, )?}}[4 x i8]** %x
28 // CHECK: [[VAR2:%[0-9]+]] = bitcast [4 x i8]* [[VAR]] to i32*
29 // CHECK: store i32 %{{.*}}, i32* [[VAR2]], align 1
30     *x = [0; 4];
31 }
32
33 // CHECK-LABEL: small_struct_alignment
34 // The struct is stored as i32, but its alignment is lower, go with 1 byte to avoid target
35 // dependent alignment
36 #[no_mangle]
37 pub fn small_struct_alignment(x: &mut Bytes) {
38 // CHECK: [[VAR:%[0-9]+]] = load {{(%Bytes\*, )?}}%Bytes** %x
39 // CHECK: [[VAR2:%[0-9]+]] = bitcast %Bytes* [[VAR]] to i32*
40 // CHECK: store i32 %{{.*}}, i32* [[VAR2]], align 1
41     *x = Bytes {
42         a: 0,
43         b: 0,
44         c: 0,
45         d: 0,
46     };
47 }