authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-16 13:00:48-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-16 13:07:07-04:00
log5a2cbe239f4299b4412209148131a501ec023ceb
tree1652cb4c4bed1849f818979dd5d41d3a27ede5d3
parent2cb1f93894be3f48f0c49004515fa5e8190f69d9
signaturelock-open Commit is signed but in an unrecognized format.

fix and test case for returning from suspend block

See #3063

3 files changed, 18 insertions(+), 2 deletions(-)

src/codegen.cpp+3-1
......@@ -5470,7 +5470,9 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab
54705470static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable,
54715471 IrInstructionSuspendBegin *instruction)
54725472{
5473 instruction->resume_bb = gen_suspend_begin(g, "SuspendResume");
5473 if (fn_is_async(g->cur_fn)) {
5474 instruction->resume_bb = gen_suspend_begin(g, "SuspendResume");
5475 }
54745476 return nullptr;
54755477}
54765478
src/ir.cpp+1-1
......@@ -7914,7 +7914,7 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod
79147914 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res));
79157915 }
79167916
7917 return ir_build_suspend_finish(irb, parent_scope, node, begin);
7917 return ir_mark_gen(ir_build_suspend_finish(irb, parent_scope, node, begin));
79187918}
79197919
79207920static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope,
test/stage1/behavior/async_fn.zig+14
......@@ -760,3 +760,17 @@ test "async call a generic function" {
760760 };
761761 _ = async S.doTheTest();
762762}
763
764test "return from suspend block" {
765 const S = struct {
766 fn doTheTest() void {
767 expect(func() == 1234);
768 }
769 fn func() i32 {
770 suspend {
771 return 1234;
772 }
773 }
774 };
775 _ = async S.doTheTest();
776}