Source file test/deferstacktemp.go
1 // run 2 3 // Copyright 2026 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 // This tests an SSA-able stack temporary whose address must refer to its stack 8 // slot. Without the addrtaken mark, (*state).addr returns &runtime.zerobase and 9 // runtime.deferprocStack follows a corrupted _defer record. 10 // 11 // On 64-bit systems, runtime._defer is 48 bytes with 7 fields and fits the 12 // current SSA limits. Nine defers force the non-open-coded deferprocStack path. 13 14 package main 15 16 var n int 17 18 func sink() { n++ } 19 20 //go:noinline 21 func nineDefers() { 22 defer sink() 23 defer sink() 24 defer sink() 25 defer sink() 26 defer sink() 27 defer sink() 28 defer sink() 29 defer sink() 30 defer sink() 31 } 32 33 func main() { 34 nineDefers() 35 if n != 9 { 36 println("n =", n, "want 9") 37 panic("defer chain corrupted") 38 } 39 } 40