| ... | ... | @@ -2015,13 +2015,15 @@ static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode |
| 2015 | 2015 | } |
| 2016 | 2016 | |
| 2017 | 2017 | static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2018 | | IrInstruction *target_value, IrInstructionCheckSwitchProngsRange *ranges, size_t range_count) |
| 2018 | IrInstruction *target_value, IrInstructionCheckSwitchProngsRange *ranges, size_t range_count, |
| 2019 | bool have_else_prong) |
| 2019 | 2020 | { |
| 2020 | 2021 | IrInstructionCheckSwitchProngs *instruction = ir_build_instruction<IrInstructionCheckSwitchProngs>( |
| 2021 | 2022 | irb, scope, source_node); |
| 2022 | 2023 | instruction->target_value = target_value; |
| 2023 | 2024 | instruction->ranges = ranges; |
| 2024 | 2025 | instruction->range_count = range_count; |
| 2026 | instruction->have_else_prong = have_else_prong; |
| 2025 | 2027 | |
| 2026 | 2028 | ir_ref_instruction(target_value, irb->current_basic_block); |
| 2027 | 2029 | for (size_t i = 0; i < range_count; i += 1) { |
| ... | ... | @@ -5542,9 +5544,8 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 5542 | 5544 | } |
| 5543 | 5545 | } |
| 5544 | 5546 | |
| 5545 | | if (!else_prong) { |
| 5546 | | ir_build_check_switch_prongs(irb, scope, node, target_value, check_ranges.items, check_ranges.length); |
| 5547 | | } |
| 5547 | ir_build_check_switch_prongs(irb, scope, node, target_value, check_ranges.items, check_ranges.length, |
| 5548 | else_prong != nullptr); |
| 5548 | 5549 | |
| 5549 | 5550 | if (cases.length == 0) { |
| 5550 | 5551 | ir_build_br(irb, scope, node, else_block, is_comptime); |
| ... | ... | @@ -13019,11 +13020,13 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 13019 | 13020 | field_prev_uses[field_index] = start_value->source_node; |
| 13020 | 13021 | } |
| 13021 | 13022 | } |
| 13022 | | for (uint32_t i = 0; i < enum_type->data.enumeration.src_field_count; i += 1) { |
| 13023 | | if (field_prev_uses[i] == nullptr) { |
| 13024 | | ir_add_error(ira, &instruction->base, |
| 13025 | | buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&enum_type->name), |
| 13026 | | buf_ptr(enum_type->data.enumeration.fields[i].name))); |
| 13023 | if (!instruction->have_else_prong) { |
| 13024 | for (uint32_t i = 0; i < enum_type->data.enumeration.src_field_count; i += 1) { |
| 13025 | if (field_prev_uses[i] == nullptr) { |
| 13026 | ir_add_error(ira, &instruction->base, |
| 13027 | buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&enum_type->name), |
| 13028 | buf_ptr(enum_type->data.enumeration.fields[i].name))); |
| 13029 | } |
| 13027 | 13030 | } |
| 13028 | 13031 | } |
| 13029 | 13032 | } else if (switch_type->id == TypeTableEntryIdInt) { |
| ... | ... | @@ -13055,15 +13058,17 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 13055 | 13058 | return ira->codegen->builtin_types.entry_invalid; |
| 13056 | 13059 | } |
| 13057 | 13060 | } |
| 13058 | | BigNum min_val; |
| 13059 | | eval_min_max_value_int(ira->codegen, switch_type, &min_val, false); |
| 13060 | | BigNum max_val; |
| 13061 | | eval_min_max_value_int(ira->codegen, switch_type, &max_val, true); |
| 13062 | | if (!rangeset_spans(&rs, &min_val, &max_val)) { |
| 13063 | | ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities")); |
| 13064 | | return ira->codegen->builtin_types.entry_invalid; |
| 13061 | if (!instruction->have_else_prong) { |
| 13062 | BigNum min_val; |
| 13063 | eval_min_max_value_int(ira->codegen, switch_type, &min_val, false); |
| 13064 | BigNum max_val; |
| 13065 | eval_min_max_value_int(ira->codegen, switch_type, &max_val, true); |
| 13066 | if (!rangeset_spans(&rs, &min_val, &max_val)) { |
| 13067 | ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities")); |
| 13068 | return ira->codegen->builtin_types.entry_invalid; |
| 13069 | } |
| 13065 | 13070 | } |
| 13066 | | } else { |
| 13071 | } else if (!instruction->have_else_prong) { |
| 13067 | 13072 | ir_add_error(ira, &instruction->base, |
| 13068 | 13073 | buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name))); |
| 13069 | 13074 | return ira->codegen->builtin_types.entry_invalid; |