1// run 2 3// Copyright 2021 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 7package main 8 9import "fmt" 10 11type T [8]*int 12 13//go:noinline 14func f(x int) T { 15 return T{} 16} 17 18//go:noinline 19func g(x int, t T) { 20 if t != (T{}) { 21 panic(fmt.Sprintf("bad: %v", t)) 22 } 23} 24 25func main() { 26 const N = 10000 27 var q T 28 func() { 29 for i := 0; i < N; i++ { 30 q = f(0) 31 g(0, q) 32 sink = make([]byte, 1024) 33 } 34 }() 35 // Note that the closure is a trick to get the write to q to be a 36 // write to a pointer that is known to be non-nil and requires 37 // a write barrier. 38} 39 40var sink []byte 41