Skip to content

cmd/compile: incorrect loop trip count #78303

@jake-ciolek

Description

@jake-ciolek

Go version

go 1.26.1

Output of go env in your module/workspace:

GOARCH=arm64

What did you do?

package main

var n = 1

func main() {
	m := int64(len("x"[:n])) - (1 << 62)
	for i, j := int64(-1<<63), 0; i < m; i, j = i+(1<<62), j+1 {
		if j == 2 {
			println(3)
			return
		}
	}
	println(2)
}

What did you see happen?

$ go run .                                                                                                                                                                               
3
$ go run -gcflags='all=-N -l' .
2

What did you expect to see?

Same result for optimized/unoptimized builds.

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.release-blocker

Type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions