]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/slice-init.rs
Enable emission of alignment attrs for pointer params
[rust.git] / src / test / codegen / slice-init.rs
1 // Copyright 2017 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 // CHECK-LABEL: @zero_sized_elem
16 #[no_mangle]
17 pub fn zero_sized_elem() {
18     // CHECK-NOT: br label %repeat_loop_header{{.*}}
19     // CHECK-NOT: call void @llvm.memset.p0i8
20     let x = [(); 4];
21     drop(&x);
22 }
23
24 // CHECK-LABEL: @zero_len_array
25 #[no_mangle]
26 pub fn zero_len_array() {
27     // CHECK-NOT: br label %repeat_loop_header{{.*}}
28     // CHECK-NOT: call void @llvm.memset.p0i8
29     let x = [4; 0];
30     drop(&x);
31 }
32
33 // CHECK-LABEL: @byte_array
34 #[no_mangle]
35 pub fn byte_array() {
36     // CHECK: call void @llvm.memset.p0i8.i[[WIDTH:[0-9]+]](i8* {{.*}}, i8 7, i[[WIDTH]] 4
37     // CHECK-NOT: br label %repeat_loop_header{{.*}}
38     let x = [7u8; 4];
39     drop(&x);
40 }
41
42 #[allow(dead_code)]
43 #[derive(Copy, Clone)]
44 enum Init {
45     Loop,
46     Memset,
47 }
48
49 // CHECK-LABEL: @byte_enum_array
50 #[no_mangle]
51 pub fn byte_enum_array() {
52     // CHECK: call void @llvm.memset.p0i8.i[[WIDTH:[0-9]+]](i8* {{.*}}, i8 {{.*}}, i[[WIDTH]] 4
53     // CHECK-NOT: br label %repeat_loop_header{{.*}}
54     let x = [Init::Memset; 4];
55     drop(&x);
56 }
57
58 // CHECK-LABEL: @zeroed_integer_array
59 #[no_mangle]
60 pub fn zeroed_integer_array() {
61     // CHECK: call void @llvm.memset.p0i8.i[[WIDTH:[0-9]+]](i8* {{.*}}, i8 0, i[[WIDTH]] 16
62     // CHECK-NOT: br label %repeat_loop_header{{.*}}
63     let x = [0u32; 4];
64     drop(&x);
65 }
66
67 // CHECK-LABEL: @nonzero_integer_array
68 #[no_mangle]
69 pub fn nonzero_integer_array() {
70     // CHECK: br label %repeat_loop_header{{.*}}
71     // CHECK-NOT: call void @llvm.memset.p0i8
72     let x = [0x1a_2b_3c_4d_u32; 4];
73     drop(&x);
74 }