diff options
| author | Gabor Greif <ggreif@gmail.com> | 2009-01-15 18:40:09 +0000 | 
|---|---|---|
| committer | Gabor Greif <ggreif@gmail.com> | 2009-01-15 18:40:09 +0000 | 
| commit | 5aa1922614648592a7f605f27af541411ae9d84c (patch) | |
| tree | f619bb8de65f4b0532cf986eb49949154f8e38cd /llvm/lib/Transforms/Utils | |
| parent | 435bbe0254871a7f55acbf0b3f0c3a4867b51acc (diff) | |
| download | bcm5719-llvm-5aa1922614648592a7f605f27af541411ae9d84c.tar.gz bcm5719-llvm-5aa1922614648592a7f605f27af541411ae9d84c.zip | |
avoid using iterators when they get invalidated potentially
this fixes PR3332
llvm-svn: 62271
Diffstat (limited to 'llvm/lib/Transforms/Utils')
| -rw-r--r-- | llvm/lib/Transforms/Utils/InlineFunction.cpp | 18 | 
1 files changed, 14 insertions, 4 deletions
| diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index 0b1105ecdcf..63b5f5475dd 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/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]; | 

