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: ir.Node is *ir.CompLitExpr, not *ir.Name #58325

Closed
evanj opened this issue Feb 4, 2023 · 4 comments
Assignees
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

@evanj
Copy link
Contributor

evanj commented Feb 4, 2023

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

$ go version
go version go1.20 darwin/arm64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
$ go env

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/evan.jones/Library/Caches/go-build"
GOENV="/Users/evan.jones/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/evan.jones/go/pkg/mod"
GONOPROXY=""
GOOS="darwin"
GOPATH="/Users/evan.jones/go"
GOPRIVATE=""
GOROOT="/Users/evan.jones/go120"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/evan.jones/go120/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/evan.jones/go120bug/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/g1/97d8s0r57hj4nv4_qd3fqcrm0000gp/T/go-build1938067015=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Attempt to run the following program with Go 1.20

package main

type BugStruct struct {
	wrappedint IntWrapper
}

type IntWrapper struct {
	int
}

func (IntWrapper) Make() IntWrapper {
	return IntWrapper{5}
}

// FromWire decodes trace ID from the data transferred over the wire
func (BugStruct) Make() BugStruct {
	return BugStruct{
		wrappedint: IntWrapper{}.Make(),
	}
}

// triggers the ICE
var somevalue = BugStruct{}.Make()

// does not trigger the ICE
// var somevalue = bugsubpackage.IntWrapper{}.Make()

func main() {}

(this is a silly example, but it was extracted and minimized from a much larger program while trying to get Go 1.20 running)

What did you expect to see?

The binary runs successfully and does nothing.

What did you see instead?

# example.go/go120bug
./bug.go:23:5: internal compiler error: panic: interface conversion: ir.Node is *ir.CompLitExpr, not *ir.Name

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
@seankhliao seankhliao changed the title go 1.20: internal compiler error: panic: interface conversion: ir.Node is *ir.CompLitExpr, not *ir.Name cmd/compile: internal compiler error: panic: interface conversion: ir.Node is *ir.CompLitExpr, not *ir.Name Feb 4, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 4, 2023
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 4, 2023
@cuonglm
Copy link
Member

cuonglm commented Feb 5, 2023

Another issue with inline static init, -gcflags=-d=inlstaticinit=0 makes the program compile and run.

@cuonglm cuonglm self-assigned this Feb 5, 2023
@cuonglm cuonglm 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 Feb 5, 2023
@cuonglm cuonglm added this to the Go1.21 milestone Feb 5, 2023
@gopherbot
Copy link

Change https://go.dev/cl/465098 mentions this issue: cmd/compile: fix inline static init arguments substitued tree

@cuonglm
Copy link
Member

cuonglm commented Feb 5, 2023

@gopherbot please consider backport this to 1.20, it's a regression.

@gopherbot
Copy link

Backport issue(s) opened: #58335 (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.

johanbrandhorst pushed a commit to Pryz/go that referenced this issue Feb 12, 2023
Blank node must be ignored when building arguments substitued tree.
Otherwise, it could be used to replace other blank node in left hand
side of an assignment, causing an invalid IR node.

Consider the following code:

	type S1 struct {
		s2 S2
	}

	type S2 struct{}

	func (S2) Make() S2 {
		return S2{}
	}

	func (S1) Make() S1 {
		return S1{s2: S2{}.Make()}
	}

	var _ = S1{}.Make()

After staticAssignInlinedCall, the assignment becomes:

	var _ = S1{s2: S2{}.Make()}

and the arg substitued tree is "map[*ir.Name]ir.Node{_: S1{}}". Now,
when doing static assignment, if there is any assignment to blank node,
for example:

	_ := S2{}

That blank node will be replaced with "S1{}":

	S1{} := S2{}

So constructing an invalid IR which causes the ICE.

Fixes golang#58325

Change-Id: I21b48357f669a7e02a7eb4325246aadc31f78fb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/465098
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
@golang golang locked and limited conversation to collaborators Feb 8, 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