Skip to content

Commit 1eaa113

Browse files
committed
Emit proper lifetime start intrinsics for personality slots
We currently only emit a single call to the lifetime start intrinsic for the personality slot alloca. This happens because we create that call at the time that we create the alloca, instead of creating it each time we start using it. Because LLVM usually removes the alloca before the lifetime intrinsics are even considered, this didn't cause any problems yet, but we should fix this anyway.
1 parent e1cec5d commit 1eaa113

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/librustc_trans/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,6 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
762762
let llretty = Type::struct_(ccx, &[Type::i8p(ccx), Type::i32(ccx)], false);
763763
let slot = bcx.alloca(llretty, "personalityslot");
764764
self.llpersonalityslot = Some(slot);
765-
Lifetime::Start.call(bcx, slot);
766765
slot
767766
}
768767
}
@@ -794,6 +793,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
794793
let llretval = bcx.landing_pad(llretty, llpersonality, 1, self.llfn);
795794
bcx.set_cleanup(llretval);
796795
let slot = self.get_personality_slot(&bcx);
796+
Lifetime::Start.call(&bcx, slot);
797797
bcx.store(llretval, slot, None);
798798
bcx.br(target_bb);
799799
bcx.llbb()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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: -O -C no-prepopulate-passes
12+
13+
#![crate_type="lib"]
14+
15+
struct S;
16+
17+
impl Drop for S {
18+
fn drop(&mut self) {
19+
}
20+
}
21+
22+
fn might_unwind() {
23+
}
24+
25+
// CHECK-LABEL: @test
26+
#[no_mangle]
27+
pub fn test() {
28+
let _s = S;
29+
// Check that the personality slot alloca gets a lifetime start in each cleanup block, not just
30+
// in the first one.
31+
// CHECK-LABEL: cleanup:
32+
// CHECK: bitcast{{.*}}personalityslot
33+
// CHECK-NEXT: call void @llvm.lifetime.start
34+
// CHECK-LABEL: cleanup1:
35+
// CHECK: bitcast{{.*}}personalityslot
36+
// CHECK-NEXT: call void @llvm.lifetime.start
37+
might_unwind();
38+
might_unwind();
39+
}

0 commit comments

Comments
 (0)