Commit bfbbda7751

mlugg <mlugg@mlugg.co.uk>
2025-09-10 13:53:03
compiler: fix new panic handler in release builds
1 parent c1a30bd
Changed files (2)
lib/std/debug.zig
@@ -355,7 +355,7 @@ pub fn relocateContext(dest: *ThreadContext) void {
 /// The value which is placed on the stack to make a copy of a `ThreadContext`.
 const ThreadContextBuf = if (ThreadContext == noreturn) void else ThreadContext;
 /// The pointer through which a `ThreadContext` is received from callers of stack tracing logic.
-const ThreadContextPtr = if (ThreadContext == noreturn) noreturn else *const ThreadContext;
+pub const ThreadContextPtr = if (ThreadContext == noreturn) noreturn else *const ThreadContext;
 
 /// Capture the current context. The register values in the context will reflect the
 /// state after the platform `getcontext` function returns.
@@ -1297,7 +1297,7 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa
     if (ThreadContext == noreturn) return handleSegfault(addr, name, null);
 
     // Some kernels don't align `ctx_ptr` properly, so we'll copy it into a local buffer.
-    var copied_ctx: ThreadContextBuf = undefined;
+    var copied_ctx: posix.ucontext_t = undefined;
     const orig_ctx: *align(1) posix.ucontext_t = @ptrCast(ctx_ptr);
     copied_ctx = orig_ctx.*;
     if (builtin.os.tag.isDarwin() and builtin.cpu.arch == .aarch64) {
src/crash_report.zig
@@ -17,7 +17,7 @@ pub const debug = struct {
 /// crash earlier than that.
 pub var zig_argv0: []const u8 = "zig";
 
-fn handleSegfaultImpl(addr: ?usize, name: []const u8, opt_ctx: ?*std.debug.ThreadContext) noreturn {
+fn handleSegfaultImpl(addr: ?usize, name: []const u8, opt_ctx: ?std.debug.ThreadContextPtr) noreturn {
     @branchHint(.cold);
     dumpCrashContext() catch {};
     std.debug.defaultHandleSegfault(addr, name, opt_ctx);
@@ -56,6 +56,7 @@ pub const AnalyzeBody = if (build_options.enable_debug_extensions) struct {
         current = ab.parent;
     }
 } else struct {
+    const current: ?noreturn = null;
     // Dummy implementation, with functions marked `inline` to avoid interfering with tail calls.
     pub inline fn push(_: AnalyzeBody, _: *Sema, _: *Sema.Block, _: []const Zir.Inst.Index) void {}
     pub inline fn pop(_: AnalyzeBody) void {}
@@ -75,6 +76,7 @@ pub const CodegenFunc = if (build_options.enable_debug_extensions) struct {
         current = null;
     }
 } else struct {
+    const current: ?noreturn = null;
     // Dummy implementation
     pub fn start(_: *const Zcu, _: InternPool.Index) void {}
     pub fn stop(_: InternPool.Index) void {}