Skip to content

Commit 1065f34

Browse files
committed
[DomTree] findNearestCommonDominator: assert the nodes are in tree
i.e. they cannot be unreachable from the entry (which usually indicate usage errors). This change allows the removal of some nullptr checks. Reviewed By: kuhar Differential Revision: https://reviews.llvm.org/D88758
1 parent 952dfd7 commit 1065f34

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

llvm/include/llvm/Support/GenericDomTree.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ class DominatorTreeBase {
463463
return this->Roots[0];
464464
}
465465

466-
/// findNearestCommonDominator - Find nearest common dominator basic block
467-
/// for basic block A and B. If there is no such block then return nullptr.
466+
/// Find nearest common dominator basic block for basic block A and B. A and B
467+
/// must have tree nodes.
468468
NodeT *findNearestCommonDominator(NodeT *A, NodeT *B) const {
469469
assert(A && B && "Pointers are not valid");
470470
assert(A->getParent() == B->getParent() &&
@@ -480,18 +480,18 @@ class DominatorTreeBase {
480480

481481
DomTreeNodeBase<NodeT> *NodeA = getNode(A);
482482
DomTreeNodeBase<NodeT> *NodeB = getNode(B);
483-
484-
if (!NodeA || !NodeB) return nullptr;
483+
assert(NodeA && "A must be in the tree");
484+
assert(NodeB && "B must be in the tree");
485485

486486
// Use level information to go up the tree until the levels match. Then
487487
// continue going up til we arrive at the same node.
488-
while (NodeA && NodeA != NodeB) {
488+
while (NodeA != NodeB) {
489489
if (NodeA->getLevel() < NodeB->getLevel()) std::swap(NodeA, NodeB);
490490

491491
NodeA = NodeA->IDom;
492492
}
493493

494-
return NodeA ? NodeA->getBlock() : nullptr;
494+
return NodeA->getBlock();
495495
}
496496

497497
const NodeT *findNearestCommonDominator(const NodeT *A,

0 commit comments

Comments
 (0)