1// run 2 3// Copyright 2019 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// Issue 30476: KeepAlive didn't keep stack object alive. 8 9package main 10 11import "runtime" 12 13func main() { 14 x := new([10]int) 15 runtime.SetFinalizer(x, func(*[10]int) { panic("FAIL: finalizer runs") }) 16 p := &T{x, 0} 17 use(p) 18 runtime.GC() 19 runtime.GC() 20 runtime.GC() 21 runtime.KeepAlive(p) 22} 23 24type T struct { 25 x *[10]int 26 y int 27} 28 29//go:noinline 30func use(*T) {} 31