func findCallees(conf *pointer.Config, site ssa.CallInstruction) ([]*ssa.Function, error) { // Avoid running the pointer analysis for static calls. if callee := site.Common().StaticCallee(); callee != nil { switch callee.String() { case "runtime.SetFinalizer", "(reflect.Value).Call": // The PTA treats calls to these intrinsics as dynamic. // TODO(adonovan): avoid reliance on PTA internals. default: return []*ssa.Function{callee}, nil // singleton } } // Dynamic call: use pointer analysis. conf.BuildCallGraph = true cg := ptrAnalysis(conf).CallGraph cg.DeleteSyntheticNodes() // Find all call edges from the site. n := cg.Nodes[site.Parent()] if n == nil { return nil, fmt.Errorf("this call site is unreachable in this analysis") } calleesMap := make(map[*ssa.Function]bool) for _, edge := range n.Out { if edge.Site == site { calleesMap[edge.Callee.Func] = true } } // De-duplicate and sort. funcs := make([]*ssa.Function, 0, len(calleesMap)) for f := range calleesMap { funcs = append(funcs, f) } sort.Sort(byFuncPos(funcs)) return funcs, nil }