| ... | ... | @@ -3135,12 +3135,19 @@ static TypeTableEntry *ir_determine_peer_types(IrAnalyze *ira, AstNode *source_n |
| 3135 | 3135 | if (prev_inst->type_entry->id == TypeTableEntryIdInvalid) { |
| 3136 | 3136 | return ira->codegen->builtin_types.entry_invalid; |
| 3137 | 3137 | } |
| 3138 | bool any_are_pure_error = (prev_inst->type_entry->id == TypeTableEntryIdPureError); |
| 3138 | 3139 | for (size_t i = 1; i < instruction_count; i += 1) { |
| 3139 | 3140 | IrInstruction *cur_inst = instructions[i]; |
| 3140 | 3141 | TypeTableEntry *cur_type = cur_inst->type_entry; |
| 3141 | 3142 | TypeTableEntry *prev_type = prev_inst->type_entry; |
| 3142 | 3143 | if (cur_type->id == TypeTableEntryIdInvalid) { |
| 3143 | 3144 | return cur_type; |
| 3145 | } else if (prev_type->id == TypeTableEntryIdPureError) { |
| 3146 | prev_inst = cur_inst; |
| 3147 | continue; |
| 3148 | } else if (cur_type->id == TypeTableEntryIdPureError) { |
| 3149 | any_are_pure_error = true; |
| 3150 | continue; |
| 3144 | 3151 | } else if (types_match_const_cast_only(prev_type, cur_type)) { |
| 3145 | 3152 | continue; |
| 3146 | 3153 | } else if (types_match_const_cast_only(cur_type, prev_type)) { |
| ... | ... | @@ -3198,7 +3205,11 @@ static TypeTableEntry *ir_determine_peer_types(IrAnalyze *ira, AstNode *source_n |
| 3198 | 3205 | return ira->codegen->builtin_types.entry_invalid; |
| 3199 | 3206 | } |
| 3200 | 3207 | } |
| 3201 | | return prev_inst->type_entry; |
| 3208 | if (any_are_pure_error && prev_inst->type_entry->id != TypeTableEntryIdPureError) { |
| 3209 | return get_error_type(ira->codegen, prev_inst->type_entry); |
| 3210 | } else { |
| 3211 | return prev_inst->type_entry; |
| 3212 | } |
| 3202 | 3213 | } |
| 3203 | 3214 | |
| 3204 | 3215 | enum ImplicitCastMatchResult { |
| ... | ... | @@ -3304,6 +3315,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 3304 | 3315 | return ir_determine_peer_types(ira, source_node, instructions, instruction_count); |
| 3305 | 3316 | } |
| 3306 | 3317 | |
| 3318 | static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *type_entry) { |
| 3319 | if (type_has_bits(type_entry) && handle_is_ptr(type_entry)) { |
| 3320 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 3321 | assert(fn_entry); |
| 3322 | fn_entry->alloca_list.append(instruction); |
| 3323 | } |
| 3324 | } |
| 3325 | |
| 3307 | 3326 | static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 3308 | 3327 | TypeTableEntry *wanted_type, CastOp cast_op, bool need_alloca) |
| 3309 | 3328 | { |
| ... | ... | @@ -4696,11 +4715,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 4696 | 4715 | impl_fn, nullptr, impl_param_count, casted_args); |
| 4697 | 4716 | |
| 4698 | 4717 | TypeTableEntry *return_type = impl_fn->type_entry->data.fn.fn_type_id.return_type; |
| 4699 | | if (type_has_bits(return_type) && handle_is_ptr(return_type)) { |
| 4700 | | FnTableEntry *callsite_fn = exec_fn_entry(ira->new_irb.exec); |
| 4701 | | assert(callsite_fn); |
| 4702 | | callsite_fn->alloca_list.append(new_call_instruction); |
| 4703 | | } |
| 4718 | ir_add_alloca(ira, new_call_instruction, return_type); |
| 4704 | 4719 | |
| 4705 | 4720 | return ir_finish_anal(ira, return_type); |
| 4706 | 4721 | } |
| ... | ... | @@ -4752,12 +4767,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 4752 | 4767 | IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base, |
| 4753 | 4768 | fn_entry, fn_ref, call_param_count, casted_args); |
| 4754 | 4769 | |
| 4755 | | if (type_has_bits(return_type) && handle_is_ptr(return_type)) { |
| 4756 | | FnTableEntry *callsite_fn = exec_fn_entry(ira->new_irb.exec); |
| 4757 | | assert(callsite_fn); |
| 4758 | | callsite_fn->alloca_list.append(new_call_instruction); |
| 4759 | | } |
| 4760 | | |
| 4770 | ir_add_alloca(ira, new_call_instruction, return_type); |
| 4761 | 4771 | return ir_finish_anal(ira, return_type); |
| 4762 | 4772 | } |
| 4763 | 4773 | |
| ... | ... | @@ -5280,6 +5290,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 5280 | 5290 | |
| 5281 | 5291 | ir_build_phi_from(&ira->new_irb, &phi_instruction->base, new_incoming_blocks.length, |
| 5282 | 5292 | new_incoming_blocks.items, new_incoming_values.items); |
| 5293 | |
| 5283 | 5294 | return resolved_type; |
| 5284 | 5295 | } |
| 5285 | 5296 | |
| ... | ... | @@ -6684,7 +6695,8 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru |
| 6684 | 6695 | |
| 6685 | 6696 | IrInstruction *new_instruction = ir_build_struct_init_from(&ira->new_irb, instruction, |
| 6686 | 6697 | container_type, actual_field_count, new_fields); |
| 6687 | | fn_entry->alloca_list.append(new_instruction); |
| 6698 | |
| 6699 | ir_add_alloca(ira, new_instruction, container_type); |
| 6688 | 6700 | return container_type; |
| 6689 | 6701 | } |
| 6690 | 6702 | |
| ... | ... | @@ -6754,7 +6766,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 6754 | 6766 | |
| 6755 | 6767 | IrInstruction *new_instruction = ir_build_container_init_list_from(&ira->new_irb, &instruction->base, |
| 6756 | 6768 | container_type_value, elem_count, new_items); |
| 6757 | | fn_entry->alloca_list.append(new_instruction); |
| 6769 | ir_add_alloca(ira, new_instruction, fixed_size_array_type); |
| 6758 | 6770 | return fixed_size_array_type; |
| 6759 | 6771 | } else if (container_type->id == TypeTableEntryIdArray) { |
| 6760 | 6772 | // same as slice init but we make a compile error if the length is wrong |