]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/loads.rs
Auto merge of #33987 - crlf0710:patch-1, r=steveklabnik
[rust.git] / src / test / codegen / loads.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 #![feature(rustc_attrs)]
15
16 pub struct Bytes {
17   a: u8,
18   b: u8,
19   c: u8,
20   d: u8,
21 }
22
23 // CHECK-LABEL: @borrow
24 #[no_mangle]
25 #[rustc_no_mir] // FIXME #27840 MIR has different codegen.
26 pub fn borrow(x: &i32) -> &i32 {
27 // CHECK: load {{(i32\*, )?}}i32** %x{{.*}}, !nonnull
28     x
29 }
30
31 // CHECK-LABEL: @_box
32 #[no_mangle]
33 #[rustc_no_mir] // FIXME #27840 MIR has different codegen.
34 pub fn _box(x: Box<i32>) -> i32 {
35 // CHECK: load {{(i32\*, )?}}i32** %x{{.*}}, !nonnull
36     *x
37 }
38
39 // CHECK-LABEL: small_array_alignment
40 // The array is loaded as i32, but its alignment is lower, go with 1 byte to avoid target
41 // dependent alignment
42 #[no_mangle]
43 pub fn small_array_alignment(x: [i8; 4]) -> [i8; 4] {
44 // CHECK: [[VAR:%[0-9]+]] = load {{(i32, )?}}i32* %{{.*}}, align 1
45 // CHECK: ret i32 [[VAR]]
46     x
47 }
48
49 // CHECK-LABEL: small_struct_alignment
50 // The struct is loaded as i32, but its alignment is lower, go with 1 byte to avoid target
51 // dependent alignment
52 #[no_mangle]
53 pub fn small_struct_alignment(x: Bytes) -> Bytes {
54 // CHECK: [[VAR:%[0-9]+]] = load {{(i32, )?}}i32* %{{.*}}, align 1
55 // CHECK: ret i32 [[VAR]]
56     x
57 }