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: panic: interface conversion: interface is nil, not ir.Node #61074

Closed
nholstein opened this issue Jun 29, 2023 · 6 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@nholstein
Copy link

What version of Go are you using (go version)?

I'm using 1.20.5 from https://pkg.go.dev/golang.org/dl/go1.20.5

$ go1.20.5 version
go version go1.20.5 darwin/arm64

Does this issue reproduce with the latest release?

Yes, with 1.20.5. It does not reproduce with 1.21rc2.

What operating system and processor architecture are you using (go env)?

I'm running on darwin/arm64. I've also reproduced on linux/amd64.

go env Output
$ go1.20.5 env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/ngh/Library/Caches/go-build"
GOENV="/Users/ngh/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/ngh/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ngh/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/ngh/sdk/go1.20.5"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/ngh/sdk/go1.20.5/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7q/4jtm00sd11d6vh2r7m59snmr0000gn/T/go-build2788118703=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I was testing the new clear builtin on go1.21rc2, then ran the same code on go1.20.5. I expected the compilation to fail due to the undefined clear function; instead the compiler panicked. I minimized to the following program:

package main

func main() {
        var foo []string
        clear(foo)
}

And see the following error:

$ go1.20.5 run ./clear.go
# command-line-arguments
./clear.go:3:6: internal compiler error: panic: interface conversion: interface is nil, not ir.Node

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new

What did you expect to see?

A compilation error ("./clear.go:5:9: undefined: clear") on go1.20.5.

Successful compilation on go1.21rc2.

What did you see instead?

Successful compilation on go1.21rc2. 👍

An internal compiler error panic with go1.20.5:

./clear.go:3:6: internal compiler error: panic: interface conversion: interface is nil, not ir.Node
@nholstein
Copy link
Author

It's worth noting the impact of this crash is limited; it only impacts valid Go 1.21 code using clear when compiled with go1.20.x. Older versions of Go behave as expected; go1.19.9 handles the erroneous source correctly:

$ go1.19.9 run ./clear.go
# command-line-arguments
./clear.go:5:9: undefined: clear

And with go1.20.5 any name other than clear doesn't crash. Additionally, if I change the type of var foo []string to a non-clearable type (var foo int), go1.20.5 doesn't panic and returns this error:

$ go1.20.5 run ./clear.go
# command-line-arguments
./clear.go:5:15: invalid argument: cannot clear foo (variable of type int): argument must be (or constrained by) map, slice, or array pointer

I've been testing by directly running the source file (go run ./clear.go); if module mode is enabled the compiler helpfully prints this error:

note: module requires Go 1.21

So I believe this will only impact code which correctly uses clear in 1.21 when compiled using a go1.20.x toolchain. One way this might occur is if a Go 1.20 module imports as 1.21 module.

@cuonglm
Copy link
Member

cuonglm commented Jun 29, 2023

GOEXPERIMENT=nounified produces a better message, though still ICE:

$ GOEXPERIMENT=nounified go1.20.5 run main.go
# command-line-arguments
<unknown line number>: internal compiler error: failed to resolve builtin clear

cc @mdempsky @griesemer for decision.

@cuonglm cuonglm added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jun 29, 2023
@griesemer
Copy link
Contributor

go1.20 should report the error

clear requires go1.21 or later (-lang was set to go1.20; check go.mod)

(playground).

@cuonglm
Copy link
Member

cuonglm commented Jun 29, 2023

go1.20 should report the error

clear requires go1.21 or later (-lang was set to go1.20; check go.mod)

(playground).

go1.20 and go1.20.x trigger ICE in my local, not sure why playground doesn't.

@mdempsky
Copy link
Member

Playground autogenerates a 1.20 go.mod file I think. This repros it: https://go.dev/play/p/sbnZ28wE-s6

I think the issue is 1.20 typechecker understands clear and allows it sometimes, but the backend doesn't have it at all.

@mdempsky
Copy link
Member

The problem here is basically just a worse error message: the Go 1.20 compiler is crashing and reporting an ICE instead of giving a standard error message when trying to compile Go 1.21 code.

We could backport a fix to report a nicer error message, but I don't think that really lives up to the standard we normally expect of backports. And it's not an issue with 1.21 or moving forward.

@bcmills bcmills added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jun 29, 2023
@mknyszek mknyszek changed the title cmd/compile@1.20.5: internal compiler error: panic: interface conversion: interface is nil, not ir.Node cmd/compile: internal compiler error: panic: interface conversion: interface is nil, not ir.Node Jul 12, 2023
@mknyszek mknyszek added this to the Backlog milestone Jul 12, 2023
@mknyszek mknyszek closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2023
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. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

6 participants