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: optimisations change the behaviour of *struct{} #8938

ainar-g opened this issue Oct 15, 2014 · 2 comments

cmd/compile: optimisations change the behaviour of *struct{} #8938

ainar-g opened this issue Oct 15, 2014 · 2 comments


Copy link

@ainar-g ainar-g commented Oct 15, 2014

What does 'go version' print?
go version go1.3.3 linux/amd64

What steps reproduce the problem?
If possible, include a link to a program on

1. Get
2. Uncomment the Println before the if.
3. Run.

What happened?
When compiled as usual, this prints "Not Equals". But when compiled with
-gcflags '-N' it prints "Equals".

What should have happened instead?
It should have printed "Equals" in both cases, as it does when fmt.Println(a)
is commented, or if b is printed as well.

Please provide any additional information below.
The behaviour is the same on Go 1.2. The tip version (go version devel +fb3d6c1631c3 Wed
Oct 15 14:33:52 2014 -0400 linux/amd64) prints "Not Equals" both with
optimisations and without them.
Copy link

@griesemer griesemer commented Oct 15, 2014

Comment 1:

Per the spec:
"Pointers to distinct zero-size variables may or may not be equal."
Technically this is not an error.
Whether or not a given implementation should be consistent with respect to this is a
different question.
Leaving for rsc.

Labels changed: added release-none, repo-main.

Owner changed to @rsc.

Copy link

@rsc rsc commented Oct 15, 2014

Comment 2:

It's not an error, and it has been this way since at least Go 1.1 if not earlier. I
don't think it's worth changing, certainly not now. Don't use equality for pointers to
zero-size values and expect it to mean anything.
I guess we could make all non-nil pointers to zero-size values equal. We can see the
type at compile time.

Labels changed: added release-go1.5, removed release-none.

Status changed to Accepted.

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014
@rsc rsc removed accepted labels Apr 14, 2015
@rsc rsc modified the milestones: Unplanned, Go1.5 May 19, 2015
@rsc rsc changed the title cmd/gc: optimisations change the behaviour of *struct{} cmd/compile: optimisations change the behaviour of *struct{} Jun 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants