staticcheck: use call graph to detect infinite recursion
@@ -2334,22 +2334,15 @@ func (c *Checker) CheckNaNComparison(f *lint.File) {
func (c *Checker) CheckInfiniteRecursion(f *lint.File) {
for _, ssafn := range c.funcsForFile(f) {
- for _, block := range ssafn.Blocks {
- for _, ins := range block.Instrs {
- call, ok := ins.(*ssa.Call)
- if !ok {
- continue
- }
- if call.Common().IsInvoke() {
- continue
- }
- subfn, ok := call.Common().Value.(*ssa.Function)
- if !ok || subfn != ssafn {
+ node := c.CallGraph.CreateNode(ssafn)
+ for _, edge := range node.Out {
+ if edge.Callee != node {
continue
}
+ block := edge.Site.Block()
canReturn := false
- for _, b := range subfn.Blocks {
+ for _, b := range ssafn.Blocks {
if block.Dominates(b) {
continue
}
@@ -2364,8 +2357,7 @@ func (c *Checker) CheckInfiniteRecursion(f *lint.File) {
if canReturn {
continue
}
- f.Errorf(call, "infinite recursive call")
- }
+ f.Errorf(edge.Site, "infinite recursive call")
}
}
}
