[PATCH] D35571: [Dominators] Improve error checking in deleteEdge

Jakub Kuderski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 18 13:20:49 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL308354: [Dominators] Improve error checking in deleteEdge (authored by kuhar).

Changed prior to commit:
  https://reviews.llvm.org/D35571?vs=107141&id=107167#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35571

Files:
  llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h


Index: llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h
===================================================================
--- llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h
+++ llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h
@@ -569,11 +569,25 @@
     assert(From && To && "Cannot disconnect nullptrs");
     DEBUG(dbgs() << "Deleting edge " << BlockNamePrinter(From) << " -> "
                  << BlockNamePrinter(To) << "\n");
+
+#ifndef NDEBUG
+    // Ensure that the edge was in fact deleted from the CFG before informing
+    // the DomTree about it.
+    // The check is O(N), so run it only in debug configuration.
+    auto IsSuccessor = [](const NodePtr SuccCandidate, const NodePtr Of) {
+      auto Successors = ChildrenGetter<NodePtr, IsPostDom>::Get(Of);
+      return llvm::find(Successors, SuccCandidate) != Successors.end();
+    };
+    (void)IsSuccessor;
+    assert(!IsSuccessor(To, From) && "Deleted edge still exists in the CFG!");
+#endif
+
     const TreeNodePtr FromTN = DT.getNode(From);
     // Deletion in an unreachable subtree -- nothing to do.
     if (!FromTN) return;
 
     const TreeNodePtr ToTN = DT.getNode(To);
+    assert(ToTN && "To already unreachable -- there is no edge to delete");
     const NodePtr NCDBlock = DT.findNearestCommonDominator(From, To);
     const TreeNodePtr NCD = DT.getNode(NCDBlock);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35571.107167.patch
Type: text/x-patch
Size: 1391 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170718/eb685339/attachment.bin>


More information about the llvm-commits mailing list