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/go: panic: runtime error: invalid memory address or nil pointer dereference during type checking in go generate #66670

Closed
pgavlin opened this issue Apr 3, 2024 · 3 comments

Comments

@pgavlin
Copy link
Contributor

pgavlin commented Apr 3, 2024

Go version

go version go1.22.2 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/pgavlin/Library/Caches/go-build'
GOENV='/Users/pgavlin/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/pgavlin/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/pgavlin/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/pgavlin/dev/dawn/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 -ffile-prefix-map=/var/folders/5s/zjjxx0nn25n9485s6tr_llxh0000gn/T/go-build3994936334=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Ran go generate ./... from the module root. The module is https://github.com/pgavlin/dawn.

What did you see happen?

dawn ❯ go generate ./...
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1008499d4]

goroutine 36 [running]:
go/types.(*Checker).handleBailout(0x14000d42600, 0x14001033c38)
	/usr/local/go/src/go/types/check.go:367 +0x9c
panic({0x100961d00?, 0x100b55100?})
	/usr/local/go/src/runtime/panic.go:770 +0x124
go/types.(*StdSizes).Sizeof(0x0, {0x1009ab680, 0x100b586c0})
	/usr/local/go/src/go/types/sizes.go:228 +0x314
go/types.(*Config).sizeof(...)
	/usr/local/go/src/go/types/sizes.go:333
go/types.representableConst.func1({0x1009ab680?, 0x100b586c0?})
	/usr/local/go/src/go/types/const.go:76 +0x9c
go/types.representableConst({0x1009ad380, 0x100b4c560}, 0x14000d42600, 0x100b586c0, 0x1400108b3e8)
	/usr/local/go/src/go/types/const.go:92 +0x138
go/types.(*Checker).conversion.func1({0x1009aad20?, 0x14000f860e0?}, 0x1400108b3e8)
	/usr/local/go/src/go/types/conversions.go:24 +0x74
go/types.(*Checker).conversion(0x14000d42600, 0x1400108b3c0, {0x1009aad20, 0x14000f860e0})
	/usr/local/go/src/go/types/conversions.go:44 +0x18c
go/types.(*Checker).callExpr(0x14000d42600, 0x1400108b3c0, 0x14000af68c0)
	/usr/local/go/src/go/types/call.go:224 +0xa54
go/types.(*Checker).exprInternal(0x14000d42600, 0x0, 0x1400108b3c0, {0x1009ac9c8, 0x14000af68c0}, {0x0, 0x0})
	/usr/local/go/src/go/types/expr.go:1374 +0xd0
go/types.(*Checker).rawExpr(0x14000d42600, 0x0, 0x1400108b3c0, {0x1009ac9c8?, 0x14000af68c0?}, {0x0?, 0x0?}, 0x0)
	/usr/local/go/src/go/types/expr.go:979 +0x12c
go/types.(*Checker).expr(0x14000d42600, 0x0?, 0x1400108b3c0, {0x1009ac9c8?, 0x14000af68c0?})
	/usr/local/go/src/go/types/expr.go:1513 +0x38
go/types.(*Checker).varDecl(0x14000d42600, 0x14000aa1140, {0x14000d046d8, 0x1, 0x1}, {0x0, 0x0}, {0x1009ac9c8, 0x14000af68c0})
	/usr/local/go/src/go/types/decl.go:521 +0x140
go/types.(*Checker).objDecl(0x14000d42600, {0x1009b0678, 0x14000aa1140}, 0x0)
	/usr/local/go/src/go/types/decl.go:194 +0x7ec
go/types.(*Checker).packageObjects(0x14000d42600)
	/usr/local/go/src/go/types/resolver.go:693 +0x468
go/types.(*Checker).checkFiles(0x14000d42600, {0x140004e5500, 0xf, 0xf})
	/usr/local/go/src/go/types/check.go:408 +0x164
go/types.(*Checker).Files(...)
	/usr/local/go/src/go/types/check.go:372
golang.org/x/tools/go/packages.(*loader).loadPackage(0x14000148000, 0x140004d3160)
	/Users/pgavlin/go/pkg/mod/golang.org/x/tools@v0.1.12/go/packages/packages.go:1001 +0x624
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
	/Users/pgavlin/go/pkg/mod/golang.org/x/tools@v0.1.12/go/packages/packages.go:838 +0x178
sync.(*Once).doSlow(0x10065feb0?, 0x1400023a360?)
	/usr/local/go/src/sync/once.go:74 +0x100
sync.(*Once).Do(...)
	/usr/local/go/src/sync/once.go:65
golang.org/x/tools/go/packages.(*loader).loadRecursive(0x0?, 0x1006c7154?)
	/Users/pgavlin/go/pkg/mod/golang.org/x/tools@v0.1.12/go/packages/packages.go:826 +0x50
golang.org/x/tools/go/packages.(*loader).refine.func2(0x0?)
	/Users/pgavlin/go/pkg/mod/golang.org/x/tools@v0.1.12/go/packages/packages.go:761 +0x30
created by golang.org/x/tools/go/packages.(*loader).refine in goroutine 1
	/Users/pgavlin/go/pkg/mod/golang.org/x/tools@v0.1.12/go/packages/packages.go:760 +0xa80
exit status 2
project_builtins.go:1: running "go": exit status 1

What did you expect to see?

I expected go generate to complete successfully.

This frame seems to indicate that the receiver of (*StdSizes).Sizeof is nil:

go/types.(*StdSizes).Sizeof(0x0, {0x1009ab680, 0x100b586c0})
	/usr/local/go/src/go/types/sizes.go:228 +0x314

Not sure how that might happen ¯_(ツ)_/¯

@seankhliao
Copy link
Member

That's a problem of the command you run, e.g. ./cmd/dawn-gen-builtins, not of go itself.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2024
@pgavlin
Copy link
Contributor Author

pgavlin commented Apr 4, 2024

That's a problem of the command you run, e.g. ./cmd/dawn-gen-builtins, not of go itself.

To close the loop--I needed to update golang.org/x/tools.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/577455 mentions this issue: go/types: fix incorrect non-nil check causing panic

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

No branches or pull requests

3 participants