diff --git a/libclc/utils/libclc-remangler/LibclcRemangler.cpp b/libclc/utils/libclc-remangler/LibclcRemangler.cpp index 1702f8a6df84e..9b092c5d4a096 100644 --- a/libclc/utils/libclc-remangler/LibclcRemangler.cpp +++ b/libclc/utils/libclc-remangler/LibclcRemangler.cpp @@ -968,6 +968,7 @@ class LibCLCRemangler : public ASTConsumer { void postProcessRemoveTmpSuffix(llvm::Module *M) { if (TestRun) return; + std::vector ToErase; for (auto &F : make_early_inc_range(*M)) { StringRef Name = F.getName(); if (!Name.consume_back(TmpSuffix)) @@ -976,7 +977,8 @@ class LibCLCRemangler : public ASTConsumer { if (RenamedFunctions.count(Name.str())) { // Drop unuseful clone of the original or remangled function. Func->replaceAllUsesWith(ConstantPointerNull::get(Func->getType())); - Func->eraseFromParent(); + Func->setName(""); + ToErase.push_back(Func); } else { // Name doesn't exist in the original module. Drop unuseful clone of // remangled function. @@ -987,6 +989,8 @@ class LibCLCRemangler : public ASTConsumer { // Complete the mangling process, e.g. from _Z1fPU3AS4i to _Z1fPi. F.setName(Name); } + for (auto *F : ToErase) + F->eraseFromParent(); } void handleModule(llvm::Module *M) {