Hi all. I want to iterate through all the functions and clone them. make_early_inc_range
should allow to insert new elements in the list without invalidating iterators. However, this code leads to an infinite loop:
for (Function &F : make_early_inc_range(M)) {
Function *NF = Function::Create(cast<FunctionType>(F.getValueType()), F.getLinkage(),
F.getAddressSpace(), F.getName(), &M);
...
}
Meanwhile, this code works as expected:
SmallVector<Function*> FList;
for (auto &F: M)
FList.push_back(&F);
for (Function *F : FList) {
Function *NF = Function::Create(cast<FunctionType>(F->getValueType()), F->getLinkage(),
F->getAddressSpace(), F->getName(), &M);
...
}
LLVM 15.0.3