From c25cf8915f66b5f67851e82d38c2ffca4fdace31 Mon Sep 17 00:00:00 2001 From: Wenju He Date: Fri, 19 Dec 2025 02:32:37 +0100 Subject: [PATCH 1/2] [libspirv] Fix function erase order in LibclcRemangler post-processing --- libclc/utils/libclc-remangler/LibclcRemangler.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libclc/utils/libclc-remangler/LibclcRemangler.cpp b/libclc/utils/libclc-remangler/LibclcRemangler.cpp index 1702f8a6df84e..245fd0082c61c 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,7 @@ 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(); + ToErase.push_back(Func); } else { // Name doesn't exist in the original module. Drop unuseful clone of // remangled function. @@ -987,6 +988,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) { From b251393eb4f1715a7ef11ae8124384249a79dc7e Mon Sep 17 00:00:00 2001 From: Wenju He Date: Sat, 20 Dec 2025 10:25:39 +0100 Subject: [PATCH 2/2] Clear old function name to unblock setName() in tmp-suffix cleanup --- libclc/utils/libclc-remangler/LibclcRemangler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libclc/utils/libclc-remangler/LibclcRemangler.cpp b/libclc/utils/libclc-remangler/LibclcRemangler.cpp index 245fd0082c61c..9b092c5d4a096 100644 --- a/libclc/utils/libclc-remangler/LibclcRemangler.cpp +++ b/libclc/utils/libclc-remangler/LibclcRemangler.cpp @@ -977,6 +977,7 @@ 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->setName(""); ToErase.push_back(Func); } else { // Name doesn't exist in the original module. Drop unuseful clone of