diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-12-21 23:48:02 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-12-21 23:48:02 -0500 |
| commit | d544672ed4cb8d8054665c9491d019dabac454e7 (patch) | |
| tree | 1ff618ce371249e963b46b83d7f8dd13ca7d9e16 /src/ir.cpp | |
| parent | b55efe5fabc5e743406d62bf5b1c2ebfcc8fc5b0 (diff) | |
| download | zig-d544672ed4cb8d8054665c9491d019dabac454e7.tar.gz zig-d544672ed4cb8d8054665c9491d019dabac454e7.zip | |
IR: fix compile time evaluation of else prong in switch
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 97d70e3e6a..79f561b7c7 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -8090,6 +8090,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, if (!target_val) return ir_unreach_error(ira); + IrBasicBlock *old_dest_block = switch_br_instruction->else_block; for (size_t i = 0; i < case_count; i += 1) { IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i]; IrInstruction *case_value = old_case->value->other; @@ -8111,17 +8112,18 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, return ir_unreach_error(ira); if (const_values_equal(target_val, case_val, target_value->type_entry)) { - IrBasicBlock *old_dest_block = old_case->block; - if (is_comptime || old_dest_block->ref_count == 1) { - return ir_inline_bb(ira, &switch_br_instruction->base, old_dest_block); - } else { - IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block); - ir_build_br_from(&ira->new_irb, &switch_br_instruction->base, new_dest_block); - return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); - } + old_dest_block = old_case->block; + break; } } + if (is_comptime || old_dest_block->ref_count == 1) { + return ir_inline_bb(ira, &switch_br_instruction->base, old_dest_block); + } else { + IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block); + ir_build_br_from(&ira->new_irb, &switch_br_instruction->base, new_dest_block); + return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); + } } IrInstructionSwitchBrCase *cases = allocate<IrInstructionSwitchBrCase>(case_count); |
