about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorBrian Anderson <andersrb@gmail.com>2011-05-17 20:35:37 -0400
committerBrian Anderson <andersrb@gmail.com>2011-05-17 22:25:24 -0400
commita98ea4f3ef60ddd83ff19d67fbc9db172893a521 (patch)
tree68392780c55c2763ad7e22c4e0a83c0f44ecb51b /src/comp
parente840a37f33869ddee5785473617a2b5f834dca9f (diff)
downloadrust-a98ea4f3ef60ddd83ff19d67fbc9db172893a521.tar.gz
rust-a98ea4f3ef60ddd83ff19d67fbc9db172893a521.zip
rustc: Run block cleanups on else if blocks
With the scheme used to translate 'else if' currently the if expression is
translated in a new (else) scope context. If that if expression wants to
result in a value that requires refcounting then it will need to drop the
refcount in the cleanups of the else block.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/trans.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 632fdaedd5a..96e92aeb852 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -3706,8 +3706,15 @@ fn trans_if(&@block_ctxt cx, &@ast::expr cond,
     alt (els) {
         case (some[@ast::expr](?elexpr)) {
             alt (elexpr.node) {
-                case (ast::expr_if(_, _, _, _)) {
-                    else_res = trans_expr(else_cx, elexpr);
+                case (ast::expr_if(?cond, ?thn, ?els, _)) {
+                    else_res = trans_if(else_cx, cond, thn, els);
+                    // The if expression may need to use the else context to
+                    // drop the refcount of its result so we need to run the
+                    // cleanups
+                    auto bcx = else_res.bcx;
+                    bcx = trans_block_cleanups(bcx,
+                                               find_scope_cx(bcx));
+                    else_res = res(bcx, else_res.val);
                 }
                 case (ast::expr_block(?blk, _)) {
                     // Calling trans_block directly instead of trans_expr