| ... | @@ -19787,6 +19787,39 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, | ... | @@ -19787,6 +19787,39 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 19787 | return ira->codegen->invalid_instruction; | 19787 | return ira->codegen->invalid_instruction; |
| 19788 | } | 19788 | } |
| 19789 | } | 19789 | } |
| | 19790 | } else if (switch_type->id == ZigTypeIdBool) { |
| | 19791 | int seenTrue = 0; |
| | 19792 | int seenFalse = 0; |
| | 19793 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| | 19794 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| | 19795 | |
| | 19796 | IrInstruction *value = range->start->child; |
| | 19797 | |
| | 19798 | IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type); |
| | 19799 | if (type_is_invalid(casted_value->value.type)) |
| | 19800 | return ira->codegen->invalid_instruction; |
| | 19801 | |
| | 19802 | ConstExprValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad); |
| | 19803 | if (!const_expr_val) |
| | 19804 | return ira->codegen->invalid_instruction; |
| | 19805 | |
| | 19806 | assert(const_expr_val->type->id == ZigTypeIdBool); |
| | 19807 | |
| | 19808 | if (const_expr_val->data.x_bool == true) { |
| | 19809 | seenTrue += 1; |
| | 19810 | } else { |
| | 19811 | seenFalse += 1; |
| | 19812 | } |
| | 19813 | |
| | 19814 | if ((seenTrue > 1) || (seenFalse > 1)) { |
| | 19815 | ir_add_error(ira, value, buf_sprintf("duplicate switch value")); |
| | 19816 | return ira->codegen->invalid_instruction; |
| | 19817 | } |
| | 19818 | } |
| | 19819 | if (((seenTrue < 1) || (seenFalse < 1)) && !instruction->have_else_prong) { |
| | 19820 | ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities")); |
| | 19821 | return ira->codegen->invalid_instruction; |
| | 19822 | } |
| 19790 | } else if (!instruction->have_else_prong) { | 19823 | } else if (!instruction->have_else_prong) { |
| 19791 | ir_add_error(ira, &instruction->base, | 19824 | ir_add_error(ira, &instruction->base, |
| 19792 | buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name))); | 19825 | buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name))); |