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

Panic on a valid go1.17 program with default configuration #2292

Closed
4 tasks done
tie opened this issue Oct 13, 2021 · 8 comments
Closed
4 tasks done

Panic on a valid go1.17 program with default configuration #2292

tie opened this issue Oct 13, 2021 · 8 comments
Assignees
Labels
bug Something isn't working dependencies Relates to an upstream dependency

Comments

@tie
Copy link

tie commented Oct 13, 2021

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

Running golangci-lint run panics on a valid Go 1.17 program.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version v1.42.1 built from (unknown, mod sum: "h1:nC4WyrbdnNdohDVUoNKjy/4N4FTM1gCFaVeXecy6vzM=") on (unknown)

Configuration file

$ cat .golangci.yml
cat: .golangci.yml: No such file or directory

Go environment

$ go version && go env
go version go1.17.1 linux/amd64
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tie/.cache/go-build"
GOENV="/home/tie/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS="-trimpath"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/tie/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/tie/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/tie/sdk/go1.17.1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/tie/sdk/go1.17.1/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.1"
GCCGO="gccgo"
AR="gcc-ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
GOMOD="/home/tie/golangci-bug/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3876884584=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/tie/golangci-bug /home/tie /home /] 
INFO [lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck] 
INFO [loader] Go packages loading at mode 575 (types_sizes|deps|files|name|compiled_files|exports_file|imports) took 216.976234ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 675.357s 
INFO [linters context/goanalysis] analyzers took 8.782652969s with top 10 stages: buildir: 6.551375469s, inspect: 791.306542ms, ctrlflow: 328.862777ms, fact_deprecated: 256.954428ms, printf: 247.996752ms, SA5012: 176.742246ms, fact_purity: 164.969088ms, nilness: 140.291993ms, typedness: 121.880695ms, SA4008: 338.082s 
ERRO [runner] Panic: buildir: package "bug" (isInitialPkg: true, needAnalyzeSource: true): in bug.SecretFromBytes: cannot convert Load <[]byte> t0 ([]byte) to *bug.Secret: goroutine 2036 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x65
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
        github.com/golangci/golangci-lint@v1.42.1/pkg/golinters/goanalysis/runner_action.go:101 +0x155
panic({0xdd1c80, 0xc0090b0e40})
        runtime/panic.go:1038 +0x215
honnef.co/go/tools/go/ir.emitConv(0xc004892900, {0x114e028, 0xc004327440}, {0x1129798, 0xc00b65a340}, {0x1128d70, 0xc00274f080})
        honnef.co/go/tools@v0.2.1/go/ir/emit.go:261 +0xb25
honnef.co/go/tools/go/ir.(*builder).expr0(0xc0058e7a40, 0xc004892900, {0x112c130, 0xc00274f080}, {0x7, {0x1129798, 0xc00b65a340}, {0x0, 0x0}})
        honnef.co/go/tools@v0.2.1/go/ir/builder.go:544 +0xa77
honnef.co/go/tools/go/ir.(*builder).expr(0xc004892900, 0xc004892900, {0x112c130, 0xc00274f080})
        honnef.co/go/tools@v0.2.1/go/ir/builder.go:500 +0x1db
honnef.co/go/tools/go/ir.(*builder).stmt(0xed5700, 0xc004892900, {0x112c640, 0xc0028421a0})
        honnef.co/go/tools@v0.2.1/go/ir/builder.go:2142 +0x1ab8
honnef.co/go/tools/go/ir.(*builder).stmtList(0x4, 0xc004327080, {0xc0028421c0, 0x2, 0x20})
        honnef.co/go/tools@v0.2.1/go/ir/builder.go:752 +0x67
honnef.co/go/tools/go/ir.(*builder).stmt(0xc004892900, 0xc004892900, {0x112c0d0, 0xc0015782d0})
        honnef.co/go/tools@v0.2.1/go/ir/builder.go:2189 +0xd05
honnef.co/go/tools/go/ir.(*builder).buildFunction(0xc0058e7a40, 0xc004892900)
        honnef.co/go/tools@v0.2.1/go/ir/builder.go:2301 +0x44a
