Source file test/fixedbugs/bug500.go

     1  // run
     2  
     3  // Copyright 2016 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  // Gccgo generated incorrect GC info when a global variable was
     8  // initialized to a slice of a value containing pointers.  The initial
     9  // backing array for the slice was allocated in the .data section,
    10  // which is fine, but the backing array was not registered as a GC
    11  // root.
    12  
    13  package main
    14  
    15  import (
    16  	"runtime"
    17  )
    18  
    19  type s struct {
    20  	str string
    21  }
    22  
    23  var a = []struct {
    24  	str string
    25  }{
    26  	{""},
    27  }
    28  
    29  var b = "b"
    30  var c = "c"
    31  
    32  func init() {
    33  	a[0].str = b + c
    34  }
    35  
    36  func main() {
    37  	runtime.GC()
    38  	if a[0].str != b + c {
    39  		panic(a[0].str)
    40  	}
    41  }
    42  

View as plain text