| ... | ... | @@ -9532,6 +9532,19 @@ static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstr |
| 9532 | 9532 | return new_bb; |
| 9533 | 9533 | } |
| 9534 | 9534 | |
| 9535 | static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) { |
| 9536 | assert(ref_old_instruction != nullptr); |
| 9537 | IrBasicBlock *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction); |
| 9538 | if (new_bb->must_be_comptime_source_instr) { |
| 9539 | ErrorMsg *msg = ir_add_error(ira, ref_old_instruction, |
| 9540 | buf_sprintf("control flow attempts to use compile-time variable at runtime")); |
| 9541 | add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_instr->source_node, |
| 9542 | buf_sprintf("compile-time variable assigned here")); |
| 9543 | return nullptr; |
| 9544 | } |
| 9545 | return new_bb; |
| 9546 | } |
| 9547 | |
| 9535 | 9548 | static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) { |
| 9536 | 9549 | ira->instruction_index = 0; |
| 9537 | 9550 | ira->old_irb.current_basic_block = old_bb; |
| ... | ... | @@ -13891,15 +13904,9 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr |
| 13891 | 13904 | if (is_comptime || old_dest_block->ref_count == 1) |
| 13892 | 13905 | return ir_inline_bb(ira, &br_instruction->base, old_dest_block); |
| 13893 | 13906 | |
| 13894 | | IrBasicBlock *new_bb = ir_get_new_bb(ira, old_dest_block, &br_instruction->base); |
| 13895 | | |
| 13896 | | if (new_bb->must_be_comptime_source_instr) { |
| 13897 | | ErrorMsg *msg = ir_add_error(ira, &br_instruction->base, |
| 13898 | | buf_sprintf("control flow attempts to use compile-time variable at runtime")); |
| 13899 | | add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_instr->source_node, |
| 13900 | | buf_sprintf("compile-time variable assigned here")); |
| 13907 | IrBasicBlock *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base); |
| 13908 | if (new_bb == nullptr) |
| 13901 | 13909 | return ir_unreach_error(ira); |
| 13902 | | } |
| 13903 | 13910 | |
| 13904 | 13911 | ir_build_br_from(&ira->new_irb, &br_instruction->base, new_bb); |
| 13905 | 13912 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| ... | ... | @@ -13925,7 +13932,10 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct |
| 13925 | 13932 | if (is_comptime || old_dest_block->ref_count == 1) |
| 13926 | 13933 | return ir_inline_bb(ira, &cond_br_instruction->base, old_dest_block); |
| 13927 | 13934 | |
| 13928 | | IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block, &cond_br_instruction->base); |
| 13935 | IrBasicBlock *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base); |
| 13936 | if (new_dest_block == nullptr) |
| 13937 | return ir_unreach_error(ira); |
| 13938 | |
| 13929 | 13939 | ir_build_br_from(&ira->new_irb, &cond_br_instruction->base, new_dest_block); |
| 13930 | 13940 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 13931 | 13941 | } |
| ... | ... | @@ -13936,8 +13946,14 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct |
| 13936 | 13946 | return ir_unreach_error(ira); |
| 13937 | 13947 | |
| 13938 | 13948 | assert(cond_br_instruction->then_block != cond_br_instruction->else_block); |
| 13939 | | IrBasicBlock *new_then_block = ir_get_new_bb(ira, cond_br_instruction->then_block, &cond_br_instruction->base); |
| 13940 | | IrBasicBlock *new_else_block = ir_get_new_bb(ira, cond_br_instruction->else_block, &cond_br_instruction->base); |
| 13949 | IrBasicBlock *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base); |
| 13950 | if (new_then_block == nullptr) |
| 13951 | return ir_unreach_error(ira); |
| 13952 | |
| 13953 | IrBasicBlock *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base); |
| 13954 | if (new_else_block == nullptr) |
| 13955 | return ir_unreach_error(ira); |
| 13956 | |
| 13941 | 13957 | ir_build_cond_br_from(&ira->new_irb, &cond_br_instruction->base, |
| 13942 | 13958 | casted_condition, new_then_block, new_else_block, nullptr); |
| 13943 | 13959 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |