Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: bug in global variable initialization #29013

randall77 opened this issue Nov 30, 2018 · 2 comments


None yet
4 participants
Copy link

commented Nov 30, 2018

package main

import "fmt"

type TestSuite struct {
	Tests []Test
type Test struct {
	Want interface{}
type Int struct {
	i int

func NewInt(v int) Int {
	return Int{i: v}

var Suites = []TestSuite{
var Dicts = TestSuite{
	Tests: []Test{
			Want: map[Int]bool{NewInt(1): true},
			Want: map[Int]string{
				NewInt(3): "3",

func main() {
	var mym = Dicts.Tests[0].Want.(map[Int]bool)
	fmt.Printf("%p %p %v\n", &Dicts.Tests[0], mym, mym)
	var mym2 = Suites[0].Tests[0].Want.(map[Int]bool)
	fmt.Printf("%p %p %v\n", &Suites[0].Tests[0], mym2, mym2)

When I run this on tip, I get:

0x54d580 0xc00007c150 map[{1}:true]
0x54d5a0 0xc00007c1b0 map[{3}:true]

That's clearly not right. Where did the map[3]=true come from?

On 1.11, I get:

0x548640 0xc000082150 map[{1}:true]
0x548660 0xc0000821b0 map[{1}:true]

Which is more correct. But not actually completely correct. I think we should have &Suites[0].Tests[0] == &Dicts.Tests[0], but we don't. This may or may not be related to the first bug.

This started happening after my reuse temporaries change: I'm not sure yet if that CL is actually buggy or just triggered something underlying.

@randall77 randall77 added this to the Go1.12 milestone Nov 30, 2018

@randall77 randall77 self-assigned this Nov 30, 2018


This comment has been minimized.

Copy link

commented Nov 30, 2018

seems is a compiler bug。


This comment has been minimized.

Copy link

commented Dec 1, 2018

Change mentions this issue: cmd/compile: fix static initializer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.