aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-02-26 21:14:15 -0500
committerAndrew Kelley <superjoe30@gmail.com>2018-02-26 21:14:15 -0500
commit4ac6c4d6bfb8f7ada2799ddb5ce3a9797be0518d (patch)
tree4ab97ddfa6d660de755eec346162df5125919d23 /src/analyze.cpp
parent3e86fb500dc918618a2ccaa5d942de98bd5fea47 (diff)
downloadzig-4ac6c4d6bfb8f7ada2799ddb5ce3a9797be0518d.tar.gz
zig-4ac6c4d6bfb8f7ada2799ddb5ce3a9797be0518d.zip
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
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp34
1 files changed, 30 insertions, 4 deletions
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<LLVMTypeRef>(4 + fn_type_id->param_count);
+ // +4 for maybe arguments async allocator and error code pointer
+ LLVMTypeRef *gen_param_types = allocate<LLVMTypeRef>(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<ZigLLVMDIType*>(5 + fn_type_id->param_count);
+ // +4 for maybe arguments async allocator and error code pointer
+ ZigLLVMDIType **param_di_types = allocate<ZigLLVMDIType*>(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;
@@ -1050,6 +1050,32 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
}
{
+ // 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);
gen_param_types[gen_param_index] = gen_type->type_ref;