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: condition in for loop body is incorrectly optimised away #53600
Comments
Change https://go.dev/cl/415219 mentions this issue: |
@gopherbot please open backport issues for 1.17 and 1.18. This is a rare bug but results in miscompilation of loops with termination conditions "<= C" for large C. |
Backport issue(s) opened: #53617 (for 1.17), #53618 (for 1.18). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Change https://go.dev/cl/415874 mentions this issue: |
Induction variable detection is still not quite right. I've added another failing test. Redo the overflow/underflow detector so it is more obviously correct. Update #53600 Fixes #53653 Fixes #53663 Change-Id: Id95228e282fdbf6bd80b26e1c41d62e935ba08ff Reviewed-on: https://go-review.googlesource.com/c/go/+/415874 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: David Chase <drchase@google.com>
When the terminating condition is <= X, we need to make sure that X+step doesn't overflow. Fixes golang#53600 Change-Id: I36e5384d05b4d7168e48db6094200fcae409bfe5 Reviewed-on: https://go-review.googlesource.com/c/go/+/415219 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Keith Randall <khr@golang.org>
Induction variable detection is still not quite right. I've added another failing test. Redo the overflow/underflow detector so it is more obviously correct. Update golang#53600 Fixes golang#53653 Fixes golang#53663 Change-Id: Id95228e282fdbf6bd80b26e1c41d62e935ba08ff Reviewed-on: https://go-review.googlesource.com/c/go/+/415874 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: David Chase <drchase@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
The program at https://go.dev/play/p/QnP9ojw3vCV does not terminate. A similar program https://go.dev/play/p/86YpX7rbHHT with the for condition clause removed does correct terminate.
If optimisation is turned off, the the first program behaves as expected.
What did you expect to see?
The output from both programs to be
What did you see instead?
The first program prints the following and does not terminate.
The assembly generated from the first program appears to have the condition body omptimised away (https://godbolt.org/z/9jW1GaKfv) unless the for condition clause is removed (https://godbolt.org/z/c3Pvnb3ad) or optimisations are turned off (https://godbolt.org/z/o7o6x3bzd). This appears to be independent of GOARCH (at least within {amd64, arm64}.
See also discussion at https://groups.google.com/g/golang-nuts/c/3_-g6hBfo9s.
The text was updated successfully, but these errors were encountered: