authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-27 18:37:30-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-27 18:37:30-04:00
logf0c049d02b68a8740096df633a41b78d90fd34cd
tree99d44e1dde3dab8a8f389bd2d37a94c173090a9b
parente5beca886ddf3138351765e1239b626e7bd612c6

detect double await


1 files changed, 12 insertions(+), 0 deletions(-)

src/ir.cpp+12
......@@ -6796,6 +6796,9 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
67966796 ir_build_store_ptr(irb, scope, node, err_ret_trace_ptr_field_ptr, err_ret_trace_ptr);
67976797 }
67986798
6799 IrBasicBlock *already_awaited_block = ir_create_basic_block(irb, scope, "AlreadyAwaited");
6800 IrBasicBlock *not_awaited_block = ir_create_basic_block(irb, scope, "NotAwaited");
6801
67996802 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);
68006803 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,
68016804 atomic_state_field_name);
......@@ -6823,6 +6826,15 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
68236826 IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node,
68246827 usize_type_val, atomic_state_ptr, nullptr, mask_bits, nullptr,
68256828 AtomicRmwOp_or, AtomicOrderSeqCst);
6829
6830 IrInstruction *is_awaited_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, await_mask, false);
6831 IrInstruction *is_awaited_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, is_awaited_value, zero, false);
6832 ir_build_cond_br(irb, scope, node, is_awaited_bool, already_awaited_block, not_awaited_block, const_bool_false);
6833
6834 ir_set_cursor_at_end_and_append_block(irb, already_awaited_block);
6835 ir_build_unreachable(irb, scope, node);
6836
6837 ir_set_cursor_at_end_and_append_block(irb, not_awaited_block);
68266838 IrInstruction *await_handle_addr = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, ptr_mask, false);
68276839 IrInstruction *is_non_null = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, await_handle_addr, zero, false);
68286840 IrBasicBlock *yes_suspend_block = ir_create_basic_block(irb, scope, "YesSuspend");