From 402c96f9a69d01771dd0d860e49e25e8cf96e761 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Fri, 27 Dec 2013 08:38:59 -0800 Subject: [PATCH] Fixing block split ordering, issue #48. --- src/alloy/hir/function_builder.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/alloy/hir/function_builder.cc b/src/alloy/hir/function_builder.cc index 936ba49df..801606b52 100644 --- a/src/alloy/hir/function_builder.cc +++ b/src/alloy/hir/function_builder.cc @@ -296,13 +296,23 @@ void FunctionBuilder::InsertLabel(Label* label, Instr* prev_instr) { label->block = new_block; label->prev = label->next = NULL; - new_block->instr_head = prev_instr->next; + Instr* prev_next = prev_instr->next; + Instr* old_prev_tail = prev_block->instr_tail; + if (prev_instr->next) { + Instr* prev_last = prev_instr->next->prev; + prev_last->next = NULL; + prev_block->instr_tail = prev_last; + } + new_block->instr_head = prev_next; if (new_block->instr_head) { new_block->instr_head->prev = NULL; - new_block->instr_tail = prev_block->instr_tail; + new_block->instr_tail = old_prev_tail; + } + + for (auto instr = new_block->instr_head; instr != new_block->instr_tail; + instr = instr->next) { + instr->block = new_block; } - prev_instr->next = NULL; - prev_block->instr_tail = prev_instr; if (current_block_ == prev_block) { current_block_ = new_block;