diff --git a/src/codegen.cpp b/src/codegen.cpp index 7e809f482..622ade712 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -5470,7 +5470,9 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable, IrInstructionSuspendBegin *instruction) { - instruction->resume_bb = gen_suspend_begin(g, "SuspendResume"); + if (fn_is_async(g->cur_fn)) { + instruction->resume_bb = gen_suspend_begin(g, "SuspendResume"); + } return nullptr; } diff --git a/src/ir.cpp b/src/ir.cpp index d6fba2385..3287a6bd3 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -7914,7 +7914,7 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res)); } - return ir_build_suspend_finish(irb, parent_scope, node, begin); + return ir_mark_gen(ir_build_suspend_finish(irb, parent_scope, node, begin)); } static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope, diff --git a/test/stage1/behavior/async_fn.zig b/test/stage1/behavior/async_fn.zig index b5e1d3a63..fea713b72 100644 --- a/test/stage1/behavior/async_fn.zig +++ b/test/stage1/behavior/async_fn.zig @@ -760,3 +760,17 @@ test "async call a generic function" { }; _ = async S.doTheTest(); } + +test "return from suspend block" { + const S = struct { + fn doTheTest() void { + expect(func() == 1234); + } + fn func() i32 { + suspend { + return 1234; + } + } + }; + _ = async S.doTheTest(); +}