Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

go/types: panic in (*StdSizes).Sizeof when building github.com/kisielk/errcheck with Go tip #64347

Closed
1 task
siebenmann opened this issue Nov 22, 2023 · 3 comments

Comments

@siebenmann
Copy link

Go version

go version devel go1.22-37aed23f51 Wed Nov 22 19:53:59 2023 +0000 linux/amd64

Reproducibility

  • Does this issue reproduce with the latest release?

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

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/homes/hawkwind/u0/cks/.cache/go-build'
GOENV='/homes/hawkwind/u0/cks/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/homes/hawkwind/u0/cks/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/homes/hawkwind/u0/cks/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/data/code/go-lang/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='path'
GOTOOLDIR='/data/code/go-lang/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.22-37aed23f51 Wed Nov 22 19:53:59 2023 +0000'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -ffile-prefix-map=/tmpfs/go-build1784122446=/tmp/go-build -gno-record-gcc-switches'

What did you do?

A version of github.com/kisielk/errcheck built from the current Go tip will panic when attempting to check anything, including its own main.go. A dlv stack trace says this happens in:

0  0x000000000043efc4 in runtime.fatalpanic
    at /data/code/go-lang/go/src/runtime/panic.go:1217
 1  0x000000000043dfbd in runtime.gopanic
    at /data/code/go-lang/go/src/runtime/panic.go:779
 2  0x00000000005fd665 in go/types.(*Checker).handleBailout
    at /data/code/go-lang/go/src/go/types/check.go:366
 3  0x00000000005fdfb3 in go/types.(*Checker).checkFiles.deferwrap1
    at /data/code/go-lang/go/src/go/types/check.go:391
 4  0x000000000043df96 in runtime.gopanic
    at /data/code/go-lang/go/src/runtime/panic.go:770
 5  0x000000000043d25e in runtime.panicmem
    at /data/code/go-lang/go/src/runtime/panic.go:261
 6  0x00000000004566c5 in runtime.sigpanic
    at /data/code/go-lang/go/src/runtime/signal_unix.go:866
 7  0x0000000000660bec in go/types.(*StdSizes).Sizeof
    at /data/code/go-lang/go/src/go/types/sizes.go:228
 8  0x0000000000694a2e in go/types.Sizes.Sizeof-fm
    at <autogenerated>:1
 9  0x00000000006616eb in go/types.(*Config).sizeof
    at /data/code/go-lang/go/src/go/types/sizes.go:333
10  0x0000000000601019 in go/types.representableConst.func1
    at /data/code/go-lang/go/src/go/types/const.go:76
11  0x0000000000600389 in go/types.representableConst
    at /data/code/go-lang/go/src/go/types/const.go:92
12  0x000000000060154f in go/types.(*Checker).representation
    at /data/code/go-lang/go/src/go/types/const.go:256
13  0x0000000000615b97 in go/types.(*Checker).implicitTypeAndValue
    at /data/code/go-lang/go/src/go/types/expr.go:375
14  0x00000000005e0a33 in go/types.(*Checker).assignment
    at /data/code/go-lang/go/src/go/types/assignments.go:52
15  0x00000000005e1a4e in go/types.(*Checker).initConst
    at /data/code/go-lang/go/src/go/types/assignments.go:126
16  0x000000000060b014 in go/types.(*Checker).constDecl
    at /data/code/go-lang/go/src/go/types/decl.go:490
17  0x000000000060789f in go/types.(*Checker).objDecl
    at /data/code/go-lang/go/src/go/types/decl.go:191
18  0x00000000006574d2 in go/types.(*Checker).packageObjects
    at /data/code/go-lang/go/src/go/types/resolver.go:693
19  0x00000000005fdb0b in go/types.(*Checker).checkFiles
    at /data/code/go-lang/go/src/go/types/check.go:407
20  0x00000000005fd6e5 in go/types.(*Checker).Files
    at /data/code/go-lang/go/src/go/types/check.go:371
21  0x0000000000713365 in golang.org/x/tools/go/packages.(*loader).loadPackage
    at /homes/hawkwind/u0/cks/go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:1052
[...]

The first non-panic related frame appears to be frame 7, where dlv says the panicing line is return s.WordSize // catch-all and s is nil.

Reproduction is straightforward:

cd /tmp
git clone https://github.com/kisielk/errcheck
cd errcheck
go build -o errcheck.bin
./errcheck.bin main.go
[panic]

I believe this has been happening in the development version for some unknown length of time, but it doesn't happen with Go 1.21.

What did you expect to see?

No panic.

What did you see instead?

The panic above.

@timothy-king
Copy link
Contributor

Maybe related #62103 ?

Several CLs listed there were updates to x/tools in the go.mod file example https://go.dev/cl/520435.

https://github.com/kisielk/errcheck looks to be on an old version of x/tools:

require golang.org/x/tools v0.9.1

My guess is you need to sync past https://go.dev/cl/520555. So does go get golang.org/x/tools@v0.15.0; go mod tidy resolve the issue?

@siebenmann
Copy link
Author

Updating golang.org/x/tools to v0.15.0 does seem to fix the issue; I can't reproduce the crash with a Go tip build of errcheck now.

@mauri870
Copy link
Member

This was fixed in x/tools in CL 516917.

Turns out a wrong type assertion to *types.StdSizes from a *types.gcSizes was causing the sizes to be nil here. Later on in *go/types/stdSizes.Sizeof it tries to access WordSize from s which is nil resulting in the segmentation fault.

Closing as this is an x/tools issue that is already fixed.

@mauri870 mauri870 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2023
@golang golang locked and limited conversation to collaborators Nov 21, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

4 participants