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

Closed
randall77 opened this issue Nov 30, 2018 · 2 comments
Closed

cmd/compile: bug in global variable initialization #29013

randall77 opened this issue Nov 30, 2018 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@randall77
Copy link
Contributor

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{
	Dicts,
}
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: https://go-review.googlesource.com/c/go/+/140301 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
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 30, 2018
@jingyugao
Copy link

seems is a compiler bug。

@gopherbot
Copy link

Change https://golang.org/cl/152081 mentions this issue: cmd/compile: fix static initializer

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants