[PATCH] Fix a use-iterator-after-invalidate error

Sanjoy Das sanjoy at playingwithpointers.com
Thu Feb 26 15:44:54 PST 2015


Hi chandlerc,

As far as I can tell, AnalysysResult::getResultImpl reuses an iterator into a `DenseMap` after inserting elements into it.  This change recomputes the iterator before the second use.

(caveat:  I'm not familiar with this bit of code, so it possible that I'm misreading it)

http://reviews.llvm.org/D7921

Files:
  include/llvm/IR/PassManager.h

Index: include/llvm/IR/PassManager.h
===================================================================
--- include/llvm/IR/PassManager.h
+++ include/llvm/IR/PassManager.h
@@ -471,6 +471,12 @@
         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());
     }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7921.20800.patch
Type: text/x-patch
Size: 668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150226/702c43f2/attachment.bin>


More information about the llvm-commits mailing list