@@ -67,13 +67,8 @@ pub fn trans_if(bcx: block,
67
67
expr:: trans_to_datum( bcx, cond) . to_result( ) ;
68
68
69
69
let then_bcx_in = scope_block( bcx, thn. info( ) , "then" ) ;
70
- let else_bcx_in = scope_block( bcx, els. info( ) , "else" ) ;
71
70
72
71
let cond_val = bool_to_i1( bcx, cond_val) ;
73
- CondBr ( bcx, cond_val, then_bcx_in. llbb, else_bcx_in. llbb) ;
74
-
75
- debug ! ( "then_bcx_in=%s, else_bcx_in=%s" ,
76
- then_bcx_in. to_str( ) , else_bcx_in. to_str( ) ) ;
77
72
78
73
let then_bcx_out = trans_block( then_bcx_in, thn, dest) ;
79
74
let then_bcx_out = trans_block_cleanups( then_bcx_out,
@@ -83,9 +78,10 @@ pub fn trans_if(bcx: block,
83
78
// because trans_expr will create another scope block
84
79
// context for the block, but we've already got the
85
80
// 'else' context
86
- let else_bcx_out = match els {
81
+ let ( else_bcx_in , next_bcx ) = match els {
87
82
Some ( elexpr) => {
88
- match elexpr. node {
83
+ let else_bcx_in = scope_block( bcx, els. info( ) , "else" ) ;
84
+ let else_bcx_out = match elexpr. node {
89
85
ast : : expr_if( _, _, _) => {
90
86
let elseif_blk = ast_util:: block_from_expr( elexpr) ;
91
87
trans_block( else_bcx_in, & elseif_blk, dest)
@@ -95,14 +91,25 @@ pub fn trans_if(bcx: block,
95
91
}
96
92
// would be nice to have a constraint on ifs
97
93
_ => bcx. tcx( ) . sess. bug( "strange alternative in if" )
98
- }
94
+ } ;
95
+ let else_bcx_out = trans_block_cleanups( else_bcx_out,
96
+ block_cleanups( else_bcx_in) ) ;
97
+
98
+ ( else_bcx_in, join_blocks( bcx, [ then_bcx_out, else_bcx_out] ) )
99
+ }
100
+ _ => {
101
+ let next_bcx = sub_block( bcx, "next" ) ;
102
+ Br ( then_bcx_out, next_bcx. llbb) ;
103
+
104
+ ( next_bcx, next_bcx)
99
105
}
100
- _ => else_bcx_in
101
106
} ;
102
- let else_bcx_out = trans_block_cleanups( else_bcx_out,
103
- block_cleanups( else_bcx_in) ) ;
104
- return join_blocks( bcx, [ then_bcx_out, else_bcx_out] ) ;
105
107
108
+ debug ! ( "then_bcx_in=%s, else_bcx_in=%s" ,
109
+ then_bcx_in. to_str( ) , else_bcx_in. to_str( ) ) ;
110
+
111
+ CondBr ( bcx, cond_val, then_bcx_in. llbb, else_bcx_in. llbb) ;
112
+ next_bcx
106
113
}
107
114
108
115
pub fn join_blocks( parent_bcx: block, in_cxs: & [ block] ) -> block {
0 commit comments