Index: include/llvm/Support/GenericDomTreeConstruction.h =================================================================== --- include/llvm/Support/GenericDomTreeConstruction.h +++ include/llvm/Support/GenericDomTreeConstruction.h @@ -1297,9 +1297,12 @@ errs().flush(); return false; } + + return true; } - RootsT ComputedRoots = FindRoots(DT, nullptr); + // Check PostDomTree roots. + const RootsT ComputedRoots = FindRoots(DT, nullptr); if (DT.Roots.size() != ComputedRoots.size() || !std::is_permutation(DT.Roots.begin(), DT.Roots.end(), ComputedRoots.begin())) { @@ -1314,6 +1317,21 @@ return false; } + for (const NodePtr Root : ComputedRoots) { + const TreeNodePtr TN = DT.getNode(Root); + if (!TN) { + errs() << "Computed root: " << BlockNamePrinter(Root) + << " not found in the PostDomTree!\n"; + return false; + } + + if (!DT.isVirtualRoot(TN->getIDom())) { + errs() << "Computed root: " << BlockNamePrinter(TN) + << " is not connected to the virtual root!\n"; + return false; + } + } + return true; }