authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-18 22:21:51+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-19 11:20:38+02:00
logf19731948e934e8e9877729cab871ed05463d3c4
tree0cf4837a5edc2a4341bdfc771d077abf856a4fb2
parent739734170e788f20a5c1d1f9f74cc7abf6efebf6

Sema: balance dbg_block_begins in case of early return


1 files changed, 17 insertions(+), 0 deletions(-)

src/Sema.zig+17
......@@ -614,6 +614,8 @@ fn analyzeBodyInner(
614614 crash_info.push();
615615 defer crash_info.pop();
616616
617 var dbg_block_begins: u32 = 0;
618
617619 // We use a while(true) loop here to avoid a redundant way of breaking out of
618620 // the loop. The only way to break out of the loop is with a `noreturn`
619621 // instruction.
......@@ -884,11 +886,13 @@ fn analyzeBodyInner(
884886 .prefetch => try sema.zirPrefetch( block, extended),
885887 // zig fmt: on
886888 .dbg_block_begin => {
889 dbg_block_begins += 1;
887890 try sema.zirDbgBlockBegin(block);
888891 i += 1;
889892 continue;
890893 },
891894 .dbg_block_end => {
895 dbg_block_begins -= 1;
892896 try sema.zirDbgBlockEnd(block);
893897 i += 1;
894898 continue;
......@@ -1221,6 +1225,19 @@ fn analyzeBodyInner(
12211225 i += 1;
12221226 } else unreachable;
12231227
1228 // balance out dbg_block_begins in case of early noreturn
1229 const noreturn_inst = block.instructions.popOrNull();
1230 while (dbg_block_begins > 0) {
1231 dbg_block_begins -= 1;
1232 if (block.is_comptime or sema.mod.comp.bin_file.options.strip) continue;
1233
1234 _ = try block.addInst(.{
1235 .tag = .dbg_block_end,
1236 .data = undefined,
1237 });
1238 }
1239 if (noreturn_inst) |some| try block.instructions.append(sema.gpa, some);
1240
12241241 if (!wip_captures.finalized) {
12251242 try wip_captures.finalize();
12261243 block.wip_capture_scope = parent_capture_scope;