Debian Codegraph @

gcc/testsuite/go.test/test/fixedbugs/issue30476.go

raw
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
9 package main
10
11 import "runtime"
12
13 func 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
24 type T struct {
25 x *[10]int
26 y int
27 }
28
29 //go:noinline
30 func use(*T) {}