Skip to content

Commit c42ef75

Browse files
zsrkmynvmaksimo
authored andcommitted
Erase instructions out of loop to avoid clobbering iterator (intel#1155)
Original commit: KhronosGroup/SPIRV-LLVM-Translator@f516ad1
1 parent 9ba2c7c commit c42ef75

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

llvm-spirv/lib/SPIRV/SPIRVUtil.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,7 @@ bool postProcessBuiltinReturningStruct(Function *F) {
18701870
LLVMContext *Context = &M->getContext();
18711871
std::string Name = F->getName().str();
18721872
F->setName(Name + ".old");
1873+
SmallVector<Instruction *, 32> InstToRemove;
18731874
for (auto *U : F->users()) {
18741875
if (auto *CI = dyn_cast<CallInst>(U)) {
18751876
auto *ST = cast<StoreInst>(*(CI->user_begin()));
@@ -1887,12 +1888,14 @@ bool postProcessBuiltinReturningStruct(Function *F) {
18871888
Args.insert(Args.begin(), ST->getPointerOperand());
18881889
auto *NewCI = CallInst::Create(NewF, Args, CI->getName(), CI);
18891890
NewCI->setCallingConv(CI->getCallingConv());
1890-
ST->dropAllReferences();
1891-
ST->eraseFromParent();
1892-
CI->dropAllReferences();
1893-
CI->eraseFromParent();
1891+
InstToRemove.push_back(ST);
1892+
InstToRemove.push_back(CI);
18941893
}
18951894
}
1895+
for (auto *Inst : InstToRemove) {
1896+
Inst->dropAllReferences();
1897+
Inst->eraseFromParent();
1898+
}
18961899
F->dropAllReferences();
18971900
F->eraseFromParent();
18981901
return true;

0 commit comments

Comments
 (0)