blob: 6135f49eb711be0c9a2e8c22bd6e84cb6b9fc444 [file] [log] [blame]
Björn Steinbrink67736752015-05-24 16:07:521// 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
Richard Diamond9a240252015-09-15 21:22:1613#![crate_type = "lib"]
14
Björn Steinbrink67736752015-05-24 16:07:5215pub 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]
Eduard Burtescubffb0de2016-03-06 12:28:1126pub fn small_array_alignment(x: &mut [i8; 4], y: [i8; 4]) {
Eduard Burtescue2528652016-06-07 21:35:0127// CHECK: [[TMP:%.+]] = alloca i32
Mark Simulacrum1be170b2016-12-31 23:00:2428// CHECK: %arg1 = alloca [4 x i8]
Eduard Burtescue2528652016-06-07 21:35:0129// CHECK: store i32 %1, i32* [[TMP]]
Eduard Burtescucb9b0ed2016-08-24 03:36:3730// CHECK: [[Y8:%[0-9]+]] = bitcast [4 x i8]* %arg1 to i8*
Eduard Burtescue2528652016-06-07 21:35:0131// CHECK: [[TMP8:%[0-9]+]] = bitcast i32* [[TMP]] to i8*
32// CHECK: call void @llvm.memcpy.{{.*}}(i8* [[Y8]], i8* [[TMP8]], i{{[0-9]+}} 4, i32 1, i1 false)
Eduard Burtescubffb0de2016-03-06 12:28:1133 *x = y;
Björn Steinbrink67736752015-05-24 16:07:5234}
35
36// CHECK-LABEL: small_struct_alignment
37// The struct is stored as i32, but its alignment is lower, go with 1 byte to avoid target
38// dependent alignment
39#[no_mangle]
Eduard Burtescubffb0de2016-03-06 12:28:1140pub fn small_struct_alignment(x: &mut Bytes, y: Bytes) {
Eduard Burtescue2528652016-06-07 21:35:0141// CHECK: [[TMP:%.+]] = alloca i32
Mark Simulacrum1be170b2016-12-31 23:00:2442// CHECK: %arg1 = alloca %Bytes
Eduard Burtescue2528652016-06-07 21:35:0143// CHECK: store i32 %1, i32* [[TMP]]
Eduard Burtescucb9b0ed2016-08-24 03:36:3744// CHECK: [[Y8:%[0-9]+]] = bitcast %Bytes* %arg1 to i8*
Eduard Burtescue2528652016-06-07 21:35:0145// CHECK: [[TMP8:%[0-9]+]] = bitcast i32* [[TMP]] to i8*
46// CHECK: call void @llvm.memcpy.{{.*}}(i8* [[Y8]], i8* [[TMP8]], i{{[0-9]+}} 4, i32 1, i1 false)
Eduard Burtescubffb0de2016-03-06 12:28:1147 *x = y;
Björn Steinbrink67736752015-05-24 16:07:5248}