@@ -927,6 +927,21 @@ static LLVMValueRef get_memcpy_fn_val(CodeGen *g) {
927
927
return g->memcpy_fn_val ;
928
928
}
929
929
930
+ static LLVMValueRef get_coro_destroy_fn_val (CodeGen *g) {
931
+ if (g->coro_destroy_fn_val )
932
+ return g->coro_destroy_fn_val ;
933
+
934
+ LLVMTypeRef param_types[] = {
935
+ LLVMPointerType (LLVMInt8Type (), 0 ),
936
+ };
937
+ LLVMTypeRef fn_type = LLVMFunctionType (LLVMVoidType (), param_types, 1 , false );
938
+ Buf *name = buf_sprintf (" llvm.coro.destroy" );
939
+ g->coro_destroy_fn_val = LLVMAddFunction (g->module , buf_ptr (name), fn_type);
940
+ assert (LLVMGetIntrinsicID (g->coro_destroy_fn_val ));
941
+
942
+ return g->coro_destroy_fn_val ;
943
+ }
944
+
930
945
static LLVMValueRef get_return_address_fn_val (CodeGen *g) {
931
946
if (g->return_address_fn_val )
932
947
return g->return_address_fn_val ;
@@ -3113,7 +3128,9 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *execu
3113
3128
}
3114
3129
3115
3130
static LLVMValueRef ir_render_cancel (CodeGen *g, IrExecutable *executable, IrInstructionCancel *instruction) {
3116
- zig_panic (" TODO ir_render_cancel" );
3131
+ LLVMValueRef target_handle = ir_llvm_value (g, instruction->target );
3132
+ LLVMBuildCall (g->builder , get_coro_destroy_fn_val (g), &target_handle, 1 , " " );
3133
+ return nullptr ;
3117
3134
}
3118
3135
3119
3136
static LLVMValueRef ir_render_get_implicit_allocator (CodeGen *g, IrExecutable *executable, IrInstructionGetImplicitAllocator *instruction) {
0 commit comments