authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-27 18:01:26-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-27 18:01:39-04:00
loge491c381896b6f36366bf554f149f79d5be8f9dd
tree65e3640a80566aea58ccf9f5d3f5b23377f05a8a
parent341bd0dfa42a729aefff56e48a67a21cb3ea0822

resume detects resuming when not suspended


1 files changed, 14 insertions(+), 4 deletions(-)

src/ir.cpp+14-4
......@@ -6713,13 +6713,15 @@ static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node)
67136713
67146714 IrBasicBlock *done_block = ir_create_basic_block(irb, scope, "ResumeDone");
67156715 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");
67166718
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);
67196720 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);
67206723 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, false);
67216724 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);
67236725 IrInstruction *promise_T_type_val = ir_build_const_type(irb, scope, node,
67246726 get_promise_type(irb->codegen, irb->codegen->builtin_types.entry_void));
67256727
......@@ -6732,7 +6734,7 @@ static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node)
67326734
67336735 // clear the is_suspended bit
67346736 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,
67366738 AtomicRmwOp_and, AtomicOrderSeqCst);
67376739
67386740 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)
67406742 ir_build_cond_br(irb, scope, node, is_canceled_bool, done_block, not_canceled_block, is_comptime);
67416743
67426744 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);
67436753 ir_build_coro_resume(irb, scope, node, target_inst);
67446754 ir_build_br(irb, scope, node, done_block, is_comptime);
67456755