<div dir="ltr">This is O(N), so you may want to do it only #ifndef NDEBUG</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 18, 2017 at 10:37 AM, Jakub Kuderski via Phabricator <span dir="ltr"><<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">kuhar created this revision.<br>
<br>
This patch improves error detection in deleteEdge. It asserts that the edge doesn't exist in the CFG and that DomTree knew about this edge before.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D35571" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D35571</a><br>
<br>
Files:<br>
include/llvm/Support/<wbr>GenericDomTreeConstruction.h<br>
<br>
<br>
Index: include/llvm/Support/<wbr>GenericDomTreeConstruction.h<br>
==============================<wbr>==============================<wbr>=======<br>
--- include/llvm/Support/<wbr>GenericDomTreeConstruction.h<br>
+++ include/llvm/Support/<wbr>GenericDomTreeConstruction.h<br>
@@ -569,11 +569,22 @@<br>
assert(From && To && "Cannot disconnect nullptrs");<br>
DEBUG(dbgs() << "Deleting edge " << BlockNamePrinter(From) << " -> "<br>
<< BlockNamePrinter(To) << "\n");<br>
+<br>
+ // Ensure that the edge was in fact deleted from the CFG before informing<br>
+ // the DomTree about it.<br>
+ auto IsSuccessor = [](const NodePtr SuccCandidate, const NodePtr Of) {<br>
+ auto Successors = ChildrenGetter<NodePtr, IsPostDom>::Get(Of);<br>
+ return llvm::find(Successors, SuccCandidate) != Successors.end();<br>
+ };<br>
+ (void)IsSuccessor;<br>
+ assert(!IsSuccessor(To, From) && "Deleted edge still exists in the CFG!");<br>
+<br>
const TreeNodePtr FromTN = DT.getNode(From);<br>
// Deletion in an unreachable subtree -- nothing to do.<br>
if (!FromTN) return;<br>
<br>
const TreeNodePtr ToTN = DT.getNode(To);<br>
+ assert(ToTN && "To already unreachable -- there is no edge to delete");<br>
const NodePtr NCDBlock = DT.findNearestCommonDominator(<wbr>From, To);<br>
const TreeNodePtr NCD = DT.getNode(NCDBlock);<br>
<br>
<br>
<br>
</blockquote></div><br></div>