diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-03-18 22:21:51 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-03-19 11:20:38 +0200 |
| commit | f19731948e934e8e9877729cab871ed05463d3c4 (patch) | |
| tree | 0cf4837a5edc2a4341bdfc771d077abf856a4fb2 /src/Sema.zig | |
| parent | 739734170e788f20a5c1d1f9f74cc7abf6efebf6 (diff) | |
| download | zig-f19731948e934e8e9877729cab871ed05463d3c4.tar.gz zig-f19731948e934e8e9877729cab871ed05463d3c4.zip | |
Sema: balance dbg_block_begins in case of early return
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index c7e98e35b6..13c3db372c 100644 --- a/src/Sema.zig +++ b/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; |
