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/pointer: internal panic in pointer analysis #41877

Open
goodmorning-coder opened this issue Oct 9, 2020 · 4 comments
Open

x/tools/go/pointer: internal panic in pointer analysis #41877

goodmorning-coder opened this issue Oct 9, 2020 · 4 comments

Comments

@goodmorning-coder
Copy link

@goodmorning-coder goodmorning-coder commented Oct 9, 2020

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

$ go version
go version go1.15.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/Alice/.cache/go-build"
GOENV="/home/Alice/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/Alice/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/Alice/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build803063649=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I wrote a program

package main

import (
	"golang.org/x/tools/go/packages"
	"golang.org/x/tools/go/pointer"
	"golang.org/x/tools/go/ssa"
	"golang.org/x/tools/go/ssa/ssautil"
	"log"
	"strings"
)

func main() {
	cfg := &packages.Config{Mode: packages.LoadAllSyntax, Tests: true}
	initial, err := packages.Load(cfg, "/path/to/bug_test.go")
	if err != nil {
		log.Fatal(err)
	}

	if packages.PrintErrors(initial) > 0 {
		log.Fatalf("packages contain errors")
	}

	prog, pkgs := ssautil.Packages(initial, ssa.PrintPackages)
	_ = prog

	var mains []*ssa.Package

	for _, p := range pkgs {
		if p != nil {
			p.Build()
		}

		if strings.HasSuffix(p.Pkg.Path(), ".test") {
			mains = append(mains, p)
		}
	}

	config := &pointer.Config{
		Mains:           mains,
		BuildCallGraph:  true,
		Log: log.Writer(),
	}

	pointer.Analyze(config)
}

bug_test.go

package bug_test

import "testing"

func TestFunc(t *testing.T) {
}

What did you expect to see?

No panic

What did you see instead?

==== Generating constraints for cg3:(*reflect.rtype).Align, shared contour
Internal panic in pointer analysis:
goroutine 1 [running]:
runtime/debug.Stack(0x24, 0x0, 0x0)
        /usr/local/go/src/runtime/debug/stack.go:24 +0x9f
runtime/debug.PrintStack()
        /usr/local/go/src/runtime/debug/stack.go:16 +0x25
golang.org/x/tools/go/pointer.Analyze.func1(0xc002a1fe48)
        /home/Alice/go/src/golang.org/x/tools/go/pointer/analysis.go:227 +0x10b
panic(0x6d5080, 0xc004e5b540)
        /usr/local/go/src/runtime/panic.go:969 +0x175
golang.org/x/tools/go/ssa.writeSignature(0xc0052fca80, 0xc005544780, 0xc005797f99, 0x5, 0xc006496f90, 0x0, 0x0, 0x0)
        /home/Alice/go/src/golang.org/x/tools/go/ssa/func.go:522 +0x286
golang.org/x/tools/go/ssa.WriteFunction(0xc0052fca80, 0xc002a1f770)
        /home/Alice/go/src/golang.org/x/tools/go/ssa/func.go:585 +0x1c5
golang.org/x/tools/go/ssa.(*Function).WriteTo(0xc002a1f770, 0x74fd20, 0xc0000be010, 0x29, 0xc002a1f750, 0x2)
        /home/Alice/go/src/golang.org/x/tools/go/ssa/func.go:544 +0x4e
golang.org/x/tools/go/pointer.(*analysis).genFunc(0xc00109c1c0, 0xc001cfcfc0)
        /home/Alice/go/src/golang.org/x/tools/go/pointer/gen.go:1166 +0x919
golang.org/x/tools/go/pointer.(*analysis).generate(0xc00109c1c0)
        /home/Alice/go/src/golang.org/x/tools/go/pointer/gen.go:1305 +0x187
golang.org/x/tools/go/pointer.Analyze(0xc002a28aa0, 0x0, 0x74fbc0, 0xc001bb5150)
        /home/Alice/go/src/golang.org/x/tools/go/pointer/analysis.go:292 +0x478
main.main()
        /home/Alice/go/src/10.3.0.221/Alice/ryze/cmd/bug/main.go:44 +0x405
@ALTree ALTree changed the title golang.org/x/tools/go/ssa/func.go: Internal panic in pointer analysis x/tools/go/pointer: internal panic in pointer analysis Oct 9, 2020
@gopherbot gopherbot added the Tools label Oct 9, 2020
@gopherbot gopherbot added this to the Unreleased milestone Oct 9, 2020
@georgettica
Copy link

@georgettica georgettica commented Oct 10, 2020

I am taking a look at this
can you please assign me?

Loading

@georgettica
Copy link

@georgettica georgettica commented Oct 10, 2020

@goodmorning-coder , @ALTree this issue seems to be because the func being tested had zero args, writing PR now to add a nil check

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 10, 2020

Change https://golang.org/cl/260998 mentions this issue: tools: guard against nil params

Loading

@dmitshur
Copy link
Contributor

@dmitshur dmitshur commented Oct 13, 2020

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants