Skip to content

Commit c25cf89

Browse files
committed
[libspirv] Fix function erase order in LibclcRemangler post-processing
1 parent 2c613bb commit c25cf89

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

libclc/utils/libclc-remangler/LibclcRemangler.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ class LibCLCRemangler : public ASTConsumer {
968968
void postProcessRemoveTmpSuffix(llvm::Module *M) {
969969
if (TestRun)
970970
return;
971+
std::vector<Function *> ToErase;
971972
for (auto &F : make_early_inc_range(*M)) {
972973
StringRef Name = F.getName();
973974
if (!Name.consume_back(TmpSuffix))
@@ -976,7 +977,7 @@ class LibCLCRemangler : public ASTConsumer {
976977
if (RenamedFunctions.count(Name.str())) {
977978
// Drop unuseful clone of the original or remangled function.
978979
Func->replaceAllUsesWith(ConstantPointerNull::get(Func->getType()));
979-
Func->eraseFromParent();
980+
ToErase.push_back(Func);
980981
} else {
981982
// Name doesn't exist in the original module. Drop unuseful clone of
982983
// remangled function.
@@ -987,6 +988,8 @@ class LibCLCRemangler : public ASTConsumer {
987988
// Complete the mangling process, e.g. from _Z1fPU3AS4i to _Z1fPi.
988989
F.setName(Name);
989990
}
991+
for (auto *F : ToErase)
992+
F->eraseFromParent();
990993
}
991994

992995
void handleModule(llvm::Module *M) {

0 commit comments

Comments
 (0)