From 8f3ccbbe367bea66d7f0f364a957870eb2cc95a0 Mon Sep 17 00:00:00 2001 From: mlugg Date: Sun, 13 Aug 2023 09:54:58 +0100 Subject: 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 --- test/cases/compile_errors/panic_has_source_location.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/cases/compile_errors/panic_has_source_location.zig (limited to 'test/cases/compile_errors/panic_has_source_location.zig') diff --git a/test/cases/compile_errors/panic_has_source_location.zig b/test/cases/compile_errors/panic_has_source_location.zig new file mode 100644 index 0000000000..6e9d16d76d --- /dev/null +++ b/test/cases/compile_errors/panic_has_source_location.zig @@ -0,0 +1,17 @@ +const std = @import("std"); + +export fn foo() void { + // This should appear in the reference trace + // (and definitely shouldn't crash due to an unneeded source location!) + @panic("oh no"); +} + +pub fn panic(_: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { + @compileError("panic"); +} + +// error +// backend=stage2 +// target=native +// +// :10:5: error: panic -- cgit v1.2.3