Skip to content

Commit 93312a2

Browse files
committed
---
yaml --- r: 1963 b: refs/heads/master c: f16e724 h: refs/heads/master i: 1961: 4cc4480 1959: 87d23dd v: v3
1 parent 8a2078c commit 93312a2

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 524e80358254575bb699756c405050da6c920e28
2+
refs/heads/master: f16e7242d2433378a0530d31427fad4ddd36c69f

trunk/src/comp/middle/trans.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5384,21 +5384,29 @@ fn trans_block(@block_ctxt cx, &ast.block b) -> result {
53845384
if (is_terminated(bcx)) {
53855385
ret r;
53865386
} else {
5387-
// The value resulting from the block gets copied into an
5388-
// alloca created in an enclosing scope and it's refcount
5389-
// bumped so that it can escape this block. This means that
5390-
// it will definitely live until the end of the enclosing
5391-
// scope, even if nobody uses it, which may be something of
5392-
// a surprise.
5393-
53945387
auto r_ty = ty.expr_ty(e);
53955388

53965389
if (ty.type_is_boxed(r_ty)) {
5397-
5398-
// Create an alloca up in the llallocas block to hold the
5399-
// expression result.
5390+
// The value resulting from the block gets copied into an
5391+
// alloca created in an outer scope and it's refcount
5392+
// bumped so that it can escape this block. This means
5393+
// that it will definitely live until the end of the
5394+
// enclosing scope, even if nobody uses it, which may be
5395+
// something of a surprise.
5396+
5397+
// It's possible we never hit this block, so the alloca
5398+
// must be initialized to null, then when the potential
5399+
// value finally goes out of scope the drop glue will see
5400+
// that it was never used and ignore it.
5401+
5402+
// NB: Here we're building and initalizing the alloca in
5403+
// the alloca context, not this block's context.
54005404
auto res_alloca = alloc_ty(bcx, r_ty);
5401-
bcx = res_alloca.bcx;
5405+
auto alloca_ty = type_of(bcx.fcx.ccx, r_ty);
5406+
auto builder = new_builder(bcx.fcx.llallocas);
5407+
builder.Store(C_null(alloca_ty), res_alloca.val);
5408+
5409+
// Now we're working in our own block context again
54025410
auto res_copy = copy_ty(bcx, INIT,
54035411
res_alloca.val, r.val, r_ty);
54045412
bcx = res_copy.bcx;

0 commit comments

Comments
 (0)