| ... | ... | @@ -19229,24 +19229,53 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 19229 | 19229 | ZigType *enum_type = target_type->data.unionation.tag_type; |
| 19230 | 19230 | assert(enum_type != nullptr); |
| 19231 | 19231 | assert(enum_type->id == ZigTypeIdEnum); |
| 19232 | assert(instruction->prongs_len > 0); |
| 19232 | 19233 | |
| 19233 | | if (instruction->prongs_len != 1) { |
| 19234 | | return target_value_ptr; |
| 19235 | | } |
| 19236 | | |
| 19237 | | IrInstruction *prong_value = instruction->prongs_ptr[0]->child; |
| 19238 | | if (type_is_invalid(prong_value->value.type)) |
| 19234 | IrInstruction *first_prong_value = instruction->prongs_ptr[0]->child; |
| 19235 | if (type_is_invalid(first_prong_value->value.type)) |
| 19239 | 19236 | return ira->codegen->invalid_instruction; |
| 19240 | 19237 | |
| 19241 | | IrInstruction *casted_prong_value = ir_implicit_cast(ira, prong_value, enum_type); |
| 19242 | | if (type_is_invalid(casted_prong_value->value.type)) |
| 19238 | IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type); |
| 19239 | if (type_is_invalid(first_casted_prong_value->value.type)) |
| 19243 | 19240 | return ira->codegen->invalid_instruction; |
| 19244 | 19241 | |
| 19245 | | ConstExprValue *prong_val = ir_resolve_const(ira, casted_prong_value, UndefBad); |
| 19246 | | if (!prong_val) |
| 19242 | ConstExprValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad); |
| 19243 | if (first_prong_val == nullptr) |
| 19247 | 19244 | return ira->codegen->invalid_instruction; |
| 19248 | 19245 | |
| 19249 | | TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag); |
| 19246 | TypeUnionField *first_field = find_union_field_by_tag(target_type, &first_prong_val->data.x_enum_tag); |
| 19247 | |
| 19248 | ErrorMsg *invalid_payload_msg = nullptr; |
| 19249 | for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) { |
| 19250 | IrInstruction *this_prong_inst = instruction->prongs_ptr[prong_i]->child; |
| 19251 | if (type_is_invalid(this_prong_inst->value.type)) |
| 19252 | return ira->codegen->invalid_instruction; |
| 19253 | |
| 19254 | IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type); |
| 19255 | if (type_is_invalid(this_casted_prong_value->value.type)) |
| 19256 | return ira->codegen->invalid_instruction; |
| 19257 | |
| 19258 | ConstExprValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad); |
| 19259 | if (this_prong == nullptr) |
| 19260 | return ira->codegen->invalid_instruction; |
| 19261 | |
| 19262 | TypeUnionField *payload_field = find_union_field_by_tag(target_type, &this_prong->data.x_enum_tag); |
| 19263 | ZigType *payload_type = payload_field->type_entry; |
| 19264 | if (first_field->type_entry != payload_type) { |
| 19265 | if (invalid_payload_msg == nullptr) { |
| 19266 | invalid_payload_msg = ir_add_error(ira, &instruction->base, |
| 19267 | buf_sprintf("capture group with incompatible types")); |
| 19268 | add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->source_node, |
| 19269 | buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name))); |
| 19270 | } |
| 19271 | add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->source_node, |
| 19272 | buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name))); |
| 19273 | } |
| 19274 | } |
| 19275 | |
| 19276 | if (invalid_payload_msg != nullptr) { |
| 19277 | return ira->codegen->invalid_instruction; |
| 19278 | } |
| 19250 | 19279 | |
| 19251 | 19280 | if (instr_is_comptime(target_value_ptr)) { |
| 19252 | 19281 | ConstExprValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad); |
| ... | ... | @@ -19258,7 +19287,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 19258 | 19287 | return ira->codegen->invalid_instruction; |
| 19259 | 19288 | |
| 19260 | 19289 | IrInstruction *result = ir_const(ira, &instruction->base, |
| 19261 | | get_pointer_to_type(ira->codegen, field->type_entry, |
| 19290 | get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 19262 | 19291 | target_val_ptr->type->data.pointer.is_const)); |
| 19263 | 19292 | ConstExprValue *out_val = &result->value; |
| 19264 | 19293 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| ... | ... | @@ -19268,8 +19297,8 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 19268 | 19297 | } |
| 19269 | 19298 | |
| 19270 | 19299 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, |
| 19271 | | instruction->base.scope, instruction->base.source_node, target_value_ptr, field, false, false); |
| 19272 | | result->value.type = get_pointer_to_type(ira->codegen, field->type_entry, |
| 19300 | instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field, false, false); |
| 19301 | result->value.type = get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 19273 | 19302 | target_value_ptr->value.type->data.pointer.is_const); |
| 19274 | 19303 | return result; |
| 19275 | 19304 | } else if (target_type->id == ZigTypeIdErrorSet) { |
| ... | ... | @@ -22977,11 +23006,11 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi |
| 22977 | 23006 | IrInstruction *type_value = instruction->type_value->child; |
| 22978 | 23007 | if (type_is_invalid(type_value->value.type)) |
| 22979 | 23008 | return ira->codegen->invalid_instruction; |
| 22980 | | |
| 23009 | |
| 22981 | 23010 | ZigType *expr_type = ir_resolve_type(ira, type_value); |
| 22982 | 23011 | if (type_is_invalid(expr_type)) |
| 22983 | 23012 | return ira->codegen->invalid_instruction; |
| 22984 | | |
| 23013 | |
| 22985 | 23014 | // Only allow float types, and vectors of floats. |
| 22986 | 23015 | ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type; |
| 22987 | 23016 | if (float_type->id != ZigTypeIdFloat) { |
| ... | ... | @@ -25082,7 +25111,7 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct |
| 25082 | 25111 | IrInstruction *type = instruction->type->child; |
| 25083 | 25112 | if (type_is_invalid(type->value.type)) |
| 25084 | 25113 | return ira->codegen->invalid_instruction; |
| 25085 | | |
| 25114 | |
| 25086 | 25115 | ZigType *expr_type = ir_resolve_type(ira, type); |
| 25087 | 25116 | if (type_is_invalid(expr_type)) |
| 25088 | 25117 | return ira->codegen->invalid_instruction; |