honnef.co/go/tools/go/ir.(*builder).buildFuncDecl(0xc0048e7ea0, 0xc0048a4000, 0xc001578300)
        honnef.co/go/tools@v0.2.1/go/ir/builder.go:2339 +0x195
honnef.co/go/tools/go/ir.(*Package).build(0xc0048a4000)
        honnef.co/go/tools@v0.2.1/go/ir/builder.go:2445 +0xc52
sync.(*Once).doSlow(0xc000179080, 0xc001ddf180)
        sync/once.go:68 +0xd2
sync.(*Once).Do(...)
        sync/once.go:59
honnef.co/go/tools/go/ir.(*Package).Build(...)
        honnef.co/go/tools@v0.2.1/go/ir/builder.go:2363
honnef.co/go/tools/internal/passes/buildir.run(0xc001634ea0)
        honnef.co/go/tools@v0.2.1/internal/passes/buildir/buildir.go:86 +0x308
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc0008d0cf0)
        github.com/golangci/golangci-lint@v1.42.1/pkg/golinters/goanalysis/runner_action.go:187 +0x9c4
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        github.com/golangci/golangci-lint@v1.42.1/pkg/golinters/goanalysis/runner_action.go:105 +0x1d
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc00018c6e0, {0xf25771, 0x7}, 0xc0010f3f60)
        github.com/golangci/golangci-lint@v1.42.1/pkg/timeutils/stopwatch.go:111 +0x4a
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc0008d0cf0)
        github.com/golangci/golangci-lint@v1.42.1/pkg/golinters/goanalysis/runner_action.go:104 +0x85
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x203d3d2062206669)
        github.com/golangci/golangci-lint@v1.42.1/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0x67
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
        github.com/golangci/golangci-lint@v1.42.1/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x1fd 
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: buildir: package "bug" (isInitialPkg: true, needAnalyzeSource: true): in bug.SecretFromBytes: cannot convert Load <[]byte> t0 ([]byte) to *bug.Secret 
INFO [runner] processing took 4.08 with stages: max_same_issues: 1.597s, path_shortener: 397ns, skip_dirs: 356ns, max_from_linter: 281ns, nolint: 263ns, skip_files: 170ns, cgo: 113ns, filename_unadjuster: 110ns, path_prettifier: 106ns, autogenerated_exclude: 103ns, source_code: 102ns, uniq_by_line: 101ns, identifier_marker: 100ns, exclude: 49ns, sort_results: 43ns, severity-rules: 40ns, exclude-rules: 40ns, path_prefixer: 39ns, diff: 38ns, max_per_file_from_linter: 37ns 
INFO [runner] linters took 6.142474954s with stages: goanalysis_metalinter: 6.074989017s 
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 65 samples, avg is 176.7MB, max is 258.5MB 
INFO Execution took 6.384884692s                  

Code example or link to a public repository

go.mod
module bug

go 1.17

require github.com/stretchr/testify v1.7.0

