diff --git a/src/all_types.hpp b/src/all_types.hpp index 002a2d4a4c..e9b4561eba 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1609,6 +1609,7 @@ struct CodeGen { LLVMValueRef trap_fn_val; LLVMValueRef return_address_fn_val; LLVMValueRef frame_address_fn_val; + LLVMValueRef coro_destroy_fn_val; bool error_during_imports; const char **clang_argv; diff --git a/src/codegen.cpp b/src/codegen.cpp index ec14d85064..783f5fd8fe 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -927,6 +927,21 @@ static LLVMValueRef get_memcpy_fn_val(CodeGen *g) { return g->memcpy_fn_val; } +static LLVMValueRef get_coro_destroy_fn_val(CodeGen *g) { + if (g->coro_destroy_fn_val) + return g->coro_destroy_fn_val; + + LLVMTypeRef param_types[] = { + LLVMPointerType(LLVMInt8Type(), 0), + }; + LLVMTypeRef fn_type = LLVMFunctionType(LLVMVoidType(), param_types, 1, false); + Buf *name = buf_sprintf("llvm.coro.destroy"); + g->coro_destroy_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type); + assert(LLVMGetIntrinsicID(g->coro_destroy_fn_val)); + + return g->coro_destroy_fn_val; +} + static LLVMValueRef get_return_address_fn_val(CodeGen *g) { if (g->return_address_fn_val) return g->return_address_fn_val; @@ -3113,7 +3128,9 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *execu } static LLVMValueRef ir_render_cancel(CodeGen *g, IrExecutable *executable, IrInstructionCancel *instruction) { - zig_panic("TODO ir_render_cancel"); + LLVMValueRef target_handle = ir_llvm_value(g, instruction->target); + LLVMBuildCall(g->builder, get_coro_destroy_fn_val(g), &target_handle, 1, ""); + return nullptr; } static LLVMValueRef ir_render_get_implicit_allocator(CodeGen *g, IrExecutable *executable, IrInstructionGetImplicitAllocator *instruction) {