From 04d64487f92bfbb65df731a972f4702d1b9379a0 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Tue, 6 Dec 2016 10:29:23 +0000 Subject: [PATCH] [LCG] Add some much needed asserts and verify runs to uncover a hilarious bug and fix it. We somehow were never verifying the RefSCCs newly formed when splitting an existing one apart, and when verifying them we weren't really checking the SCC indices mapping effectively. If we had been, it would have been blindingly obvious that right after putting something int `RC.SCCs` we should update `RC.SCCIndices` instead of `SCCIndices` which we were about to clear and rebuild anyways. =[ Anyways, this is thoroughly covered by existing tests now that we actually verify things properly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288795 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/LazyCallGraph.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Analysis/LazyCallGraph.cpp b/lib/Analysis/LazyCallGraph.cpp index fe635c4e366..d1689377ac6 100644 --- a/lib/Analysis/LazyCallGraph.cpp +++ b/lib/Analysis/LazyCallGraph.cpp @@ -258,6 +258,9 @@ void LazyCallGraph::RefSCC::verify() { "SCC doesn't think it is inside this RefSCC!"); bool Inserted = SCCSet.insert(C).second; assert(Inserted && "Found a duplicate SCC!"); + auto IndexIt = SCCIndices.find(C); + assert(IndexIt != SCCIndices.end() && + "Found an SCC that doesn't have an index!"); } // Check that our indices map correctly. @@ -1203,9 +1206,8 @@ LazyCallGraph::RefSCC::removeInternalRefEdge(Node &SourceN, Node &TargetN) { } // If this child isn't currently in this RefSCC, no need to process - // it. - // However, we do need to remove this RefSCC from its RefSCC's parent - // set. + // it. However, we do need to remove this RefSCC from its RefSCC's + // parent set. RefSCC &ChildRC = *G->lookupRefSCC(ChildN); ChildRC.Parents.erase(this); ++I; @@ -1305,7 +1307,7 @@ LazyCallGraph::RefSCC::removeInternalRefEdge(Node &SourceN, Node &TargetN) { RefSCC &RC = *Result[SCCNumber - 1]; int SCCIndex = RC.SCCs.size(); RC.SCCs.push_back(C); - SCCIndices[C] = SCCIndex; + RC.SCCIndices[C] = SCCIndex; C->OuterRefSCC = &RC; } @@ -1376,6 +1378,12 @@ LazyCallGraph::RefSCC::removeInternalRefEdge(Node &SourceN, Node &TargetN) { std::remove(G->LeafRefSCCs.begin(), G->LeafRefSCCs.end(), this), G->LeafRefSCCs.end()); +#ifndef NDEBUG + // Verify all of the new RefSCCs. + for (RefSCC *RC : Result) + RC->verify(); +#endif + // Return the new list of SCCs. return Result; } -- 2.50.1