@@ -260,6 +260,8 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
260
260
// Apply debuginfo to the newly allocated locals.
261
261
fx. debug_introduce_locals ( & mut start_bx) ;
262
262
263
+ // If we have multiple return terminators, create a special return block. If this block is
264
+ // present, return terminator codegen will be a jump to it instead of a return.
263
265
if mir
264
266
. basic_blocks
265
267
. iter ( )
@@ -268,15 +270,21 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
268
270
> 1
269
271
{
270
272
let llbb = Bx :: append_block ( fx. cx , fx. llfn , "return" ) ;
271
- let mut bx = Bx :: build ( fx. cx , llbb) ;
272
- fx. codegen_return_terminator ( & mut bx) ;
273
273
fx. return_block = Some ( llbb) ;
274
274
}
275
275
276
276
// Codegen the body of each block using reverse postorder
277
277
for ( bb, _) in traversal:: reverse_postorder ( & mir) {
278
278
fx. codegen_block ( bb) ;
279
279
}
280
+
281
+ // Actually codegen the return block. We need to delay until here because our return place
282
+ // might not be generated yet, and will only be generated by handling codegen for the
283
+ // assignment to it.
284
+ if let Some ( llbb) = fx. return_block {
285
+ let mut bx = Bx :: build ( fx. cx , llbb) ;
286
+ fx. codegen_return_terminator ( & mut bx) ;
287
+ }
280
288
}
281
289
282
290
/// Produces, for each argument, a `Value` pointing at the
0 commit comments