mirror of
https://github.com/golang/go
synced 2024-11-18 17:54:57 -07:00
go/pointer: fix crash: valueNode(*FreeVar) was allocating 1 node, even for multi-word types.
+ regression test. Fixes golang/go#8172 Also: return error (not panic) when called with empty input. LGTM=gri R=crawshaw, gri CC=golang-codereviews, jon https://golang.org/cl/104270043
This commit is contained in:
parent
5fe8afcb15
commit
5c5c4f4888
@ -212,6 +212,9 @@ func (a *analysis) computeTrackBits() {
|
||||
// always succeed. An error can occur only due to an internal bug.
|
||||
//
|
||||
func Analyze(config *Config) (result *Result, err error) {
|
||||
if config.Mains == nil {
|
||||
return nil, fmt.Errorf("no main/test packages to analyze (check $GOROOT/$GOPATH)")
|
||||
}
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
err = fmt.Errorf("internal error in pointer analysis: %v (please report this bug)", p)
|
||||
|
@ -226,7 +226,7 @@ func (a *analysis) valueNode(v ssa.Value) nodeid {
|
||||
if a.log != nil {
|
||||
comment = v.String()
|
||||
}
|
||||
id = a.addOneNode(v.Type(), comment, nil)
|
||||
id = a.addNodes(v.Type(), comment)
|
||||
if obj := a.objectNode(nil, v); obj != 0 {
|
||||
a.addressOf(v.Type(), id, obj)
|
||||
}
|
||||
|
34
go/pointer/testdata/func.go
vendored
34
go/pointer/testdata/func.go
vendored
@ -156,6 +156,39 @@ func func8(x ...int) {
|
||||
print(&x[0]) // @pointsto varargs[*]@varargs:15
|
||||
}
|
||||
|
||||
type E struct {
|
||||
x1, x2, x3, x4, x5 *int
|
||||
}
|
||||
|
||||
func (e E) f() {}
|
||||
|
||||
func func9() {
|
||||
// Regression test for bug reported by Jon Valdes on golang-dev, Jun 19 2014.
|
||||
// The receiver of a bound method closure may be of a multi-node type, E.
|
||||
// valueNode was reserving only a single node for it, so the
|
||||
// nodes used by the immediately following constraints
|
||||
// (e.g. param 'i') would get clobbered.
|
||||
|
||||
var e E
|
||||
e.x1 = &a
|
||||
e.x2 = &a
|
||||
e.x3 = &a
|
||||
e.x4 = &a
|
||||
e.x5 = &a
|
||||
|
||||
_ = e.f // form a closure---must reserve sizeof(E) nodes
|
||||
|
||||
func(i I) {
|
||||
i.f() // must not crash the solver
|
||||
}(new(D))
|
||||
|
||||
print(e.x1) // @pointsto main.a
|
||||
print(e.x2) // @pointsto main.a
|
||||
print(e.x3) // @pointsto main.a
|
||||
print(e.x4) // @pointsto main.a
|
||||
print(e.x5) // @pointsto main.a
|
||||
}
|
||||
|
||||
func main() {
|
||||
func1()
|
||||
func2()
|
||||
@ -165,6 +198,7 @@ func main() {
|
||||
func6()
|
||||
func7()
|
||||
func8(1, 2, 3) // @line varargs
|
||||
func9()
|
||||
}
|
||||
|
||||
// @calls <root> -> main.main
|
||||
|
Loading…
Reference in New Issue
Block a user