Skip to content

cmd/compile: incorrect loop variable detection #53653

@randall77

Description

@randall77
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions