| ... | ... | @@ -6174,6 +6174,7 @@ static void do_code_gen(CodeGen *g) { |
| 6174 | 6174 | clear_debug_source_node(g); |
| 6175 | 6175 | |
| 6176 | 6176 | bool is_async = fn_is_async(fn_table_entry); |
| 6177 | size_t async_var_index = coro_arg_start + (type_has_bits(fn_type_id->return_type) ? 1 : 0); |
| 6177 | 6178 | |
| 6178 | 6179 | if (want_sret || is_async) { |
| 6179 | 6180 | g->cur_ret_ptr = LLVMGetParam(fn, 0); |
| ... | ... | @@ -6206,25 +6207,27 @@ static void do_code_gen(CodeGen *g) { |
| 6206 | 6207 | g->cur_err_ret_trace_val_stack = nullptr; |
| 6207 | 6208 | } |
| 6208 | 6209 | |
| 6209 | | // allocate temporary stack data |
| 6210 | | for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) { |
| 6211 | | IrInstructionAllocaGen *instruction = fn_table_entry->alloca_gen_list.at(alloca_i); |
| 6212 | | ZigType *ptr_type = instruction->base.value.type; |
| 6213 | | assert(ptr_type->id == ZigTypeIdPointer); |
| 6214 | | ZigType *child_type = ptr_type->data.pointer.child_type; |
| 6215 | | if (!type_has_bits(child_type)) |
| 6216 | | continue; |
| 6217 | | if (instruction->base.ref_count == 0) |
| 6218 | | continue; |
| 6219 | | if (instruction->base.value.special != ConstValSpecialRuntime) { |
| 6220 | | if (const_ptr_pointee(nullptr, g, &instruction->base.value, nullptr)->special != |
| 6221 | | ConstValSpecialRuntime) |
| 6222 | | { |
| 6210 | if (!is_async) { |
| 6211 | // allocate temporary stack data |
| 6212 | for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) { |
| 6213 | IrInstructionAllocaGen *instruction = fn_table_entry->alloca_gen_list.at(alloca_i); |
| 6214 | ZigType *ptr_type = instruction->base.value.type; |
| 6215 | assert(ptr_type->id == ZigTypeIdPointer); |
| 6216 | ZigType *child_type = ptr_type->data.pointer.child_type; |
| 6217 | if (!type_has_bits(child_type)) |
| 6223 | 6218 | continue; |
| 6219 | if (instruction->base.ref_count == 0) |
| 6220 | continue; |
| 6221 | if (instruction->base.value.special != ConstValSpecialRuntime) { |
| 6222 | if (const_ptr_pointee(nullptr, g, &instruction->base.value, nullptr)->special != |
| 6223 | ConstValSpecialRuntime) |
| 6224 | { |
| 6225 | continue; |
| 6226 | } |
| 6224 | 6227 | } |
| 6228 | instruction->base.llvm_value = build_alloca(g, child_type, instruction->name_hint, |
| 6229 | get_ptr_align(g, ptr_type)); |
| 6225 | 6230 | } |
| 6226 | | instruction->base.llvm_value = build_alloca(g, child_type, instruction->name_hint, |
| 6227 | | get_ptr_align(g, ptr_type)); |
| 6228 | 6231 | } |
| 6229 | 6232 | |
| 6230 | 6233 | ZigType *import = get_scope_import(&fn_table_entry->fndef_scope->base); |
| ... | ... | @@ -6263,9 +6266,9 @@ static void do_code_gen(CodeGen *g) { |
| 6263 | 6266 | fn_walk_var.data.vars.var = var; |
| 6264 | 6267 | iter_function_params_c_abi(g, fn_table_entry->type_entry, &fn_walk_var, var->src_arg_index); |
| 6265 | 6268 | } else if (is_async) { |
| 6266 | | size_t ret_1_or_0 = type_has_bits(fn_type_id->return_type) ? 1 : 0; |
| 6267 | | var->value_ref = LLVMBuildStructGEP(g->builder, g->cur_ret_ptr, |
| 6268 | | coro_arg_start + ret_1_or_0 + var_i, ""); |
| 6269 | var->value_ref = LLVMBuildStructGEP(g->builder, g->cur_ret_ptr, async_var_index, |
| 6270 | buf_ptr(&var->name)); |
| 6271 | async_var_index += 1; |
| 6269 | 6272 | if (var->decl_node) { |
| 6270 | 6273 | var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, get_di_scope(g, var->parent_scope), |
| 6271 | 6274 | buf_ptr(&var->name), import->data.structure.root_struct->di_file, |
| ... | ... | @@ -6299,6 +6302,29 @@ static void do_code_gen(CodeGen *g) { |
| 6299 | 6302 | } |
| 6300 | 6303 | } |
| 6301 | 6304 | |
| 6305 | if (is_async) { |
| 6306 | for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) { |
| 6307 | IrInstructionAllocaGen *instruction = fn_table_entry->alloca_gen_list.at(alloca_i); |
| 6308 | ZigType *ptr_type = instruction->base.value.type; |
| 6309 | assert(ptr_type->id == ZigTypeIdPointer); |
| 6310 | ZigType *child_type = ptr_type->data.pointer.child_type; |
| 6311 | if (!type_has_bits(child_type)) |
| 6312 | continue; |
| 6313 | if (instruction->base.ref_count == 0) |
| 6314 | continue; |
| 6315 | if (instruction->base.value.special != ConstValSpecialRuntime) { |
| 6316 | if (const_ptr_pointee(nullptr, g, &instruction->base.value, nullptr)->special != |
| 6317 | ConstValSpecialRuntime) |
| 6318 | { |
| 6319 | continue; |
| 6320 | } |
| 6321 | } |
| 6322 | instruction->base.llvm_value = LLVMBuildStructGEP(g->builder, g->cur_ret_ptr, async_var_index, |
| 6323 | instruction->name_hint); |
| 6324 | async_var_index += 1; |
| 6325 | } |
| 6326 | } |
| 6327 | |
| 6302 | 6328 | // finishing error return trace setup. we have to do this after all the allocas. |
| 6303 | 6329 | if (have_err_ret_trace_stack) { |
| 6304 | 6330 | ZigType *usize = g->builtin_types.entry_usize; |