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: '(*Tree[go.shape.int]).RemoveParent.func1': value .dict (nil) incorrectly live at entry #58341

Closed
anupcshan opened this issue Feb 5, 2023 · 6 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@anupcshan
Copy link

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

$ go version
go version go1.20 linux/amd64

Does this issue reproduce with the latest release?

Reproduces with Go 1.20, but not with 1.19.4

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/codespace/.cache/go-build"
GOENV="/home/codespace/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/codespace/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/codespace/go:/home/codespace/src/server/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/workspaces/goissue/go.mod"
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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1991160894=/tmp/go-build -gno-record-gcc-switches"

What did you do?

main.go:

package main

func main() {
        _ = Tree[int]{}
}

type Tree[T comparable] struct {
        parent map[T]T
}

func (g *Tree[T]) RemoveParent(node T) {
        defer delete(g.parent, node)
        // To fix, remove "defer" from the above line, like below.
        // delete(g.parent, node)
}

What did you expect to see?

$ go build

What did you see instead?

$ go build
# goissue
./main.go:12:2: internal compiler error: '(*Tree[go.shape.int]).RemoveParent.func1': value .dict (nil) incorrectly live at entry

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

#57778 shows the same error

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 5, 2023
@cuonglm
Copy link
Member

cuonglm commented Feb 6, 2023

It seems to me that GOEXPERIMENT=nounified build ok, but unified IR crashes.

@cuonglm cuonglm added the NeedsFix The path to resolution is known, but the work has not been done. label Feb 6, 2023
@cuonglm cuonglm added this to the Go1.21 milestone Feb 6, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/466035 mentions this issue: cmd/compile: fix wrong ecsape analysis for go/defer generic calls

@cuonglm
Copy link
Member

cuonglm commented Feb 7, 2023

Seems we need to backport this? @mdempsky @randall77

@mdempsky
Copy link
Contributor

@cuonglm Yes, I think so.

@gopherbot Please backport to Go 1.20.

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #58467 (for 1.20).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@mdempsky
Copy link
Contributor

FWIW, as a workaround until a fix is included in a point release, if you change defer delete(m, k) into defer func() { delete(m, k) }(), it should work. The same applies to any other go/defer calls to builtin functions within a generic function/method.

johanbrandhorst pushed a commit to Pryz/go that referenced this issue Feb 22, 2023
For go/defer calls like "defer f(x, y)", the compiler rewrites it to:

	x1, y1 := x, y
	defer func() { f(x1, y1) }()

However, if "f" needs runtime type information, the "RType" field will
refer to the outer ".dict" param, causing wrong liveness analysis.

To fix this, if "f" refers to outer ".dict", the dict param will be
copied to an autotmp, and "f" will refer to this autotmp instead.

Fixes golang#58341

Change-Id: I238b6e75441442b5540d39bc818205398e80c94d
Reviewed-on: https://go-review.googlesource.com/c/go/+/466035
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Feb 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge 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