]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/lifetime_start_end.rs
Rollup merge of #55280 - vlad20012:add-libproc_macro-to-src-disrt, r=Mark-Simulacrum
[rust.git] / src / test / codegen / lifetime_start_end.rs
1 // Copyright 2016 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: -O -C no-prepopulate-passes
12
13 #![crate_type = "lib"]
14
15 // CHECK-LABEL: @test
16 #[no_mangle]
17 pub fn test() {
18     let a = 0;
19     &a; // keep variable in an alloca
20
21 // CHECK: [[S_a:%[0-9]+]] = bitcast i32* %a to i8*
22 // CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S_a]])
23
24     {
25         let b = &Some(a);
26         &b; // keep variable in an alloca
27
28 // CHECK: [[S_b:%[0-9]+]] = bitcast { i32, i32 }** %b to i8*
29 // CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S_b]])
30
31 // CHECK: [[S__4:%[0-9]+]] = bitcast { i32, i32 }* %_4 to i8*
32 // CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S__4]])
33
34 // CHECK: [[E__4:%[0-9]+]] = bitcast { i32, i32 }* %_4 to i8*
35 // CHECK: call void @llvm.lifetime.end{{.*}}(i{{[0-9 ]+}}, i8* [[E__4]])
36
37 // CHECK: [[E_b:%[0-9]+]] = bitcast { i32, i32 }** %b to i8*
38 // CHECK: call void @llvm.lifetime.end{{.*}}(i{{[0-9 ]+}}, i8* [[E_b]])
39     }
40
41     let c = 1;
42     &c; // keep variable in an alloca
43
44 // CHECK: [[S_c:%[0-9]+]] = bitcast i32* %c to i8*
45 // CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S_c]])
46
47 // CHECK: [[E_c:%[0-9]+]] = bitcast i32* %c to i8*
48 // CHECK: call void @llvm.lifetime.end{{.*}}(i{{[0-9 ]+}}, i8* [[E_c]])
49
50 // CHECK: [[E_a:%[0-9]+]] = bitcast i32* %a to i8*
51 // CHECK: call void @llvm.lifetime.end{{.*}}(i{{[0-9 ]+}}, i8* [[E_a]])
52 }