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...@@ -5470,7 +5470,9 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab
5470static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable,5470static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable,
5471 IrInstructionSuspendBegin *instruction)5471 IrInstructionSuspendBegin *instruction)
5472{5472{
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 }
5474 return nullptr;5476 return nullptr;
5475}5477}
54765478
src/ir.cpp+1-1
...@@ -7914,7 +7914,7 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod...@@ -7914,7 +7914,7 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod
7914 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res));7914 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res));
7915 }7915 }
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));
7918}7918}
79197919
7920static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope,7920static 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" {...@@ -760,3 +760,17 @@ test "async call a generic function" {
760 };760 };
761 _ = async S.doTheTest();761 _ = async S.doTheTest();
762}762}
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}