Skip to content

fakexml: doesn't terminate checking type X *X #1202

Closed

Description

@fho

The following code causes staticcheck v0.2.2 (staticcheck ./...) to hang forever.
staticcheck v0.2.1 terminates quickly on the same code.

package main

import "fmt"

type OperationHeaders struct {
	OperationCode *OperationCode `xml:"operationCode"`
}

type OperationCode *OperationCode

func main() {
	fmt.Println("hello")
}

If the struct tag xml:"operationCode" in OperationHeaders is omitted, staticcheck 0.2.2 also terminates.

A type definition like this was generated by an xml code generator.
I don't know when such a type definition could make sense.
Go 1.17 and 1.18 compile the code without any issues.


$ staticcheck --version
staticcheck 2021.1.2 (v0.2.2)

$ staticcheck -debug.version
staticcheck 2021.1.2 (v0.2.2)

Compiled with Go version: go1.17.8
Main module:
	honnef.co/go/tools@v0.2.2 (sum: h1:MNh1AVMyVX23VUHE2O27jm6lNj3vjO5DexS4A1xvnzk=)
Dependencies:
	github.com/BurntSushi/toml@v0.3.1 (sum: h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=)
	golang.org/x/mod@v0.3.0 (sum: h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=)
	golang.org/x/sys@v0.0.0-20210119212857-b64e53b001e4 (sum: h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=)
	golang.org/x/tools@v0.1.0 (sum: h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=)
	golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 (sum: h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=)
$ go version
go version go1.17.8 linux/amd64
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/fho/.cache/go-build"
GOENV="/home/fho/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/fho/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/fho/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.8"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/t/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-build66536980=/tmp/go-build -gno-record-gcc-switches"

Activity

  1. added
    needs-triage
    on Mar 16, 2022
  2. changed the title [-]staticcheck hangs forever on recursive type definition[/-] [+]staticcheck hangs forever on recursive type definition with buildtag[/+] on Mar 16, 2022
  3. changed the title [-]staticcheck hangs forever on recursive type definition with buildtag[/-] [+]staticcheck hangs forever on recursive type definition with struct tag[/+] on Mar 16, 2022
  4. removed
    needs-triage
    on Mar 16, 2022
  5. dominikh commented on Mar 16, 2022

    @dominikh
    Owner

    Can reproduce.

  6. dominikh commented on Mar 16, 2022

    @dominikh
    Owner

    In v0.2.2 we started reusing encoding/xml's logic for checking if types can be marshaled. We inherited its infinite loop (cf. https://go.dev/play/p/SYxLx7YKqoT which doesn't terminate).

    This is (probably) fine for encoding/xml, which in general doesn't support cyclic data structures, but obviously not fine for static analysis.

  7. changed the title [-]staticcheck hangs forever on recursive type definition with struct tag[/-] [+]fakexml: doesn't terminate checking `type X *X`[/+] on Mar 16, 2022
  8. fho commented on Mar 31, 2022

    @fho
    Author

    thanks a lot @dominikh

  9. added a commit that references this issue on Apr 3, 2022
    5322218
  10. added a commit that references this issue on Apr 8, 2024
    4a64968
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions