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

x/tools/go/ssa: addNamedLocal panic: runtime error: invalid memory address or nil pointer dereference #58600

Open
lmxx1234567 opened this issue Feb 20, 2023 · 6 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@lmxx1234567
Copy link

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

$ go version
go version go1.18.3 linux/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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/[username]/.cache/go-build"
GOENV="/home/[username]/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/data00/home/[username]/gopath/pkg/mod"
GONOPROXY="*.byted.org,*.everphoto.cn,git.smartisan.com"
GONOSUMDB="*.byted.org,*.everphoto.cn,git.smartisan.com"
GOOS="linux"
GOPATH="/data00/home/[username]/gopath"
GOPRIVATE="*.byted.org,*.everphoto.cn,git.smartisan.com"
GOPROXY="https://go-mod-proxy.byted.org,https://goproxy.cn,https://proxy.golang.org,direct"
GOROOT="/data00/home/[username]/go1.16"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/data00/home/[username]/go1.16/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.3"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/data00/home/[username]/repos/bytest_ut_api/go.mod"
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-build3893359244=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Create SSA program for a set of packages

initial, err := packages.Load(cfg, fileDir)
if err != nil {
return nil, fmt.Errorf("The error belongs to %w\n, the details is: %v", logextractor.ParseProgramError, err.Error())
}

// Create SSA packages for all well-typed packages.
prog, pkgs := ssautil.AllPackages(initial, 0)
prog.Build()

What did you expect to see?

Packages loaded without panic.

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x50 pc=0x104773d28]
goroutine 13469 [running]:
golang.org/x/tools/go/ssa.(*Function).addNamedLocal(0x1400aa32780, {0x0, 0x0})
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/func.go:392 +0x28
golang.org/x/tools/go/ssa.(*Function).addLocalForIdent(...)
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/func.go:399
golang.org/x/tools/go/ssa.(*builder).localValueSpec(0x7708?, 0x1400aa32780, 0x140003b7540)
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:1155 +0x2c0
golang.org/x/tools/go/ssa.(*builder).stmt(0x140000a7901?, 0x1400aa32780, {0x104a42a30?, 0x14003be1bf0?})
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2147 +0x1514
golang.org/x/tools/go/ssa.(*builder).stmtList(0x1049d0e80?, 0x104a453b8?, {0x14005cb0a80?, 0x6, 0x140000a7948?})
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:946 +0x6c
golang.org/x/tools/go/ssa.(*builder).stmt(0x1400aa32780?, 0x1400aa32780, {0x104a428e0?, 0x14005093ec0?})
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2277 +0x850
golang.org/x/tools/go/ssa.(*builder).buildFunctionBody(0x1400aa32180?, 0x1400aa32780)
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2391 +0x3c8
golang.org/x/tools/go/ssa.(*builder).buildFunction(0x104773b30?, 0x1400aa32780)
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2326 +0x34
golang.org/x/tools/go/ssa.(*builder).buildCreated(0x140000a7dd0)
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2413 +0x2c
golang.org/x/tools/go/ssa.(*Package).build(0x1400a8b1c00)
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2606 +0xaf8
sync.(*Once).doSlow(0x140035c37a8?, 0x10474cf24?)
        /usr/local/go/src/sync/once.go:68 +0x10c
sync.(*Once).Do(...)
        /usr/local/go/src/sync/once.go:59
golang.org/x/tools/go/ssa.(*Package).Build(...)
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2477
golang.org/x/tools/go/ssa.(*Program).Build.func1(0x0?)
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2462 +0x58
created by golang.org/x/tools/go/ssa.(*Program).Build
        /Users/[username]/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2461 +0x180

Potentially problematic code

https://cs.opensource.google/go/x/tools/+/refs/tags/v0.6.0:go/ssa/func.go;l=399
f.info.Defs[id] cloud be nil in some case. Should check if Defs[id] == nil at first

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Feb 20, 2023
@gopherbot gopherbot added this to the Unreleased milestone Feb 20, 2023
@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 21, 2023
@thanm
Copy link
Contributor

thanm commented Feb 21, 2023

@golang/tools-team

@thanm
Copy link
Contributor

thanm commented Feb 21, 2023

@lmxx1234567 it would help if you could post a complete reproducer.

@lmxx1234567
Copy link
Author

@thanm ok, I'll try to. It is a litte bit hard to find the code that caused the panic cuz I have built all backage.

@findleyr
Copy link
Contributor

findleyr commented Mar 2, 2023

CC @timothy-king @adonovan

@adonovan
Copy link
Member

adonovan commented Mar 2, 2023

Potentially problematic code https://cs.opensource.google/go/x/tools/+/refs/tags/v0.6.0:go/ssa/func.go;l=399
f.info.Defs[id] cloud be nil in some case. Should check if Defs[id] == nil at first

I don't see any problem there: in all cases, the Ident is non-blank and is guaranteed by its context to be a declaration, and the code is well-typed.

If you are able to reproduce the problem easily, then please run again with the ssautil.AllPackages(initial, ssa.LogSource) mode bit. This will cause it to print source locations as it goes. The last one before the crash should tell you where the problem is. I expect it to be a var declaration statement inside a function body. Thanks.

@timothy-king
Copy link
Contributor

What would help for a reproducer is to also have:

  • A bit more context on the cfg in packages.Load(cfg, ...),
  • the code being built in some form (maybe simplified? maybe just a repo?), and
  • the version of x/tools/go/ssa being used.

I don't see any problem there: in all cases, the Ident is non-blank and is guaranteed by its context to be a declaration, and the code is well-typed.

+1 I don't see an obvious way f.info.Defs[id] could be nil here either. I am not sure how to make much progress without more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

6 participants