Skip to content

Commit 469e243

Browse files
jakebaileydeadprogram
authored andcommitted
compiler: document defer frame field dependency
1 parent 278aa09 commit 469e243

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

compiler/defer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ func (b *builder) deferInitFunc() {
6969
// in the setjmp-like inline assembly.
7070
deferFrameType := b.getLLVMRuntimeType("deferFrame")
7171
b.deferFrame = b.CreateAlloca(deferFrameType, "deferframe.buf")
72+
// The field index must match the DeferPtr field in runtime.deferFrame,
73+
// defined in src/runtime/panic.go.
7274
b.deferPtr = b.CreateInBoundsGEP(deferFrameType, b.deferFrame, []llvm.Value{
7375
llvm.ConstInt(b.ctx.Int32Type(), 0, false),
7476
llvm.ConstInt(b.ctx.Int32Type(), 6, false), // DeferPtr field

src/runtime/panic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func panicStrategy() uint8
3131
// DeferFrame is a stack allocated object that stores information for the
3232
// current "defer frame", which is used in functions that use the `defer`
3333
// keyword.
34-
// The compiler knows about the JumpPC struct offset, so it should not be moved
35-
// without also updating compiler/defer.go.
34+
// The compiler knows about the JumpPC struct offset and the DeferPtr field
35+
// index, so they should not be moved without also updating compiler/defer.go.
3636
type deferFrame struct {
3737
JumpSP unsafe.Pointer // stack pointer to return to
3838
JumpPC unsafe.Pointer // pc to return to

0 commit comments

Comments
 (0)