Add asserts in gen_add_insn_before and gen_add_insn_after. Process a case when before is a label.
@@ -500,15 +500,23 @@ static void gen_delete_insn (MIR_context_t ctx, MIR_insn_t insn) {
}
static void gen_add_insn_before (MIR_context_t ctx, MIR_insn_t before, MIR_insn_t insn) {
+ MIR_insn_t insn_for_bb = before;
struct gen_ctx *gen_ctx = *gen_ctx_loc (ctx);
+ gen_assert (!MIR_branch_code_p (insn->code) && insn->code != MIR_LABEL);
+ if (before->code == MIR_LABEL) {
+ insn_for_bb = DLIST_PREV (MIR_insn_t, before);
+ gen_assert (insn_for_bb == NULL || !MIR_branch_code_p (insn_for_bb->code));
+ }
MIR_insert_insn_before (ctx, curr_func_item, before, insn);
- create_new_bb_insns (ctx, DLIST_PREV (MIR_insn_t, insn), before, before);
+ create_new_bb_insns (ctx, DLIST_PREV (MIR_insn_t, insn), before, insn_for_bb);
}
static void gen_add_insn_after (MIR_context_t ctx, MIR_insn_t after, MIR_insn_t insn) {
struct gen_ctx *gen_ctx = *gen_ctx_loc (ctx);
+ gen_assert (insn->code != MIR_LABEL);
+ gen_assert (!MIR_branch_code_p (after->code));
MIR_insert_insn_after (ctx, curr_func_item, after, insn);
create_new_bb_insns (ctx, after, DLIST_NEXT (MIR_insn_t, insn), after);
}
