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(...@@ -614,6 +614,8 @@ fn analyzeBodyInner(
614 crash_info.push();614 crash_info.push();
615 defer crash_info.pop();615 defer crash_info.pop();
616616
617 var dbg_block_begins: u32 = 0;
618
617 // We use a while(true) loop here to avoid a redundant way of breaking out of619 // We use a while(true) loop here to avoid a redundant way of breaking out of
618 // the loop. The only way to break out of the loop is with a `noreturn`620 // the loop. The only way to break out of the loop is with a `noreturn`
619 // instruction.621 // instruction.
...@@ -884,11 +886,13 @@ fn analyzeBodyInner(...@@ -884,11 +886,13 @@ fn analyzeBodyInner(
884 .prefetch => try sema.zirPrefetch( block, extended),886 .prefetch => try sema.zirPrefetch( block, extended),
885 // zig fmt: on887 // zig fmt: on
886 .dbg_block_begin => {888 .dbg_block_begin => {
889 dbg_block_begins += 1;
887 try sema.zirDbgBlockBegin(block);890 try sema.zirDbgBlockBegin(block);
888 i += 1;891 i += 1;
889 continue;892 continue;
890 },893 },
891 .dbg_block_end => {894 .dbg_block_end => {
895 dbg_block_begins -= 1;
892 try sema.zirDbgBlockEnd(block);896 try sema.zirDbgBlockEnd(block);
893 i += 1;897 i += 1;
894 continue;898 continue;
...@@ -1221,6 +1225,19 @@ fn analyzeBodyInner(...@@ -1221,6 +1225,19 @@ fn analyzeBodyInner(
1221 i += 1;1225 i += 1;
1222 } else unreachable;1226 } 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
1224 if (!wip_captures.finalized) {1241 if (!wip_captures.finalized) {
1225 try wip_captures.finalize();1242 try wip_captures.finalize();
1226 block.wip_capture_scope = parent_capture_scope;1243 block.wip_capture_scope = parent_capture_scope;