1
0
mirror of https://github.com/golang/go synced 2024-11-18 18:04:46 -07:00

go.tool.pointer: fix regression in pointer.cgraph.Root().

The previous CL made the assumption that Root is the first
node, which is false for programs that import "reflect".
Reverted to the previous way: an explicit root field.

Added regression test (callgraph2) via oracle.

R=crawshaw
TBR=crawshaw
CC=golang-dev
https://golang.org/cl/13967043
This commit is contained in:
Alan Donovan 2013-09-26 09:31:39 -04:00
parent cb07517a77
commit d7287a0289
5 changed files with 34 additions and 3 deletions

View File

@ -200,6 +200,7 @@ func TestOracle(t *testing.T) {
for _, filename := range []string{
"testdata/src/main/calls.go",
"testdata/src/main/callgraph.go",
"testdata/src/main/callgraph2.go",
"testdata/src/main/describe.go",
"testdata/src/main/freevars.go",
"testdata/src/main/implements.go",

14
oracle/testdata/src/main/callgraph2.go vendored Normal file
View File

@ -0,0 +1,14 @@
package main
// Tests of call-graph queries.
// See go.tools/oracle/oracle_test.go for explanation.
// See callgraph2.golden for expected query results.
import _ "reflect"
func f() {}
func main() {
f()
}
// @callgraph callgraph "^"

View File

@ -0,0 +1,15 @@
-------- @callgraph callgraph --------
Below is a call graph of the entire program.
The numbered nodes form a spanning tree.
Non-numbered nodes indicate back- or cross-edges to the node whose
number follows in parentheses.
Some nodes may appear multiple times due to context-sensitive
treatment of some calls.
0 <root>
1 main.init
2 reflect.init
3 main.main
4 main.f

View File

@ -267,7 +267,7 @@ func Analyze(config *Config) *Result {
fmt.Fprintln(a.log, "======== NEW ANALYSIS ========")
}
a.generate()
root := a.generate()
//a.optimize()
@ -304,7 +304,7 @@ func Analyze(config *Config) *Result {
var callgraph *cgraph
if a.config.BuildCallGraph {
callgraph = &cgraph{a.cgnodes}
callgraph = &cgraph{root, a.cgnodes}
}
return &Result{

View File

@ -16,6 +16,7 @@ import (
// cgraph implements call.Graph.
type cgraph struct {
root *cgnode
nodes []*cgnode
}
@ -28,7 +29,7 @@ func (g *cgraph) Nodes() []call.GraphNode {
}
func (g *cgraph) Root() call.GraphNode {
return g.nodes[0]
return g.root
}
// cgnode implements call.GraphNode.