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: 'main': Value live at entry. It shouldn't be #52590

Closed
lurenjia528 opened this issue Apr 27, 2022 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@lurenjia528
Copy link

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

$ go version
go version go1.18 windows/amd64

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
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\lurenjia\AppData\Local\go-build
set GOENV=C:\Users\lurenjia\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\gopath\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\gopath
set GOPRIVATE=
set GOPROXY=https://goproxy.io,direct
set GOROOT=D:\softwarelocation\go
set GOSUMDB=off
set GOTMPDIR=
set GOTOOLDIR=D:\softwarelocation\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.18
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\work\code\archer\archer-all\go.mod
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\lurenjia\AppData\Local\Temp\go-build2952525131=/tmp/go-build -gno-record-gcc-switches

What did you do?

.\main.go:17:23: internal compiler error: 'main': Value live at entry. It shouldn't be. func main, node bbb..autotmp_0, value nil

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

recurrent

 tree
.
├── aaa
│   └── main.go
└── bbb
    └── bbb.go

 # cat aaa/main.go 
package main

import (
        "archer-all/test/bbb"
)

func main() {
        bbb.InitOrUpdateTable()
}
# cat bbb/bbb.go 
package bbb

func InitOrUpdateTable() {
        println(T())
}

func T() (int, int) {
        return 1, 1
}

then

 go build aaa/main.go 
# command-line-arguments
aaa/main.go:12:23: internal compiler error: 'main': Value live at entry. It shouldn't be. func main, node bbb..autotmp_0, value nil

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

but if modify bbb/bbb.go

package bbb

import "fmt"

func InitOrUpdateTable() {
	fmt.Println(1)
	println(T())
}

func T() (int, int) {
	return 1, 1
}

then

 # go run aaa/main.go 
1
1 1

What did you expect to see?

why is the println() error

What did you see instead?

@mengzhuo mengzhuo changed the title affected/package: builtin cmd/compile: internal compiler error: 'main': Value live at entry. It shouldn't be Apr 27, 2022
@ianlancetaylor
Copy link
Contributor

CC @randall77 @mdempsky

@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Apr 28, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Apr 28, 2022
@mdempsky
Copy link
Member

Playground link: https://go.dev/play/p/V1I_NzFDws5

@mdempsky
Copy link
Member

mdempsky commented Apr 28, 2022

I think the issue is we're missing export/import for n.Init for OPRINTLN, and other builtins that allow multiple arguments.

Good:

case ir.OCALL, ir.OCALLFUNC, ir.OCALLMETH, ir.OCALLINTER, ir.OGETG:
n := n.(*ir.CallExpr)
if go117ExportTypes {
w.op(n.Op())
} else {
w.op(ir.OCALL)
}
w.pos(n.Pos())
w.stmtList(n.Init())
w.expr(n.X)
w.exprList(n.Args)

Bad:

case ir.OAPPEND, ir.ODELETE, ir.ORECOVER, ir.OPRINT, ir.OPRINTN:
n := n.(*ir.CallExpr)
w.op(n.Op())
w.pos(n.Pos())
w.exprList(n.Args) // emits terminating OEND

Should be a straightforward fix (just matching changes to iexport.go and iimport.go, and a regress test case). I'll send a CL tomorrow, unless any contributors want to tackle it.

@gopherbot
Copy link

Change https://go.dev/cl/402854 mentions this issue: cmd/compile: fix missing export/import init nodes of builtins that allow multiple arguments

@mdempsky
Copy link
Member

FWIW, I think the fix is small and could be easily backported, but I don't think it's necessary here.

It looks like the same issue existed back in Go 1.16, so it's not a recent regression. So there's probably no existing code running into this.

There's also two easy workarounds: (1) rewrite the code to manually spill the multi-value results to temporary variables (e.g., rewrite println(T()) to x, y := T(); println(x, y); or (2) mark the function as //go:noinline.

If anyone else thinks it deserves a backport, I encourage opening a backport issue and we can discuss further there. Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants