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: internal compiler error on range over negative integer #63378

Closed
ALTree opened this issue Oct 4, 2023 · 1 comment
Closed

cmd/compile: internal compiler error on range over negative integer #63378

ALTree opened this issue Oct 4, 2023 · 1 comment
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ALTree
Copy link
Member

ALTree commented Oct 4, 2023

$ gotip version
go version devel go1.22-e47cab13 Wed Oct 4 17:02:36 2023 +0000 linux/amd64
package main

func main() {
	for i := range -1 {
		println(i)
	}
}
$ GOEXPERIMENT=range gotip build crash.go

# command-line-arguments
<unknown line number>: internal compiler error: assertion failed

goroutine 1 [running]:
runtime/debug.Stack()
	./desktop/gotip/src/runtime/debug/stack.go:24 +0x5e
cmd/compile/internal/base.FatalfAt({0xed4600?, 0x0?}, {0xd7f3b9, 0x10}, {0x0, 0x0, 0x0})
	./desktop/gotip/src/cmd/compile/internal/base/print.go:225 +0x1d7
cmd/compile/internal/base.Fatalf(...)
	./desktop/gotip/src/cmd/compile/internal/base/print.go:194
cmd/compile/internal/base.Assert(...)
	./desktop/gotip/src/cmd/compile/internal/base/print.go:237
cmd/compile/internal/noder.assert(...)
	./desktop/gotip/src/cmd/compile/internal/noder/stencil.go:15
cmd/compile/internal/noder.idealType({{0xed2968, 0x13b61a0}, {0xed4600, 0xc000012f60}, 0x8})
	./desktop/gotip/src/cmd/compile/internal/noder/helpers.go:94 +0x11b
cmd/compile/internal/noder.(*writer).expr(0xc000410160, {0xed5958?, 0xc0003ee9c0?})
	./desktop/gotip/src/cmd/compile/internal/noder/writer.go:1724 +0x79b
cmd/compile/internal/noder.(*writer).forStmt(0xc000410160, 0xc0003eb270)
	./desktop/gotip/src/cmd/compile/internal/noder/writer.go:1429 +0x278
...

cc @golang/compiler

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 4, 2023
@ALTree ALTree added this to the Go1.22 milestone Oct 4, 2023
@ALTree ALTree added the compiler/runtime Issues related to the Go compiler and/or runtime. label Oct 4, 2023
@ALTree ALTree changed the title cmd/compile: internal compiler error on loop over negative integer cmd/compile: internal compiler error on range over negative integer Oct 4, 2023
@gopherbot
Copy link

Change https://go.dev/cl/532835 mentions this issue: cmd/compile: fix typecheck range over negative integer

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 9, 2023
yunginnanet pushed a commit to yunginnanet/go that referenced this issue Oct 20, 2023
Before range over integer, types2 leaves constant expression in RHS of
non-constant shift untyped, so idealType do the validation to ensure
that constant value must be an int >= 0.

With range over int, the range expression can also be left untyped, and
can be an negative integer, causing the validation false.

Fixing this by relaxing the validation in idealType, and moving the
check to Unified IR reader.

Fixes golang#63378

Change-Id: I43042536c09afd98d52c5981adff5dbc5e7d882a
Reviewed-on: https://go-review.googlesource.com/c/go/+/532835
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. 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