https://github.com/lolloz98 created https://github.com/llvm/llvm-project/pull/90255
Closes #88917 I am a newby in llvm development. I followed the suggestion for solving the issue. I added just a simple test to verify that the compilation does not crash. Should the test not be good enough or any problems are found, please let me know, eager to learn :) >From 0d473873057b094c8cf112f7075c4a578e54a4f5 Mon Sep 17 00:00:00 2001 From: lolloz98 <lorenzocarpan...@yahoo.it> Date: Fri, 26 Apr 2024 20:31:32 +0100 Subject: [PATCH] [clang] solve crash due to function overloading. --- clang/lib/CodeGen/CodeGenModule.cpp | 16 ++++++++++++---- clang/test/CodeGen/function_overload_crash.c | 7 +++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 clang/test/CodeGen/function_overload_crash.c diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 0c447b20cef40d..bed5669861392d 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -5702,13 +5702,16 @@ CodeGenModule::getLLVMLinkageVarDefinition(const VarDecl *VD) { static void replaceUsesOfNonProtoConstant(llvm::Constant *old, llvm::Function *newFn) { // Fast path. - if (old->use_empty()) return; + if (old->use_empty()) + return; llvm::Type *newRetTy = newFn->getReturnType(); - SmallVector<llvm::Value*, 4> newArgs; + SmallVector<llvm::Value *, 4> newArgs; + + SmallVector<llvm::CallBase *> callSitesToBeRemovedFromParent; for (llvm::Value::use_iterator ui = old->use_begin(), ue = old->use_end(); - ui != ue; ) { + ui != ue;) { llvm::Value::use_iterator use = ui++; // Increment before the use is erased. llvm::User *user = use->getUser(); @@ -5722,7 +5725,8 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old, // Recognize calls to the function. llvm::CallBase *callSite = dyn_cast<llvm::CallBase>(user); - if (!callSite) continue; + if (!callSite) + continue; if (!callSite->isCallee(&*use)) continue; @@ -5792,6 +5796,10 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old, if (callSite->getDebugLoc()) newCall->setDebugLoc(callSite->getDebugLoc()); + callSitesToBeRemovedFromParent.push_back(callSite); + } + + for (auto *callSite : callSitesToBeRemovedFromParent) { callSite->eraseFromParent(); } } diff --git a/clang/test/CodeGen/function_overload_crash.c b/clang/test/CodeGen/function_overload_crash.c new file mode 100644 index 00000000000000..094b56030d7ae0 --- /dev/null +++ b/clang/test/CodeGen/function_overload_crash.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm < %s + +int b(); +int main() { return b(b); } +int b(int (*f)()){ + return 0; +} \ No newline at end of file _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits