Skip to content

Commit 9551398

Browse files
zpavlinovicgopherbot
authored andcommitted
go/callgraph: keep instantiations in DeleteSyntheticNodes
DeleteSyntheticNodes currently removes instantiations of generics from the call graph. This function is intended to remove synthetic functions that don't have a counterpart in the source code. Instantiations of generics do not fit that bill. This also caused problems in govulncheck where a function call to instantiation was missing from a call stack. The fix is to keep instantiations and improved the documentation of DeleteSyntheticNodes. Change-Id: I32392b7495a8c1a5f6b26f795d46c8f184983e67 Reviewed-on: https://go-review.googlesource.com/c/tools/+/575095 Reviewed-by: Alan Donovan <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Zvonimir Pavlinovic <[email protected]> Auto-Submit: Zvonimir Pavlinovic <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 11b4b5e commit 9551398

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

go/callgraph/util.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ func PathSearch(start *Node, isEnd func(*Node) bool) []*Edge {
7676
}
7777

7878
// DeleteSyntheticNodes removes from call graph g all nodes for
79-
// synthetic functions (except g.Root and package initializers),
80-
// preserving the topology. In effect, calls to synthetic wrappers
81-
// are "inlined".
79+
// functions that do not correspond to source syntax. For historical
80+
// reasons, nodes for g.Root and package initializers are always
81+
// kept.
82+
//
83+
// As nodes are removed, edges are created to preserve the
84+
// reachability relation of the remaining nodes.
8285
func (g *Graph) DeleteSyntheticNodes() {
8386
// Measurements on the standard library and go.tools show that
8487
// resulting graph has ~15% fewer nodes and 4-8% fewer edges
@@ -99,7 +102,7 @@ func (g *Graph) DeleteSyntheticNodes() {
99102
}
100103
}
101104
for fn, cgn := range g.Nodes {
102-
if cgn == g.Root || fn.Synthetic == "" || isInit(cgn.Func) {
105+
if cgn == g.Root || isInit(cgn.Func) || fn.Syntax() != nil {
103106
continue // keep
104107
}
105108
for _, eIn := range cgn.In {

0 commit comments

Comments
 (0)