fix PR6858: a dangling pointer use bug which was caused
authorChris Lattner <sabre@nondot.org>
Sat, 17 Apr 2010 17:57:56 +0000 (17:57 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 17 Apr 2010 17:57:56 +0000 (17:57 +0000)
by switching CachedFunctionInfo from a std::map to a
ValueMap (which is implemented in terms of a DenseMap).

DenseMap has different iterator invalidation semantics
than std::map.

This should hopefully fix the dragonegg builder.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101658 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/InlineCost.cpp

index acc3f202f2795720c9df60f70c477ec56261f3c5..50400d3085d91514099b239b4f8257ff8022d86c 100644 (file)
@@ -319,8 +319,13 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS,
     FunctionInfo &CallerFI = CachedFunctionInfo[Caller];
 
     // If we haven't calculated this information yet, do so now.
-    if (CallerFI.Metrics.NumBlocks == 0)
+    if (CallerFI.Metrics.NumBlocks == 0) {
       CallerFI.analyzeFunction(Caller);
+     
+      // Recompute the CalleeFI pointer, getting Caller could have invalidated
+      // it.
+      CalleeFI = &CachedFunctionInfo[Callee];
+    }
 
     // Don't inline a callee with dynamic alloca into a caller without them.
     // Functions containing dynamic alloca's are inefficient in various ways;
@@ -426,6 +431,8 @@ InlineCostAnalyzer::growCachedCostInfo(Function *Caller, Function *Callee) {
     return;
   }
   
+  // Since CalleeMetrics were already calculated, we know that the CallerMetrics
+  // reference isn't invalidated: both were in the DenseMap.  
   CallerMetrics.NeverInline |= CalleeMetrics.NeverInline;
   CallerMetrics.usesDynamicAlloca |= CalleeMetrics.usesDynamicAlloca;