diff options
author | Matthijs Kooijman <matthijs@stdin.nl> | 2008-08-14 15:03:05 +0000 |
---|---|---|
committer | Matthijs Kooijman <matthijs@stdin.nl> | 2008-08-14 15:03:05 +0000 |
commit | 9ca41bad635d3f582b8f4874f11a79e57823b16f (patch) | |
tree | a249bfdf33e7a8320c861bbe00fa3c229aaab079 /lib | |
parent | 4a472711c76faa15bdb773de9c542af0f672f6f6 (diff) | |
download | external_llvm-9ca41bad635d3f582b8f4874f11a79e57823b16f.zip external_llvm-9ca41bad635d3f582b8f4874f11a79e57823b16f.tar.gz external_llvm-9ca41bad635d3f582b8f4874f11a79e57823b16f.tar.bz2 |
Replace two for loops with while(!X->use_empty()) loops. This prevents
invalidating the iterator by deleting the current use. This fixes a segfault on
64 bit linux reported in PR2675.
Also remove an unneeded if.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54778 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/IPO/StructRetPromotion.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/Transforms/IPO/StructRetPromotion.cpp b/lib/Transforms/IPO/StructRetPromotion.cpp index 1db7446..2f44d80 100644 --- a/lib/Transforms/IPO/StructRetPromotion.cpp +++ b/lib/Transforms/IPO/StructRetPromotion.cpp @@ -258,10 +258,8 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) { // ParamAttrs - Keep track of the parameter attributes for the arguments. SmallVector<ParamAttrsWithIndex, 8> ArgAttrsVec; - for (Value::use_iterator FUI = F->use_begin(), FUE = F->use_end(); - FUI != FUE;) { - CallSite CS = CallSite::get(*FUI); - ++FUI; + while (!F->use_empty()) { + CallSite CS = CallSite::get(*F->use_begin()); Instruction *Call = CS.getInstruction(); const PAListPtr &PAL = F->getParamAttrs(); @@ -317,12 +315,12 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) { assert (Idx && "Unexpected getelementptr index!"); Value *GR = ExtractValueInst::Create(New, Idx->getZExtValue(), "evi", UGEP); - for (Value::use_iterator GI = UGEP->use_begin(), - GE = UGEP->use_end(); GI != GE; ++GI) { - if (LoadInst *L = dyn_cast<LoadInst>(*GI)) { - L->replaceAllUsesWith(GR); - L->eraseFromParent(); - } + while(!UGEP->use_empty()) { + // isSafeToUpdateAllCallers has checked that all GEP uses are + // LoadInsts + LoadInst *L = cast<LoadInst>(*UGEP->use_begin()); + L->replaceAllUsesWith(GR); + L->eraseFromParent(); } UGEP->eraseFromParent(); } |