AstGen: fix dbg_block_end being inserted before last instruction in block

Closes #14125
This commit is contained in:
Veikka Tuominen 2022-12-30 15:50:44 +02:00
parent 4e64373fc0
commit 67316e2eab

View File

@ -6942,7 +6942,13 @@ fn switchExpr(
// it as the break operand.
if (body_len < 2)
break :blk;
const store_inst = payloads.items[end_index - 2];
var store_index = end_index - 2;
while (true) : (store_index -= 1) switch (zir_tags[payloads.items[store_index]]) {
.dbg_block_end, .dbg_block_begin, .dbg_stmt, .dbg_var_val, .dbg_var_ptr => {},
else => break,
};
const store_inst = payloads.items[store_index];
if (zir_tags[store_inst] != .store_to_block_ptr or
zir_datas[store_inst].bin.lhs != block_scope.rl_ptr)
break :blk;
@ -12150,7 +12156,7 @@ const GenZir = struct {
const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined });
try gz.instructions.insert(gpa, gz.instructions.items.len - 1, new_index);
try gz.instructions.append(gpa, new_index);
}
};