| ... | ... | @@ -7492,6 +7492,19 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 7492 | 7492 | } |
| 7493 | 7493 | } |
| 7494 | 7494 | |
| 7495 | // implicit enum to &const union which has the enum as the tag type |
| 7496 | if (actual_type->id == TypeTableEntryIdEnum && expected_type->id == TypeTableEntryIdPointer) { |
| 7497 | TypeTableEntry *union_type = expected_type->data.pointer.child_type; |
| 7498 | if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || |
| 7499 | union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr) |
| 7500 | { |
| 7501 | type_ensure_zero_bits_known(ira->codegen, union_type); |
| 7502 | if (union_type->data.unionation.tag_type == actual_type) { |
| 7503 | return ImplicitCastMatchResultYes; |
| 7504 | } |
| 7505 | } |
| 7506 | } |
| 7507 | |
| 7495 | 7508 | // implicit undefined literal to anything |
| 7496 | 7509 | if (actual_type->id == TypeTableEntryIdUndefLit) { |
| 7497 | 7510 | return ImplicitCastMatchResultYes; |
| ... | ... | @@ -9079,6 +9092,27 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 9079 | 9092 | } |
| 9080 | 9093 | } |
| 9081 | 9094 | |
| 9095 | // explicit enum to &const union which has the enum as the tag type |
| 9096 | if (actual_type->id == TypeTableEntryIdEnum && wanted_type->id == TypeTableEntryIdPointer) { |
| 9097 | TypeTableEntry *union_type = wanted_type->data.pointer.child_type; |
| 9098 | if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || |
| 9099 | union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr) |
| 9100 | { |
| 9101 | type_ensure_zero_bits_known(ira->codegen, union_type); |
| 9102 | if (union_type->data.unionation.tag_type == actual_type) { |
| 9103 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, union_type, value); |
| 9104 | if (type_is_invalid(cast1->value.type)) |
| 9105 | return ira->codegen->invalid_instruction; |
| 9106 | |
| 9107 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 9108 | if (type_is_invalid(cast2->value.type)) |
| 9109 | return ira->codegen->invalid_instruction; |
| 9110 | |
| 9111 | return cast2; |
| 9112 | } |
| 9113 | } |
| 9114 | } |
| 9115 | |
| 9082 | 9116 | // explicit cast from undefined to anything |
| 9083 | 9117 | if (actual_type->id == TypeTableEntryIdUndefLit) { |
| 9084 | 9118 | return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type); |