modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/bug483.go (about)

     1  // run
     2  
     3  // Copyright 2014 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  // Test for a garbage collection bug involving not
     8  // marking x as having its address taken by &x[0]
     9  // when x is an array value.
    10  
    11  package main
    12  
    13  import (
    14  	"bytes"
    15  	"fmt"
    16  	"runtime"
    17  )
    18  
    19  func main() {
    20  	var x = [4]struct{ x, y interface{} }{
    21  		{"a", "b"},
    22  		{"c", "d"},
    23  		{"e", "f"},
    24  		{"g", "h"},
    25  	}
    26  
    27  	var buf bytes.Buffer
    28  	for _, z := range x {
    29  		runtime.GC()
    30  		fmt.Fprintf(&buf, "%s %s ", z.x.(string), z.y.(string))
    31  	}
    32  
    33  	if buf.String() != "a b c d e f g h " {
    34  		println("BUG wrong output\n", buf.String())
    35  	}
    36  }