require (
        github.com/davecgh/go-spew v1.1.0 // indirect
        github.com/pmezard/go-difflib v1.0.0 // indirect
        gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
go.sum
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
bug.go
package bug

type Secret [32]byte

func SecretFromBytes(buf []byte) (*Secret, bool) {
        if len(buf) != len(Secret{}) {
                return nil, false
        }
        return (*Secret)(buf), true
}
bug_test.go
package bug

import (
        "testing"

        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/require"
)

func TestSecretFromBytes(t *testing.T) {
        testCases := []struct {
                Bytes   []byte
                Secret  *Secret
                Success bool
        }{
                {
                        Bytes:   nil,
                        Secret:  nil,
                        Success: false,
                },
                {
                        Bytes:   make([]byte, len(Secret{})),
                        Secret:  &Secret{},
                        Success: true,
                },
                {
                        Bytes:   make([]byte, len(Secret{})-1),
                        Secret:  nil,
                        Success: false,
                },
                {
                        Bytes:   make([]byte, len(Secret{})+1),
                        Secret:  nil,
                        Success: false,
                },
        }
        for _, tc := range testCases {
                secret, ok := SecretFromBytes(tc.Bytes)
                if tc.Success {
                        require.True(t, ok)
                } else {
                        require.False(t, ok)
                }
                assert.Equal(t, tc.Secret, secret)
        }
}
@tie tie added the bug Something isn't working label Oct 13, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 13, 2021

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@tie
Copy link
Author

tie commented Oct 13, 2021

FWIW staticcheck panics with similar stack trace, so I’d assume that it’s caused by some shared tooling since golangci-lint panics even with staticcheck disabled.

linters:
  disable:
    - staticcheck

@tie
Copy link
Author

tie commented Oct 13, 2021

I can also reproduce this with the latest commit.

golangci-lint has version v1.42.2-0.20211012001543-680f3e6c8ec7 built from (unknown, mod sum: "h1:xToCTAGNexlfjCEEnOu6dXCV76GNWiSGr+jpYJFOp4Y=") on (unknown)

@ldez ldez self-assigned this Oct 13, 2021
@ldez
Copy link
Member

ldez commented Oct 28, 2021

bug.go
package bug

import "sync/atomic"

type Secret [32]byte

func SecretFromBytes(buf []byte) (*Secret, bool) {
	if len(buf) != len(Secret{}) {
		return nil, false
	}
	return (*Secret)(buf), true
}

func foo() {
	_ = atomic.Value{}
}
.golangci.yml
linters:
  enable-all: true
  disable:
    - staticcheck
    - stylecheck
    - gosimple
    - unused
go.mod
module github.com/golangci/sandbox

go 1.17

require github.com/stretchr/testify v1.7.0

require (
	github.com/davecgh/go-spew v1.1.0 // indirect
	github.com/pmezard/go-difflib v1.0.0 // indirect
	gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
run with a build of the current HEAD of golangci-lint (go1.17.2)
$ ./golangci-lint run
WARN [runner] The linter 'golint' is deprecated (since v1.41.0) due to: The repository of the linter has been archived by the owner.  Replaced by revive. 
WARN [runner] The linter 'interfacer' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner.  
WARN [runner] The linter 'maligned' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner.  Replaced by govet 'fieldalignment'. 
WARN [runner] The linter 'scopelint' is deprecated (since v1.39.0) due to: The repository of the linter has been deprecated by the owner.  Replaced by exportloopref. 
bug.go:14:6: `foo` is unused (deadcode)
func foo() {
     ^
bug.go:11:2: return statements should not be cuddled if block has more than two lines (wsl)
        return (*Secret)(buf), true
        ^
bug_test.go:44:3: expressions should not be cuddled with blocks (wsl)
                assert.Equal(t, tc.Secret, secret)
                ^
bug_test.go:10:1: Function TestSecretFromBytes missing the call to method parallel (paralleltest)
func TestSecretFromBytes(t *testing.T) {
^
bug_test.go:1:9: package should be `bug_test` instead of `bug` (testpackage)
package bug
        ^
bug_test.go:37:6: variable name 'tc' is too short for the scope of its usage (varnamelen)
        for _, tc := range testCases {
            ^
run with a build of the current HEAD of staticcheck (go1.17.2)
$ ./staticcheck .
panic: in github.com/golangci/sandbox.SecretFromBytes: cannot convert Load <[]byte> t0 ([]byte) to *github.com/golangci/sandbox.Secret

goroutine 165 [running]:
honnef.co/go/tools/go/ir.emitConv(0xc0008da480, {0x96b548, 0xc000561620}, {0x95c420, 0xc000620b40}, {0x95bb60, 0xc000286300})
        /home/ldez/sources/go/src/honnef.co/go/tools/go/ir/emit.go:261 +0xb25
honnef.co/go/tools/go/ir.(*builder).expr0(0xc0002e3b00, 0xc0008da480, {0x95d720, 0xc000286300}, {0x7, {0x95c420, 0xc000620b40}, {0x0, 0x0}})
        /home/ldez/sources/go/src/honnef.co/go/tools/go/ir/builder.go:544 +0xa77
honnef.co/go/tools/go/ir.(*builder).expr(0xc0008da480, 0xc0008da480, {0x95d720, 0xc000286300})
        /home/ldez/sources/go/src/honnef.co/go/tools/go/ir/builder.go:500 +0x1db
honnef.co/go/tools/go/ir.(*builder).stmt(0x889c40, 0xc0008da480, {0x95dc30, 0xc0006be360})
        /home/ldez/sources/go/src/honnef.co/go/tools/go/ir/builder.go:2142 +0x1ab8
honnef.co/go/tools/go/ir.(*builder).stmtList(0x4, 0xc0005612c0, {0xc0006be380, 0x2, 0x20})
        /home/ldez/sources/go/src/honnef.co/go/tools/go/ir/builder.go:752 +0x67
honnef.co/go/tools/go/ir.(*builder).stmt(0xc0008da480, 0xc0008da480, {0x95d6c0, 0xc00039a630})
        /home/ldez/sources/go/src/honnef.co/go/tools/go/ir/builder.go:2189 +0xd05
honnef.co/go/tools/go/ir.(*builder).buildFunction(0xc0008e7b00, 0xc0008da480)
        /home/ldez/sources/go/src/honnef.co/go/tools/go/ir/builder.go:2301 +0x44a
honnef.co/go/tools/go/ir.(*builder).buildFuncDecl(0xc0003982a0, 0xc0006863f0, 0xc00039a660)
        /home/ldez/sources/go/src/honnef.co/go/tools/go/ir/builder.go:2339 +0x195
honnef.co/go/tools/go/ir.(*Package).build(0xc0006863f0)
        /home/ldez/sources/go/src/honnef.co/go/tools/go/ir/builder.go:2445 +0xc52
sync.(*Once).doSlow(0xc00013a2c0, 0xc0006baa00)
        /home/ldez/.gvm/gos/go1.17.2/src/sync/once.go:68 +0xd2
sync.(*Once).Do(...)
        /home/ldez/.gvm/gos/go1.17.2/src/sync/once.go:59
honnef.co/go/tools/go/ir.(*Package).Build(...)
        /home/ldez/sources/go/src/honnef.co/go/tools/go/ir/builder.go:2363
honnef.co/go/tools/internal/passes/buildir.run(0xc00011cdd0)
        /home/ldez/sources/go/src/honnef.co/go/tools/internal/passes/buildir/buildir.go:86 +0x308
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc0006e07e0, {0x965bf8, 0xc000156960})
        /home/ldez/sources/go/src/honnef.co/go/tools/lintcmd/runner/runner.go:937 +0x614
honnef.co/go/tools/lintcmd/runner.genericHandle({0x965bf8, 0xc000156960}, {0x965bf8, 0xc0001560a0}, 0x0, 0xc0003880b8, 0xc000621d50)
        /home/ldez/sources/go/src/honnef.co/go/tools/lintcmd/runner/runner.go:762 +0x102
created by honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers
        /home/ldez/sources/go/src/honnef.co/go/tools/lintcmd/runner/runner.go:1003 +0x725

staticcheck is a binary and a set of rules, those rules are grouped in "category": staticcheck, gosimple, stylecheck and unused.

The problem comes from staticcheck itself, so an issue must open of the staticcheck repo. Maybe @dominikh already has a fix.

@ldez ldez added the dependencies Relates to an upstream dependency label Oct 28, 2021
@dominikh
Copy link

No, this is not yet fixed. However, I can see why it happens, and an outstanding PR (dominikh/go-tools#1081) contains a fix for it. Fix incoming soon.

@dominikh
Copy link

This should be fixed on master now. I'll publish a new patch release on Monday.

@dominikh
Copy link

https://github.com/dominikh/go-tools/releases/tag/2021.1.2

@ldez
Copy link
Member

ldez commented Nov 23, 2021

Closed by #2370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Relates to an upstream dependency
Projects
None yet
Development

No branches or pull requests

3 participants