From 26f67b5a279f47178b8ba4b507da3d75d8b124a5 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Fri, 27 Feb 2015 02:19:11 +0000 Subject: [PATCH] Fix a use-iterator-after-invalidate error AnalysisResult::getResultImpl reuses an iterator into a DenseMap after inserting elements into it. This change adds code to recompute the iterator before the second use. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230718 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/PassManager.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/llvm/IR/PassManager.h b/include/llvm/IR/PassManager.h index c92e7c91994..513bbe01da0 100644 --- a/include/llvm/IR/PassManager.h +++ b/include/llvm/IR/PassManager.h @@ -471,6 +471,12 @@ private: dbgs() << "Running analysis: " << P.name() << "\n"; AnalysisResultListT &ResultList = AnalysisResultLists[&IR]; ResultList.emplace_back(PassID, P.run(IR, this)); + + // P.run may have inserted elements into AnalysisResults and invalidated + // RI. + RI = AnalysisResults.find(std::make_pair(PassID, &IR)); + assert(RI != AnalysisResults.end() && "we just inserted it!"); + RI->second = std::prev(ResultList.end()); } -- 2.34.1