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