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: nil pointer deref when printing error message for invalid program in 1.17 #51165

Open
nobozo opened this issue Feb 12, 2022 · 2 comments
Labels
NeedsInvestigation

Comments

@nobozo
Copy link

@nobozo nobozo commented Feb 12, 2022

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

go version go1.17.7 linux/amd64

Does this issue reproduce with the latest release?

This is the latest release.

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

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jonf/.cache/go-build"
GOENV="/home/jonf/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jonf/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jonf/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.17.7"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1969232472=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://go.dev/play/p/K7yu7V7_LsE

What did you expect to see?

Various syntax errors. I know this file doesn't compile. That's not the problem.

What did you see instead?

A compiler panic e.g.

./strcache.go:29:14: cannot assign *st_name to %!L(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference) in multiple assignment

@ALTree
Copy link
Member

@ALTree ALTree commented Feb 12, 2022

It looks like -in go1.17- the culprit is a function in cmd/compile/internal/typecheck/typecheck.go:

$ ag -C3 "cannot assign .* in multiple assignment"
cmd/compile/internal/typecheck/typecheck.go
1696-	}
1697-
1698-	if op, why := Assignop(src, dst.Type()); op == ir.OXXX {
1699:		base.Errorf("cannot assign %v to %L in multiple assignment%s", src, dst, why)
1700-		return
1701-	}
1702-}

now, on tip the error message doesn't have this issue:

$ gotip version
go version devel go1.18-8ba3ad92eb Thu Feb 10 19:08:19 2022 +0000 linux/amd64

$ gotip run test.go
# command-line-arguments
./test.go:25:6: name_st declared but not used
./test.go:28:2: st_name (type) is not an expression
./test.go:31:14: (*st_name).st_refcnt undefined (type *st_name has no method st_refcnt)
./test.go:33:3: st_name (type) is not an expression
./test.go:34:14: (*st_name).st_string undefined (type *st_name has no method st_string)
./test.go:35:14: (*st_name).st_refcnt undefined (type *st_name has no method st_refcnt)
./test.go:37:23: st_name (type) is not an expression
./test.go:40:20: (*st_name).st_string undefined (type *st_name has no method st_string)

The typecheck.go function is still there, but it's possible we no longer call it in a way that triggers the issue.

cc @mdempsky

@ALTree ALTree changed the title affected/package: go build cmd/compile: nil pointer deref when printing error message for invalid program in 1.17 Feb 12, 2022
@ALTree ALTree added the NeedsInvestigation label Feb 12, 2022
@born2ngopi
Copy link

@born2ngopi born2ngopi commented Feb 26, 2022

I think the panic also applies when assigning a map to a data type, ex: bool, ok = string_cache[str]. I thought to check if Op is a data type before assign data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

3 participants