mirror of
https://github.com/golang/go
synced 2024-11-12 08:50:22 -07:00
1a3ee6794c
Not recording the address being taken was causing the liveness analysis not to preserve x in the absence of direct references to x, which in turn was making the net test fail with GOGC=0. In addition to the test, this fixes a bug wherein GOGC=0 go test -short net crashed if liveness analysis was in use (like at tip, not like Go 1.2). TBR=ken2 CC=golang-codereviews https://golang.org/cl/64470043
37 lines
681 B
Go
37 lines
681 B
Go
// run
|
|
|
|
// Copyright 2014 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Test for a garbage collection bug involving not
|
|
// marking x as having its address taken by &x[0]
|
|
// when x is an array value.
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"runtime"
|
|
)
|
|
|
|
func main() {
|
|
var x = [4]struct{ x, y interface{} }{
|
|
{"a", "b"},
|
|
{"c", "d"},
|
|
{"e", "f"},
|
|
{"g", "h"},
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
for _, z := range x {
|
|
runtime.GC()
|
|
fmt.Fprintf(&buf, "%s %s ", z.x.(string), z.y.(string))
|
|
}
|
|
|
|
if buf.String() != "a b c d e f g h " {
|
|
println("BUG wrong output\n", buf.String())
|
|
}
|
|
}
|