Debian Codegraph @

gcc/testsuite/go.test/test/fixedbugs/issue22781.go

raw
1 // run
2
3 // Copyright 2017 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 package main
8
9 import "runtime/debug"
10
11 type T struct {
12 // >= 16 bytes to avoid tiny alloc.
13 a, b int
14 }
15
16 func main() {
17 debug.SetGCPercent(1)
18 for i := 0; i < 100000; i++ {
19 m := make(map[*T]struct{}, 0)
20 for j := 0; j < 20; j++ {
21 // During the call to mapassign_fast64, the key argument
22 // was incorrectly treated as a uint64. If the stack was
23 // scanned during that call, the only pointer to k was
24 // missed, leading to *k being collected prematurely.
25 k := new(T)
26 m[k] = struct{}{}
27 }
28 }
29 }