Skip to content

x/tools/go/ssa: no way to determine type of *deferStack #72914

Open
@aykevl

Description

@aykevl

Go version

go version go1.24.0 linux/arm64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/ayke/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/ayke/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3827790920=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/ayke/src/tinygo/tinygo/go.mod'
GOMODCACHE='/home/ayke/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ayke'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go1.24.0'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/ayke/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go1.24.0/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.24.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I have the following code:

package main

func main() {
        for range func(func() bool) {} {
                defer func() {}()
        }
}

I ran it through ssadump:

$ ssadump -build GCFI code.go

What did you see happen?

See this short part of the output of the main function:

# Name: command-line-arguments.main
# Package: command-line-arguments
# Location: /home/ayke/src/tinygo/tinygo/tmp/issue4441.go:3:6
# Recover: 2
func main():
0:                                                                entry P:0 S:2
        t0 = ssa:deferstack()                                       *deferStack
        t1 = new *deferStack (defer$stack)                         **deferStack
        *t1 = t0
[...]

It has a new *deferStack (defer$stack) instruction. Unfortunately, it's hard to detect this specific type. For other types (in the go/types package) you can use type asserts and such to determine the type, but there is no way to do it for the deferStack.

(Also, typeutil.Map panics when it encounters a *deferStack type so typeutil.Map can't be used here, I'm not sure whether this is intended or not).

What did you expect to see?

I would like to see a way to detect this type, either by making the ssa.opaqueType public (to allow type asserts) or by making ssa.tDeferStack public (to compare against).

I guess I can use reflection to do the same, but that feels like a kludge and not how the API was meant to be used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions