aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Greif <ggreif@gmail.com>2009-01-15 18:40:09 +0000
committerGabor Greif <ggreif@gmail.com>2009-01-15 18:40:09 +0000
commitc478e52bf4c12691037856ee103c66946afeab6c (patch)
tree390f34dc462e076fd490fd37128ba85a6fb0fe94
parent0e5200f3fd4c884e41f003cd57e75f6aca625cbd (diff)
downloadexternal_llvm-c478e52bf4c12691037856ee103c66946afeab6c.zip
external_llvm-c478e52bf4c12691037856ee103c66946afeab6c.tar.gz
external_llvm-c478e52bf4c12691037856ee103c66946afeab6c.tar.bz2
avoid using iterators when they get invalidated potentially
this fixes PR3332 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62271 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Utils/InlineFunction.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp
index 0b1105e..63b5f54 100644
--- a/lib/Transforms/Utils/InlineFunction.cpp
+++ b/lib/Transforms/Utils/InlineFunction.cpp
@@ -155,8 +155,18 @@ static void UpdateCallGraphAfterInlining(CallSite CS,
// Since we inlined some uninlined call sites in the callee into the caller,
// add edges from the caller to all of the callees of the callee.
- for (CallGraphNode::iterator I = CalleeNode->begin(),
- E = CalleeNode->end(); I != E; ++I) {
+ CallGraphNode::iterator I = CalleeNode->begin(), E = CalleeNode->end();
+
+ // Consider the case where CalleeNode == CallerNode.
+ typedef std::pair<CallSite, CallGraphNode*> CallRecord;
+ std::vector<CallRecord> CallCache;
+ if (CalleeNode == CallerNode) {
+ CallCache.assign(I, E);
+ I = CallCache.begin();
+ E = CallCache.end();
+ }
+
+ for (; I != E; ++I) {
const Instruction *OrigCall = I->first.getInstruction();
DenseMap<const Value*, Value*>::iterator VMI = ValueMap.find(OrigCall);
@@ -514,8 +524,8 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
TheCall->replaceAllUsesWith(PHI);
}
- // Loop over all of the return instructions adding entries to the PHI node as
- // appropriate.
+ // Loop over all of the return instructions adding entries to the PHI node
+ // as appropriate.
if (PHI) {
for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
ReturnInst *RI = Returns[i];