Skip to content

cmd/compile: incorrect loop variable detection #53653

Closed

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

Activity

  1. gopherbot commented on Jul 2, 2022

    @gopherbot
    Contributor

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

  2. gopherbot commented on Jul 2, 2022

    @gopherbot
    Contributor

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

  3. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Jul 3, 2022
  4. added this to the Go1.19 milestone on Jul 6, 2022
  5. added a commit that references this issue on Aug 10, 2022
    e2abf12
  6. locked and limited conversation to collaborators on Jul 6, 2023
  7. added a commit that references this issue on Feb 10, 2024
    2acd364
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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