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: incorrect loop variable detection #53653

Closed
randall77 opened this issue Jul 1, 2022 · 2 comments
Closed

cmd/compile: incorrect loop variable detection #53653

randall77 opened this issue Jul 1, 2022 · 2 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@randall77
Copy link
Contributor

randall77 commented Jul 1, 2022

func main() {
	for i := math.MinInt64 + 2; i >= math.MinInt64; i-- {
		if i == math.MaxInt64 {
			break
		}
		println(i)
	}
}

This program will loop forever when it shouldn't. You can "fix" it by passing -gcflags=-N.

Similar to #53600, this is a bug in induction variable detection. Just reversing the direction when step is negative in cmd/compile/internal/ssa/loopbce.go (added in CL 104041 ) isn't quite right. The "distance until overflow" isn't preserved under mirroring.

@dr2chase @rasky

@gopherbot
Copy link

gopherbot commented Jul 2, 2022

Change https://go.dev/cl/415854 mentions this issue: cmd/compile: fix prove pass when lower condition is >= minint

@gopherbot
Copy link

gopherbot commented Jul 2, 2022

Change https://go.dev/cl/415874 mentions this issue: cmd/compile: rework induction variable detector

@dr2chase dr2chase added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 3, 2022
@dmitshur dmitshur added this to the Go1.19 milestone Jul 6, 2022
jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants