diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-02-25 16:15:14 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-02-25 16:15:14 -0500 |
| commit | 79f1ff574b3badf7cf0a0cd7632c529801b4c611 (patch) | |
| tree | c891a66cc0440e3fff7e90c6b8cf6e9cfb6c6c1f /src/codegen.cpp | |
| parent | bced3fb64cbb9006886bc237d959ce0f2ca3c3f7 (diff) | |
| download | zig-79f1ff574b3badf7cf0a0cd7632c529801b4c611.tar.gz zig-79f1ff574b3badf7cf0a0cd7632c529801b4c611.zip | |
codegen for coro_alloc_fail instruction
See #727
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index 0c8e601bc0..60667ac465 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3811,8 +3811,24 @@ static LLVMValueRef ir_render_coro_begin(CodeGen *g, IrExecutable *executable, I zig_panic("TODO ir_render_coro_begin"); } -static LLVMValueRef ir_render_coro_alloc_fail(CodeGen *g, IrExecutable *executable, IrInstructionCoroAllocFail *instruction) { - zig_panic("TODO ir_render_coro_alloc_fail"); +static LLVMValueRef ir_render_coro_alloc_fail(CodeGen *g, IrExecutable *executable, + IrInstructionCoroAllocFail *instruction) +{ + TypeTableEntry *src_return_type = g->cur_fn->type_entry->data.fn.fn_type_id.return_type; + bool prefix_arg_err_ret_stack = get_prefix_arg_err_ret_stack(g, src_return_type); + size_t err_code_ptr_arg_index = prefix_arg_err_ret_stack ? 2 : 1; + LLVMValueRef err_code_ptr_val = LLVMGetParam(g->cur_fn_val, err_code_ptr_arg_index); + LLVMValueRef err_code = ir_llvm_value(g, instruction->err_val); + LLVMBuildStore(g->builder, err_code, err_code_ptr_val); + + LLVMValueRef return_value; + if (ir_want_runtime_safety(g, &instruction->base)) { + return_value = LLVMConstNull(LLVMPointerType(LLVMInt8Type(), 0)); + } else { + return_value = LLVMGetUndef(LLVMPointerType(LLVMInt8Type(), 0)); + } + LLVMBuildRet(g->builder, return_value); + return nullptr; } static LLVMValueRef ir_render_coro_suspend(CodeGen *g, IrExecutable *executable, IrInstructionCoroSuspend *instruction) { |
