[clang] [Clang][CodeGen] Segfault when compiling weird code (PR #90165)

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 25 22:29:57 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-codegen

Author:  Tim Pham (timmyhoa)

<details>
<summary>Changes</summary>

Closes #<!-- -->88917 

Do I really know what is going on? Nope. 
Do I know what the bug is? Enough to fix it (hopefully) :)

I'm just a beginner so sorry for any obvious mistake.  

---
Full diff: https://github.com/llvm/llvm-project/pull/90165.diff


1 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+4) 


``````````diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index d085e735ecb443..7e79b6ce350beb 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5706,6 +5706,7 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old,
 
   llvm::Type *newRetTy = newFn->getReturnType();
   SmallVector<llvm::Value*, 4> newArgs;
+  SmallVector<llvm::CallBase *> toBeRemoved;
 
   for (llvm::Value::use_iterator ui = old->use_begin(), ue = old->use_end();
          ui != ue; ) {
@@ -5792,6 +5793,9 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old,
     if (callSite->getDebugLoc())
       newCall->setDebugLoc(callSite->getDebugLoc());
 
+    toBeRemoved.push_back(callSite);
+  }
+  for (llvm::CallBase *callSite : toBeRemoved) {
     callSite->eraseFromParent();
   }
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/90165


More information about the cfe-commits mailing list