]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/stores.rs
Enable emission of alignment attrs for pointer params
[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 // ignore-tidy-linelength
13 // min-llvm-version 7.0
14
15 #![crate_type = "lib"]
16
17 pub struct Bytes {
18   a: u8,
19   b: u8,
20   c: u8,
21   d: u8,
22 }
23
24 // CHECK-LABEL: small_array_alignment
25 // The array is stored as i32, but its alignment is lower, go with 1 byte to avoid target
26 // dependent alignment
27 #[no_mangle]
28 pub fn small_array_alignment(x: &mut [i8; 4], y: [i8; 4]) {
29 // CHECK: [[TMP:%.+]] = alloca i32
30 // CHECK: %y = alloca [4 x i8]
31 // CHECK: store i32 %0, i32* [[TMP]]
32 // CHECK: [[Y8:%[0-9]+]] = bitcast [4 x i8]* %y to i8*
33 // CHECK: [[TMP8:%[0-9]+]] = bitcast i32* [[TMP]] to i8*
34 // CHECK: call void @llvm.memcpy.{{.*}}(i8* align 1 [[Y8]], i8* align 4 [[TMP8]], i{{[0-9]+}} 4, i1 false)
35     *x = y;
36 }
37
38 // CHECK-LABEL: small_struct_alignment
39 // The struct is stored as i32, but its alignment is lower, go with 1 byte to avoid target
40 // dependent alignment
41 #[no_mangle]
42 pub fn small_struct_alignment(x: &mut Bytes, y: Bytes) {
43 // CHECK: [[TMP:%.+]] = alloca i32
44 // CHECK: %y = alloca %Bytes
45 // CHECK: store i32 %0, i32* [[TMP]]
46 // CHECK: [[Y8:%[0-9]+]] = bitcast %Bytes* %y to i8*
47 // CHECK: [[TMP8:%[0-9]+]] = bitcast i32* [[TMP]] to i8*
48 // CHECK: call void @llvm.memcpy.{{.*}}(i8* align 1 [[Y8]], i8* align 4 [[TMP8]], i{{[0-9]+}} 4, i1 false)
49     *x = y;
50 }