]> git.proxmox.com Git - rustc.git/blob - src/test/codegen/lifetime_start_end.rs
New upstream version 1.15.0+dfsg1
[rustc.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 #![feature(rustc_attrs)]
15
16 // CHECK-LABEL: @test
17 #[no_mangle]
18 #[rustc_mir] // FIXME #27840 MIR has different codegen.
19 pub fn test() {
20 let a = 0;
21 &a; // keep variable in an alloca
22
23 // CHECK: [[S_a:%[0-9]+]] = bitcast i32* %a to i8*
24 // CHECK: call void @llvm.lifetime.start(i{{[0-9 ]+}}, i8* [[S_a]])
25
26 {
27 let b = &Some(a);
28 &b; // keep variable in an alloca
29
30 // CHECK: [[S_b:%[0-9]+]] = bitcast %"core::option::Option<i32>"** %b to i8*
31 // CHECK: call void @llvm.lifetime.start(i{{[0-9 ]+}}, i8* [[S_b]])
32
33 // CHECK: [[S__5:%[0-9]+]] = bitcast %"core::option::Option<i32>"* %_5 to i8*
34 // CHECK: call void @llvm.lifetime.start(i{{[0-9 ]+}}, i8* [[S__5]])
35
36 // CHECK: [[E__5:%[0-9]+]] = bitcast %"core::option::Option<i32>"* %_5 to i8*
37 // CHECK: call void @llvm.lifetime.end(i{{[0-9 ]+}}, i8* [[E__5]])
38
39 // CHECK: [[E_b:%[0-9]+]] = bitcast %"core::option::Option<i32>"** %b to i8*
40 // CHECK: call void @llvm.lifetime.end(i{{[0-9 ]+}}, i8* [[E_b]])
41 }
42
43 let c = 1;
44 &c; // keep variable in an alloca
45
46 // CHECK: [[S_c:%[0-9]+]] = bitcast i32* %c to i8*
47 // CHECK: call void @llvm.lifetime.start(i{{[0-9 ]+}}, i8* [[S_c]])
48
49 // CHECK: [[E_c:%[0-9]+]] = bitcast i32* %c to i8*
50 // CHECK: call void @llvm.lifetime.end(i{{[0-9 ]+}}, i8* [[E_c]])
51
52 // CHECK: [[E_a:%[0-9]+]] = bitcast i32* %a to i8*
53 // CHECK: call void @llvm.lifetime.end(i{{[0-9 ]+}}, i8* [[E_a]])
54 }