Skip to content

Commit

Permalink
graph/cfg: fix panic in Dominates
Browse files Browse the repository at this point in the history
DominatorOf returns nil for the root node. With the previous version
of the gonum/graph API this was fine, but with the new version
(using ID) we must first ensure that the dominator of B is not nil
before invoking the ID method.
  • Loading branch information
mewmew committed Oct 30, 2019
1 parent f5e2ba8 commit de6e23e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion graph/cfg/dom.go
Expand Up @@ -20,5 +20,10 @@ func NewDom(g graph.Directed, entry graph.Node) DominatorTree {

// Dominates reports whether A dominates B.
func (dt DominatorTree) Dominates(a, b graph.Node) bool {
return a.ID() == dt.DominatorTree.DominatorOf(b.ID()).ID()
bDom := dt.DominatorTree.DominatorOf(b.ID())
if bDom == nil {
// B is root node, thus not dominated by A.
return false
}
return a.ID() == bDom.ID()
}

0 comments on commit de6e23e

Please sign in to comment.