[StructurizeCfg] Update dominator info.
In some cases StructurizeCfg updates root node, but dominator info
remains unchanges, it causes crash when expensive checks are enabled.
To cope with this problem a new method was added to DominatorTreeBase
that allows adding new root nodes, it is called in StructurizeCfg to
put dominator tree in sync.
This change fixes PR27488.
Differential Revision: https://reviews.llvm.org/D28114
llvm-svn: 291530
diff --git a/llvm/unittests/IR/DominatorTreeTest.cpp b/llvm/unittests/IR/DominatorTreeTest.cpp
index 6c49deb..ae9c268 100644
--- a/llvm/unittests/IR/DominatorTreeTest.cpp
+++ b/llvm/unittests/IR/DominatorTreeTest.cpp
@@ -203,6 +203,16 @@
EXPECT_EQ(DT->getNode(BB4)->getDFSNumIn(), 5UL);
EXPECT_EQ(DT->getNode(BB4)->getDFSNumOut(), 6UL);
+ // Change root node
+ DT->verifyDomTree();
+ BasicBlock *NewEntry = BasicBlock::Create(F.getContext(), "new_entry",
+ &F, BB0);
+ BranchInst::Create(BB0, NewEntry);
+ EXPECT_EQ(F.begin()->getName(), NewEntry->getName());
+ EXPECT_TRUE(&F.getEntryBlock() == NewEntry);
+ DT->setNewRoot(NewEntry);
+ DT->verifyDomTree();
+
return false;
}
void getAnalysisUsage(AnalysisUsage &AU) const override {