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: "x[i] op= y" evaluates x[i] more than once #21687

Closed
mdempsky opened this issue Aug 29, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@mdempsky
Copy link
Member

commented Aug 29, 2017

The Go spec says "An assignment operation x op= y where op is a binary arithmetic operator is equivalent to x = x op (y) but evaluates x only once."

I think for both of these sample programs the only valid outputs are "2 2" and "12 2":

An output of "11 2" indicates that m[0] was evaluated twice: once indexing into the old slice/map to read the value 1, and then once into the new to store the value 11.

Notably, gccgo outputs "12 2" for slices, but cmd/compile outputs "11 2" for slices, and both output "11 2" for maps.

/cc @griesemer @ianlancetaylor

@mdempsky

This comment has been minimized.

Copy link
Member Author

commented Aug 29, 2017

Slightly simpler repro cases: the only valid outputs (IMO) are "-1 2" and "1 -2":

An output of "1 -1" indicates the same failure as above.

@gopherbot

This comment has been minimized.

Copy link

commented Aug 29, 2017

Change https://golang.org/cl/60091 mentions this issue: cmd/compile: fix evaluation order for OASOP

@gopherbot gopherbot closed this in 34db5f0 Sep 5, 2017

@golang golang locked and limited conversation to collaborators Sep 5, 2018

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