[llvm] r250692 - [GlobalsAA] Fix a really horrible iterator invalidation bug

James Molloy via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 19 01:55:00 PDT 2015


Author: jamesm
Date: Mon Oct 19 03:54:59 2015
New Revision: 250692

URL: http://llvm.org/viewvc/llvm-project?rev=250692&view=rev
Log:
[GlobalsAA] Fix a really horrible iterator invalidation bug

We were keeping a reference to an object in a DenseMap then mutating it. At the end of the function we were attempting to clone that reference into other keys in the DenseMap, but DenseMap may well decide to resize its hashtable which would invalidate the reference!

It took an extremely complex testcase to catch this - many thanks to Zhendong Su for catching it in PR25225.

This fixes PR25225.

Modified:
    llvm/trunk/lib/Analysis/GlobalsModRef.cpp

Modified: llvm/trunk/lib/Analysis/GlobalsModRef.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/GlobalsModRef.cpp?rev=250692&r1=250691&r2=250692&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/GlobalsModRef.cpp (original)
+++ llvm/trunk/lib/Analysis/GlobalsModRef.cpp Mon Oct 19 03:54:59 2015
@@ -587,8 +587,11 @@ void GlobalsAAResult::AnalyzeCallGraph(C
 
     // Finally, now that we know the full effect on this SCC, clone the
     // information to each function in the SCC.
+    // FI is a reference into FunctionInfos, so copy it now so that it doesn't
+    // get invalidated if DenseMap decides to re-hash.
+    FunctionInfo CachedFI = FI;
     for (unsigned i = 1, e = SCC.size(); i != e; ++i)
-      FunctionInfos[SCC[i]->getFunction()] = FI;
+      FunctionInfos[SCC[i]->getFunction()] = CachedFI;
   }
 }
 




More information about the llvm-commits mailing list