| ... | @@ -10015,21 +10015,25 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -10015,21 +10015,25 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_ |
| 10015 | | 10015 | |
| 10016 | if (value->id == IrInstructionIdLoadPtr) { | 10016 | if (value->id == IrInstructionIdLoadPtr) { |
| 10017 | IrInstructionLoadPtr *load_ptr_inst = (IrInstructionLoadPtr *)value; | 10017 | IrInstructionLoadPtr *load_ptr_inst = (IrInstructionLoadPtr *)value; |
| 10018 | return load_ptr_inst->ptr; | 10018 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, |
| 10019 | } else { | 10019 | load_ptr_inst->ptr->value.type, source_instr->source_node, false); |
| 10020 | IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instr->scope, | 10020 | if (const_cast_result.id == ConstCastResultIdInvalid) |
| 10021 | source_instr->source_node, value, true, false); | 10021 | return ira->codegen->invalid_instruction; |
| 10022 | new_instruction->value.type = wanted_type; | 10022 | if (const_cast_result.id == ConstCastResultIdOk) |
| | 10023 | return load_ptr_inst->ptr; |
| | 10024 | } |
| | 10025 | IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instr->scope, |
| | 10026 | source_instr->source_node, value, true, false); |
| | 10027 | new_instruction->value.type = wanted_type; |
| 10023 | | 10028 | |
| 10024 | ZigType *child_type = wanted_type->data.pointer.child_type; | 10029 | ZigType *child_type = wanted_type->data.pointer.child_type; |
| 10025 | if (type_has_bits(child_type)) { | 10030 | if (type_has_bits(child_type)) { |
| 10026 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); | 10031 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 10027 | assert(fn_entry); | 10032 | assert(fn_entry); |
| 10028 | fn_entry->alloca_list.append(new_instruction); | 10033 | fn_entry->alloca_list.append(new_instruction); |
| 10029 | } | | |
| 10030 | ir_add_alloca(ira, new_instruction, child_type); | | |
| 10031 | return new_instruction; | | |
| 10032 | } | 10034 | } |
| | 10035 | ir_add_alloca(ira, new_instruction, child_type); |
| | 10036 | return new_instruction; |
| 10033 | } | 10037 | } |
| 10034 | | 10038 | |
| 10035 | static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { | 10039 | static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { |
| ... | @@ -11057,7 +11061,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -11057,7 +11061,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 11057 | } | 11061 | } |
| 11058 | } | 11062 | } |
| 11059 | | 11063 | |
| 11060 | // enum to &const union which has the enum as the tag type | 11064 | // enum to *const union which has the enum as the tag type |
| 11061 | if (actual_type->id == ZigTypeIdEnum && wanted_type->id == ZigTypeIdPointer) { | 11065 | if (actual_type->id == ZigTypeIdEnum && wanted_type->id == ZigTypeIdPointer) { |
| 11062 | ZigType *union_type = wanted_type->data.pointer.child_type; | 11066 | ZigType *union_type = wanted_type->data.pointer.child_type; |
| 11063 | if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || | 11067 | if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || |