mirror of
https://github.com/ziglang/zig.git
synced 2025-12-31 02:23:22 +00:00
Sema: balance dbg_block_begins in case of early return
This commit is contained in:
parent
739734170e
commit
f19731948e
17
src/Sema.zig
17
src/Sema.zig
@ -614,6 +614,8 @@ fn analyzeBodyInner(
|
||||
crash_info.push();
|
||||
defer crash_info.pop();
|
||||
|
||||
var dbg_block_begins: u32 = 0;
|
||||
|
||||
// We use a while(true) loop here to avoid a redundant way of breaking out of
|
||||
// the loop. The only way to break out of the loop is with a `noreturn`
|
||||
// instruction.
|
||||
@ -884,11 +886,13 @@ fn analyzeBodyInner(
|
||||
.prefetch => try sema.zirPrefetch( block, extended),
|
||||
// zig fmt: on
|
||||
.dbg_block_begin => {
|
||||
dbg_block_begins += 1;
|
||||
try sema.zirDbgBlockBegin(block);
|
||||
i += 1;
|
||||
continue;
|
||||
},
|
||||
.dbg_block_end => {
|
||||
dbg_block_begins -= 1;
|
||||
try sema.zirDbgBlockEnd(block);
|
||||
i += 1;
|
||||
continue;
|
||||
@ -1221,6 +1225,19 @@ fn analyzeBodyInner(
|
||||
i += 1;
|
||||
} else unreachable;
|
||||
|
||||
// balance out dbg_block_begins in case of early noreturn
|
||||
const noreturn_inst = block.instructions.popOrNull();
|
||||
while (dbg_block_begins > 0) {
|
||||
dbg_block_begins -= 1;
|
||||
if (block.is_comptime or sema.mod.comp.bin_file.options.strip) continue;
|
||||
|
||||
_ = try block.addInst(.{
|
||||
.tag = .dbg_block_end,
|
||||
.data = undefined,
|
||||
});
|
||||
}
|
||||
if (noreturn_inst) |some| try block.instructions.append(sema.gpa, some);
|
||||
|
||||
if (!wip_captures.finalized) {
|
||||
try wip_captures.finalize();
|
||||
block.wip_capture_scope = parent_capture_scope;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user