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

go/ir: nil pointer dereference panic #1270

Closed
tdakkota opened this issue May 11, 2022 · 1 comment
Closed

go/ir: nil pointer dereference panic #1270

tdakkota opened this issue May 11, 2022 · 1 comment
Labels

Comments

@tdakkota
Copy link
Contributor

tdakkota commented May 11, 2022

The output of 'staticcheck -version'

$ staticcheck -version
staticcheck.exe 2022.1.1 (v0.3.1)

The output of 'staticcheck -debug.version' (it is fine if this command fails)

$ staticcheck -debug.version
flag provided but not defined: -debug
...

The output of 'go version'

$ go version
go version go1.18.2 windows/amd64

The output of 'go env'

$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\tdakkota\AppData\Local\go-build
set GOENV=C:\Users\tdakkota\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\tdakkota\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\tdakkota\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.18.2
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=G:\workspace\ogen\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

Exactly which command you ran/Output of the command and what's wrong with the output

$ staticcheck
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x8f8d37]

goroutine 225 [running]:
honnef.co/go/tools/go/ir.(*builder).expr0(0xc001ab87e0, 0xc001cb4dc0, {0xbfac18?, 0xc001113b00?}, {0x7, {0xbf9490, 0xc00255ae40}, {0x0, 0x0}})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:674 +0xfb7
honnef.co/go/tools/go/ir.(*builder).expr(0xae8740?, 0xc001cb4dc0, {0xbfac18?, 0xc001113b00?})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:566 +0x1db
honnef.co/go/tools/go/ir.(*builder).emitCallArgs(0xbf93f0?, 0xc001cb4dc0, 0xc000e39740, 0xc003488cc8?, {0x0?, 0xc001ab7980?, 0x63d867?})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:954 +0xd65
honnef.co/go/tools/go/ir.(*builder).setCall(0xbf8ae0?, 0xc001cb4dc0, 0xc0022a3100, 0xc003488cc8)
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:1030 +0x8e
honnef.co/go/tools/go/ir.(*builder).expr0(0xc001ab87e0, 0xc001cb4dc0, {0xbfa618?, 0xc0022a3100?}, {0x7, {0xbf9418, 0xc0022e81c0}, {0x0, 0x0}})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:623 +0x235e
honnef.co/go/tools/go/ir.(*builder).expr(0xb698b0?, 0xc001cb4dc0, {0xbfa618?, 0xc0022a3100?})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:566 +0x1db
honnef.co/go/tools/go/ir.(*builder).assign(0xbfabb8?, 0xc002299530?, {0xbfb4d8, 0xc00349ba60}, {0xbfa618?, 0xc0022a3100?}, 0xc0?, 0xc001ab7f60, {0xbf8978, 0xc0022a3140})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:538 +0x605
honnef.co/go/tools/go/ir.(*builder).assignStmt(0xc0022a30c0?, 0xc001cb4dc0, {0xc0022a4c50, 0x1, 0x0?}, {0xc0022a4c70, 0x1, 0xbf9490?}, 0x0, {0xbf8978, ...})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:1111 +0x29f
honnef.co/go/tools/go/ir.(*builder).stmt(0x63b27d?, 0xc001cb4dc0, {0xbfa498?, 0xc0022a3140?})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:2245 +0xa0b
honnef.co/go/tools/go/ir.(*builder).stmtList(0xc001ab8218?, 0x0?, {0xc00112f980?, 0x7, 0x0?})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:848 +0x67
honnef.co/go/tools/go/ir.(*builder).stmt(0xc001cb4dc0?, 0xc001cb4dc0, {0xbfa5b8?, 0xc0022b6420?})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:2331 +0xd31
honnef.co/go/tools/go/ir.(*builder).buildFunction(0xc001ab87e0, 0xc001cb4dc0)
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:2443 +0x453
honnef.co/go/tools/go/ir.(*builder).buildFuncDecl(0x0?, 0xc00234aab0, 0xc0022b6450)
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:2481 +0x195
honnef.co/go/tools/go/ir.(*Package).build(0xc00234aab0)
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:2587 +0xc52
sync.(*Once).doSlow(0xc001910a80?, 0xc000e41ef0?)
        c:/go/src/sync/once.go:68 +0xc2
sync.(*Once).Do(...)
        c:/go/src/sync/once.go:59
honnef.co/go/tools/go/ir.(*Package).Build(...)
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:2505
honnef.co/go/tools/internal/passes/buildir.run(0xc001714340)
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/internal/passes/buildir/buildir.go:86 +0x368
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc001789fb0, {0xbfbbd8?, 0xc000e13720})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/lintcmd/runner/runner.go:1032 +0x614
honnef.co/go/tools/lintcmd/runner.genericHandle({0xbfbbd8?, 0xc000e13720}, {0xbfbbd8?, 0xc000e13680?}, 0x63d505?, 0x0, 0xc0009c6e40)
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/lintcmd/runner/runner.go:857 +0x102
honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers(0xc0002ea870, 0xc0006fd680, 0xc000e41f40)
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/lintcmd/runner/runner.go:1105 +0x766
honnef.co/go/tools/lintcmd/runner.(*subrunner).doUncached(0xc0002ea870, 0xc0006fd680)
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/lintcmd/runner/runner.go:728 +0x1c9
honnef.co/go/tools/lintcmd/runner.(*subrunner).do(0xc0002ea870, {0xbfbc20?, 0xc0006fd680})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/lintcmd/runner/runner.go:584 +0x78d
honnef.co/go/tools/lintcmd/runner.(*Runner).Run.func2({0xbfbc20?, 0xc0006fd680?})
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/lintcmd/runner/runner.go:1308 +0x30
honnef.co/go/tools/lintcmd/runner.genericHandle({0xbfbc20?, 0xc0006fd680}, {0xbfbc20?, 0xc00007eb40?}, 0x0?, 0xc00034d9f0, 0xc000bc6e10)
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/lintcmd/runner/runner.go:857 +0x102
created by honnef.co/go/tools/lintcmd/runner.(*Runner).Run
        C:/Users/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.3.1/lintcmd/runner/runner.go:1307 +0x525

Running staticcheck via golangci-lint leads to the same panic (failed CI workflow link).

Where we can read the code you're running Staticcheck on

https://github.com/ogen-go/ogen
https://github.com/go-faster/jx (ogen dependency, seems it causes panic)

@tdakkota tdakkota added bug needs-triage Newly filed issue that needs triage labels May 11, 2022
@tdakkota
Copy link
Contributor Author

Smaller reproducer:

package foobar

type byteseq interface {
	string | []byte
}

func foo[T byteseq](s T) T {
	return s[0:len(s)]
}

@tdakkota tdakkota changed the title ir: nil pointer dereference panic go/ir: nil pointer dereference panic May 11, 2022
@dominikh dominikh removed the needs-triage Newly filed issue that needs triage label May 11, 2022
dominikh pushed a commit that referenced this issue May 16, 2022
Closes: gh-1270
Closes: gh-1271 [via git-merge-pr]
Co-authored-by: Dominik Honnef <dominik@honnef.co>
(cherry picked from commit 67bbe3d)
dominikh pushed a commit that referenced this issue May 16, 2022
Closes: gh-1270
Closes: gh-1271 [via git-merge-pr]
Co-authored-by: Dominik Honnef <dominik@honnef.co>
(cherry picked from commit 67bbe3d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants