From 469e2434fd7b174026fbc932cfdf780e818e11e9 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 2 Jun 2026 14:13:36 -0700 Subject: [PATCH] compiler: document defer frame field dependency --- compiler/defer.go | 2 ++ src/runtime/panic.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/defer.go b/compiler/defer.go index 8863bfd87..b0bc3a967 100644 --- a/compiler/defer.go +++ b/compiler/defer.go @@ -69,6 +69,8 @@ func (b *builder) deferInitFunc() { // in the setjmp-like inline assembly. deferFrameType := b.getLLVMRuntimeType("deferFrame") b.deferFrame = b.CreateAlloca(deferFrameType, "deferframe.buf") + // The field index must match the DeferPtr field in runtime.deferFrame, + // defined in src/runtime/panic.go. b.deferPtr = b.CreateInBoundsGEP(deferFrameType, b.deferFrame, []llvm.Value{ llvm.ConstInt(b.ctx.Int32Type(), 0, false), llvm.ConstInt(b.ctx.Int32Type(), 6, false), // DeferPtr field diff --git a/src/runtime/panic.go b/src/runtime/panic.go index cdd323267..f28cb75a4 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -31,8 +31,8 @@ func panicStrategy() uint8 // DeferFrame is a stack allocated object that stores information for the // current "defer frame", which is used in functions that use the `defer` // keyword. -// The compiler knows about the JumpPC struct offset, so it should not be moved -// without also updating compiler/defer.go. +// The compiler knows about the JumpPC struct offset and the DeferPtr field +// index, so they should not be moved without also updating compiler/defer.go. type deferFrame struct { JumpSP unsafe.Pointer // stack pointer to return to JumpPC unsafe.Pointer // pc to return to