Björn Steinbrink | 6773675 | 2015-05-24 16:07:52 | [diff] [blame] | 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 | |
Richard Diamond | 9a24025 | 2015-09-15 21:22:16 | [diff] [blame] | 13 | #![crate_type = "lib"] |
| 14 | |
Björn Steinbrink | 6773675 | 2015-05-24 16:07:52 | [diff] [blame] | 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] |
Eduard Burtescu | bffb0de | 2016-03-06 12:28:11 | [diff] [blame] | 26 | pub fn small_array_alignment(x: &mut [i8; 4], y: [i8; 4]) { |
Eduard Burtescu | e252865 | 2016-06-07 21:35:01 | [diff] [blame] | 27 | // CHECK: [[TMP:%.+]] = alloca i32 |
Mark Simulacrum | 1be170b | 2016-12-31 23:00:24 | [diff] [blame] | 28 | // CHECK: %arg1 = alloca [4 x i8] |
Eduard Burtescu | e252865 | 2016-06-07 21:35:01 | [diff] [blame] | 29 | // CHECK: store i32 %1, i32* [[TMP]] |
Eduard Burtescu | cb9b0ed | 2016-08-24 03:36:37 | [diff] [blame] | 30 | // CHECK: [[Y8:%[0-9]+]] = bitcast [4 x i8]* %arg1 to i8* |
Eduard Burtescu | e252865 | 2016-06-07 21:35:01 | [diff] [blame] | 31 | // 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 Burtescu | bffb0de | 2016-03-06 12:28:11 | [diff] [blame] | 33 | *x = y; |
Björn Steinbrink | 6773675 | 2015-05-24 16:07:52 | [diff] [blame] | 34 | } |
| 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 Burtescu | bffb0de | 2016-03-06 12:28:11 | [diff] [blame] | 40 | pub fn small_struct_alignment(x: &mut Bytes, y: Bytes) { |
Eduard Burtescu | e252865 | 2016-06-07 21:35:01 | [diff] [blame] | 41 | // CHECK: [[TMP:%.+]] = alloca i32 |
Mark Simulacrum | 1be170b | 2016-12-31 23:00:24 | [diff] [blame] | 42 | // CHECK: %arg1 = alloca %Bytes |
Eduard Burtescu | e252865 | 2016-06-07 21:35:01 | [diff] [blame] | 43 | // CHECK: store i32 %1, i32* [[TMP]] |
Eduard Burtescu | cb9b0ed | 2016-08-24 03:36:37 | [diff] [blame] | 44 | // CHECK: [[Y8:%[0-9]+]] = bitcast %Bytes* %arg1 to i8* |
Eduard Burtescu | e252865 | 2016-06-07 21:35:01 | [diff] [blame] | 45 | // 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 Burtescu | bffb0de | 2016-03-06 12:28:11 | [diff] [blame] | 47 | *x = y; |
Björn Steinbrink | 6773675 | 2015-05-24 16:07:52 | [diff] [blame] | 48 | } |