diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2023-08-13 09:54:58 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-08-14 11:43:21 -0700 |
| commit | 8f3ccbbe367bea66d7f0f364a957870eb2cc95a0 (patch) | |
| tree | 33dad0b953904d39e75490b05f414bdbc09869bb /src | |
| parent | 1054e67f01e0f2eff1adf4982189ebba0a3696ab (diff) | |
| download | zig-8f3ccbbe367bea66d7f0f364a957870eb2cc95a0.tar.gz zig-8f3ccbbe367bea66d7f0f364a957870eb2cc95a0.zip | |
Sema: provide source location when analyzing panic handler
The panic handler decl_val was previously given a `unneeded` source
location, which was then added to the reference trace, resulting in a
crash if the source location was used in the reference trace. This
commit makes two trivial changes:
* Don't add unneeded source locations to the ref table (panic in debug, silently ignore in release)
* Pass a real source location when analyzing the panic handler
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 0ed89a0fdb..e7d1df0ebb 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -25202,7 +25202,7 @@ fn panicWithMsg(sema: *Sema, block: *Block, src: LazySrcLoc, msg_inst: Air.Inst. try sema.prepareSimplePanic(block); const panic_func = mod.funcInfo(mod.panic_func_index); - const panic_fn = try sema.analyzeDeclVal(block, .unneeded, panic_func.owner_decl); + const panic_fn = try sema.analyzeDeclVal(block, src, panic_func.owner_decl); const null_stack_trace = Air.internedToRef(mod.null_stack_trace); const opt_usize_ty = try mod.optionalType(.usize_type); @@ -30702,7 +30702,15 @@ fn addReferencedBy( src: LazySrcLoc, decl_index: Decl.Index, ) !void { - if (sema.mod.comp.reference_trace == @as(u32, 0)) return; + if (sema.mod.comp.reference_trace == 0) return; + if (src == .unneeded) { + // We can't use NeededSourceLocation, since sites handling that assume it means a compile + // error. Our long-term strategy here is to gradually transition from NeededSourceLocation + // into having more LazySrcLoc tags. In the meantime, let release compilers just ignore this + // reference (a slightly-incomplete error is better than a crash!), but trigger a panic in + // debug so we can fix this case. + if (std.debug.runtime_safety) unreachable else return; + } try sema.mod.reference_table.put(sema.gpa, decl_index, .{ .referencer = block.src_decl, .src = src, |
