| ... | ... | @@ -6713,13 +6713,15 @@ static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) |
| 6713 | 6713 | |
| 6714 | 6714 | IrBasicBlock *done_block = ir_create_basic_block(irb, scope, "ResumeDone"); |
| 6715 | 6715 | IrBasicBlock *not_canceled_block = ir_create_basic_block(irb, scope, "NotCanceled"); |
| 6716 | IrBasicBlock *suspended_block = ir_create_basic_block(irb, scope, "IsSuspended"); |
| 6717 | IrBasicBlock *not_suspended_block = ir_create_basic_block(irb, scope, "IsNotSuspended"); |
| 6716 | 6718 | |
| 6717 | | IrInstruction *inverted_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b010 |
| 6718 | | IrInstruction *mask = ir_build_un_op(irb, scope, node, IrUnOpBinNot, inverted_mask); |
| 6719 | IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0); |
| 6719 | 6720 | IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001 |
| 6721 | IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b010 |
| 6722 | IrInstruction *and_mask = ir_build_un_op(irb, scope, node, IrUnOpBinNot, is_suspended_mask); |
| 6720 | 6723 | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, false); |
| 6721 | 6724 | IrInstruction *usize_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_usize); |
| 6722 | | IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0); |
| 6723 | 6725 | IrInstruction *promise_T_type_val = ir_build_const_type(irb, scope, node, |
| 6724 | 6726 | get_promise_type(irb->codegen, irb->codegen->builtin_types.entry_void)); |
| 6725 | 6727 | |
| ... | ... | @@ -6732,7 +6734,7 @@ static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) |
| 6732 | 6734 | |
| 6733 | 6735 | // clear the is_suspended bit |
| 6734 | 6736 | IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node, |
| 6735 | | usize_type_val, atomic_state_ptr, nullptr, mask, nullptr, |
| 6737 | usize_type_val, atomic_state_ptr, nullptr, and_mask, nullptr, |
| 6736 | 6738 | AtomicRmwOp_and, AtomicOrderSeqCst); |
| 6737 | 6739 | |
| 6738 | 6740 | IrInstruction *is_canceled_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, is_canceled_mask, false); |
| ... | ... | @@ -6740,6 +6742,14 @@ static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) |
| 6740 | 6742 | ir_build_cond_br(irb, scope, node, is_canceled_bool, done_block, not_canceled_block, is_comptime); |
| 6741 | 6743 | |
| 6742 | 6744 | ir_set_cursor_at_end_and_append_block(irb, not_canceled_block); |
| 6745 | IrInstruction *is_suspended_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, is_suspended_mask, false); |
| 6746 | IrInstruction *is_suspended_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, is_suspended_value, zero, false); |
| 6747 | ir_build_cond_br(irb, scope, node, is_suspended_bool, suspended_block, not_suspended_block, is_comptime); |
| 6748 | |
| 6749 | ir_set_cursor_at_end_and_append_block(irb, not_suspended_block); |
| 6750 | ir_build_unreachable(irb, scope, node); |
| 6751 | |
| 6752 | ir_set_cursor_at_end_and_append_block(irb, suspended_block); |
| 6743 | 6753 | ir_build_coro_resume(irb, scope, node, target_inst); |
| 6744 | 6754 | ir_build_br(irb, scope, node, done_block, is_comptime); |
| 6745 | 6755 | |