From 4ac6c4d6bfb8f7ada2799ddb5ce3a9797be0518d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 26 Feb 2018 21:14:15 -0500 Subject: workaround llvm coro transformations by making alloc and free functions be parameters to async functions instead of using getelementptr in the DynAlloc block See #727 --- src/analyze.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index ce9e99f8fa..26924cc7db 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1006,13 +1006,13 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { fn_type_id->return_type->id == TypeTableEntryIdErrorSet); // +1 for maybe making the first argument the return value // +1 for maybe first argument the error return trace - // +2 for maybe arguments async allocator and error code pointer - LLVMTypeRef *gen_param_types = allocate(4 + fn_type_id->param_count); + // +4 for maybe arguments async allocator and error code pointer + LLVMTypeRef *gen_param_types = allocate(6 + fn_type_id->param_count); // +1 because 0 is the return type and // +1 for maybe making first arg ret val and // +1 for maybe first argument the error return trace - // +2 for maybe arguments async allocator and error code pointer - ZigLLVMDIType **param_di_types = allocate(5 + fn_type_id->param_count); + // +4 for maybe arguments async allocator and error code pointer + ZigLLVMDIType **param_di_types = allocate(7 + fn_type_id->param_count); param_di_types[0] = fn_type_id->return_type->di_type; size_t gen_param_index = 0; TypeTableEntry *gen_return_type; @@ -1049,6 +1049,32 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { param_di_types[gen_param_index] = gen_type->di_type; } + { + // async alloc fn param + assert(fn_type_id->async_allocator_type->id == TypeTableEntryIdPointer); + TypeTableEntry *struct_type = fn_type_id->async_allocator_type->data.pointer.child_type; + TypeStructField *alloc_fn_field = find_struct_type_field(struct_type, buf_create_from_str("allocFn")); + assert(alloc_fn_field->type_entry->id == TypeTableEntryIdFn); + TypeTableEntry *gen_type = alloc_fn_field->type_entry; + gen_param_types[gen_param_index] = gen_type->type_ref; + gen_param_index += 1; + // after the gen_param_index += 1 because 0 is the return type + param_di_types[gen_param_index] = gen_type->di_type; + } + + { + // async free fn param + assert(fn_type_id->async_allocator_type->id == TypeTableEntryIdPointer); + TypeTableEntry *struct_type = fn_type_id->async_allocator_type->data.pointer.child_type; + TypeStructField *free_fn_field = find_struct_type_field(struct_type, buf_create_from_str("freeFn")); + assert(free_fn_field->type_entry->id == TypeTableEntryIdFn); + TypeTableEntry *gen_type = free_fn_field->type_entry; + gen_param_types[gen_param_index] = gen_type->type_ref; + gen_param_index += 1; + // after the gen_param_index += 1 because 0 is the return type + param_di_types[gen_param_index] = gen_type->di_type; + } + { // error code pointer TypeTableEntry *gen_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false); -- cgit v1.2.3