Skip to content

Commit 652ae9f

Browse files
committed
Fix structure returns harder.
1 parent e3a3a03 commit 652ae9f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/comp/middle/trans.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,15 @@ impure fn trans_call(@block_ctxt cx, @ast.expr f,
14031403
auto args_res = trans_args(f_res._0.bcx, args, fn_ty);
14041404
auto retval = args_res._0.build.FastCall(f_res._0.val, args_res._1);
14051405

1406+
// Structured returns come back as first-class values. This is nice for
1407+
// LLVM but wrong for us; we treat structured values by pointer in
1408+
// most of our code here. So spill it to an alloca.
1409+
if (typeck.type_is_structural(ret_ty)) {
1410+
auto local = args_res._0.build.Alloca(type_of(cx.fcx.ccx, ret_ty));
1411+
args_res._0.build.Store(retval, local);
1412+
retval = local;
1413+
}
1414+
14061415
// Retval doesn't correspond to anything really tangible in the frame, but
14071416
// it's a ref all the same, so we put a note here to drop it when we're
14081417
// done in this scope.

0 commit comments

Comments
 (0)