From 4801bd41cf2a3491f21dbd526dc91346e4d54c05 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 14 Aug 2008 15:03:05 +0000 Subject: 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. llvm-svn: 54778 --- llvm/lib/Transforms/IPO/StructRetPromotion.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'llvm/lib/Transforms/IPO/StructRetPromotion.cpp') diff --git a/llvm/lib/Transforms/IPO/StructRetPromotion.cpp b/llvm/lib/Transforms/IPO/StructRetPromotion.cpp index 1db7446d2b0..2f44d80ae48 100644 --- a/llvm/lib/Transforms/IPO/StructRetPromotion.cpp +++ b/llvm/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 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(*GI)) { - L->replaceAllUsesWith(GR); - L->eraseFromParent(); - } + while(!UGEP->use_empty()) { + // isSafeToUpdateAllCallers has checked that all GEP uses are + // LoadInsts + LoadInst *L = cast(*UGEP->use_begin()); + L->replaceAllUsesWith(GR); + L->eraseFromParent(); } UGEP->eraseFromParent(); } -- cgit v1.2.3