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 error (panic) in pointer analysis - not a tagged object #43104

Closed
zyq823 opened this issue Dec 9, 2020 · 6 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) FrozenDueToAge 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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@zyq823
Copy link

zyq823 commented Dec 9, 2020

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

$ go version 

go1.15.2 linux/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xxx/.cache/go-build"
GOENV="/home/xxx/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/xxx/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/xxx/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,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="/home/xxx/Downloads/research/xx/istio/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-build086903914=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Running a go analyzer I wrote that incorporates the pointer package, on the istio codebase

What did you expect to see?

Error-free analysis that utilizes Go's pointer analysis package.

What did you see instead?

A panic error in the pointer analysis package was triggered. As shown below,

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(0xc1fad78658)
/home/xxx/go/pkg/mod/golang.org/x/tools@v0.0.0-20200806022845-90696ccdc692/go/pointer/analysis.go:227 +0x10b
panic(0x6cc900, 0xc054a07080)
/usr/local/go/src/runtime/panic.go:969 +0x175
golang.org/x/tools/go/pointer.(*analysis).taggedValue(0xc0f5566a80, 0xc00009dacb, 0x4, 0x64, 0xc07c8d8700)
/home/xxx/go/pkg/mod/golang.org/x/tools@v0.0.0-20200806022845-90696ccdc692/go/pointer/gen.go:272 +0x105
golang.org/x/tools/go/pointer.(*typeFilterConstraint).solve(0xc0b7ae0940, 0xc0f5566a80, 0xc08e16d940)
/home/xxx/go/pkg/mod/golang.org/x/tools@v0.0.0-20200806022845-90696ccdc692/go/pointer/solve.go:273 +0xcc
golang.org/x/tools/go/pointer.(*analysis).solveConstraints(0xc0f5566a80, 0xc09b797620, 0xc08e16d940)
/home/xxx/go/pkg/mod/golang.org/x/tools@v0.0.0-20200806022845-90696ccdc692/go/pointer/solve.go:165 +0x178
golang.org/x/tools/go/pointer.(*analysis).solve(0xc0f5566a80)
/home/xxx/go/pkg/mod/golang.org/x/tools@v0.0.0-20200806022845-90696ccdc692/go/pointer/solve.go:59 +0x1ad
golang.org/x/tools/go/pointer.Analyze(0xc0f5a34a00, 0x0, 0x790a20, 0xc054a070b0)
/home/xxx/go/pkg/mod/golang.org/x/tools@v0.0.0-20200806022845-90696ccdc692/go/pointer/analysis.go:331 +0x4bc
main.(*analysis).pointerAnalysis(0xc000f42960, 0x798860, 0xc0eb11c660, 0x0, 0x797ea0, 0xc0eae465f0)
/home/xxx/Downloads/research/go2/race_checker/pointerAnalysis.go:25 +0x125
main.(*analysis).insMakeInterface(0xc000f42960, 0xc0eae465f0, 0x0, 0x797ea0, 0xc0eae465f0)
/home/xxx/Downloads/research/go2/race_checker/ssaInstructions.go:317 +0x1ac
main.(*analysis).visitAllInstructions(0xc000f42960, 0xc0786d5040, 0x0)
/home/xxx/Downloads/research/go2/race_checker/staticAnalysis.go:414 +0x1b1e
main.(*analysis).insCall(0xc000f42960, 0xc0931fb800, 0x0, 0x797240, 0xc0931fb800, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/home/xxx/Downloads/research/go2/race_checker/ssaInstructions.go:394 +0x452
main.(*analysis).visitAllInstructions(0xc000f42960, 0xc0786f3b80, 0x0)
/home/xxx/Downloads/research/go2/race_checker/staticAnalysis.go:416 +0x1da5
main.staticAnalysis(0xc0000ae030, 0x0, 0x0, 0x1, 0x0)
/home/xxx/Downloads/research/go2/race_checker/staticAnalysis.go:134 +0x99c
main.main()
/home/xxx/Downloads/research/go2/race_checker/main.go:150 +0x26d
FATA[13:01:11] internal error in pointer analysis: not a tagged object: n645835 (please report this bug)

@ianlancetaylor ianlancetaylor changed the title Internal error (panic) in pointer analysis - not a tagged object x/tools/go/pointer: internal error (panic) in pointer analysis - not a tagged object Dec 9, 2020
@ianlancetaylor
Copy link
Contributor

Can you show us how to recreate the problem ourselves? Thanks.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Dec 9, 2020
@gopherbot gopherbot added this to the Unreleased milestone Dec 9, 2020
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 9, 2020
@ianlancetaylor
Copy link
Contributor

CC @alandonovan @matloob

@zyq823
Copy link
Author

zyq823 commented Dec 10, 2020

Here is a synopsis of some code in my program that led to the panic. I was testing it on istio (upon building binary file in istio/istioctl/cmd/istioctl)

type pa struct {
	ptaConfig	*pointer.Config
}

func main() {
	flag.Parse()
	args := flag.Args()
	cfg := &packages.Config{
		Mode:  packages.LoadAllSyntax, 
		Dir:   "",     
		Tests: false,  
	}

	initial, _ := packages.Load(cfg, args...)
	prog, pkgs := ssautil.AllPackages(initial, 0)
	prog.Build()

	var mains []*ssa.Package
	for _, p := range pkgs {
		if p != nil && p.Pkg.Name() == "main" && p.Func("main") != nil {
			mains = append(mains, p)
		}
	}

	fn := mains[0].Func("main")
	config := &pointer.Config{
		Mains:	mains,
	}

	PTA := &pa {
		ptaConfig: config,
	}
	PTA.visitFn(fn)
}

func (p *pa) visitFn(fn *ssa.Function) {
	if fn != nil && (fn.Name() == "main" || fn.Name() == "ConfigAndEnvProcessing" || fn.Name() == "GetExitCode") {
		basicBlocks := fn.Blocks
		for k := 0; k < len(basicBlocks); k++ {
			b := basicBlocks[k]
			for _, i := range b.Instrs {
				switch ins := i.(type) {
				case *ssa.Call:
					p.visitFn(ins.Call.StaticCallee())
				case *ssa.MakeInterface:
					switch insT := ins.X.(type) {
					case *ssa.UnOp:
						if pointer.CanPoint(ins.X.Type()) {
							p.ptaConfig.AddQuery(ins.X)
						}
						if _, ok := insT.X.(*ssa.Global); !ok {
							result, _ := pointer.Analyze(p.ptaConfig)
							_ = result
						}
					}
				default:
					continue
				}
			}
		}
	}
}

@MyLGG
Copy link

MyLGG commented Jun 27, 2021

anybody else can solve this problem now? I also meet the same problem when use x/tools/go/pointer

@zpavlinovic
Copy link
Contributor

The information here is helpful, but I wonder if we can get a minimal reproducible example. @MyLGG, do you perhaps have an example like that or the bug you are seeing also manifests on istio code base?

@zpavlinovic zpavlinovic added Analysis Issues related to static analysis (vet, x/tools/go/analysis) WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Sep 21, 2021
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Oct 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) FrozenDueToAge 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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants