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: ssa.EnclosingFunction panic #59428

Closed
nabice opened this issue Apr 4, 2023 · 3 comments
Closed

x/tools/go/ssa: ssa.EnclosingFunction panic #59428

nabice opened this issue Apr 4, 2023 · 3 comments
Assignees
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

@nabice
Copy link

nabice commented Apr 4, 2023

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

$ go version
go version go1.20.2 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/nabice/.cache/go-build"
GOENV="/home/nabice/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/nabice/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/nabice/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/nabice/source/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/nabice/source/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.2"
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 -fdebug-prefix-map=/tmp/go-build2666103133=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Source Code:
parser.go: https://go.dev/play/p/P-kZ6j7Eq7R
async_pool.go: https://go.dev/play/p/hVneLr-mMLI

Build parser.go and run, program will read async_pool.go, and crashes occasionally.
I think the problem is here:
https://github.com/golang/tools/blob/d5076cc64d484da83963b1ae098aef830c21c448/go/ssa/source.go#L112-L128
Here, the iteration order of the map may be inconsistent. If the outer struct(AsyncPoolProcessor) is iterated first, a new *types.Func will be generated, and its address is different.

What did you expect to see?

No panic.

What did you see instead?

Panic

command-line-arguments.NewAsyncPool
panic: interface conversion: ssa.Member is nil, not *ssa.Function

goroutine 1 [running]:
golang.org/x/tools/go/ssa.findNamedFunc(0xc00011a280, 0x8f)
        /home/nabice/go/pkg/mod/golang.org/x/tools@v0.7.0/go/ssa/source.go:124 +0x1fe
golang.org/x/tools/go/ssa.findEnclosingPackageLevelFunction(0x5f5800?, {0xc0000693a0?, 0xc0000fbb40?, 0xc0000fbb48?})
        /home/nabice/go/pkg/mod/golang.org/x/tools@v0.7.0/go/ssa/source.go:101 +0xb8
golang.org/x/tools/go/ssa.EnclosingFunction(0x6230e0?, {0xc0000693a0?, 0x2, 0x6b18b8?})
        /home/nabice/go/pkg/mod/golang.org/x/tools@v0.7.0/go/ssa/source.go:34 +0x2c
main.main.func2({0x6b1b88?, 0xc000076990})
@nabice nabice changed the title affected/package: golang.org/x/tools/go/ssa golang.org/x/tools/go/ssa: ssa.EnclosingFunction panic Apr 4, 2023
@mknyszek mknyszek changed the title golang.org/x/tools/go/ssa: ssa.EnclosingFunction panic x/tools/go/ssa: ssa.EnclosingFunction panic Apr 4, 2023
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 4, 2023
@mknyszek mknyszek added this to the Backlog milestone Apr 4, 2023
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Apr 4, 2023
@gopherbot gopherbot modified the milestones: Backlog, Unreleased Apr 4, 2023
@mknyszek
Copy link
Contributor

mknyszek commented Apr 4, 2023

CC @golang/tools-team

@nabice
Copy link
Author

nabice commented Apr 6, 2023

Workaround:

if obj.Pos() == pos {
    for _, o := range pkg.objects {
        if f, ok := o.(*Function); ok {
            if f.Pos() == pos && f.Name() == obj.Name() {
                return f
            }
        }
    }
}

@timothy-king timothy-king self-assigned this Apr 6, 2023
@gopherbot
Copy link

Change https://go.dev/cl/491155 mentions this issue: go/ssa: use origin method in source lookup

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

4 participants