@@ -5740,15 +5740,17 @@ CodeGenModule::getLLVMLinkageVarDefinition(const VarDecl *VD) {
5740
5740
static void replaceUsesOfNonProtoConstant (llvm::Constant *old,
5741
5741
llvm::Function *newFn) {
5742
5742
// Fast path.
5743
- if (old->use_empty ()) return ;
5743
+ if (old->use_empty ())
5744
+ return ;
5744
5745
5745
5746
llvm::Type *newRetTy = newFn->getReturnType ();
5746
- SmallVector<llvm::Value*, 4 > newArgs;
5747
+ SmallVector<llvm::Value *, 4 > newArgs;
5748
+
5749
+ SmallVector<llvm::CallBase *> callSitesToBeRemovedFromParent;
5747
5750
5748
5751
for (llvm::Value::use_iterator ui = old->use_begin (), ue = old->use_end ();
5749
- ui != ue; ) {
5750
- llvm::Value::use_iterator use = ui++; // Increment before the use is erased.
5751
- llvm::User *user = use->getUser ();
5752
+ ui != ue; ui++) {
5753
+ llvm::User *user = ui->getUser ();
5752
5754
5753
5755
// Recognize and replace uses of bitcasts. Most calls to
5754
5756
// unprototyped functions will use bitcasts.
@@ -5760,8 +5762,9 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old,
5760
5762
5761
5763
// Recognize calls to the function.
5762
5764
llvm::CallBase *callSite = dyn_cast<llvm::CallBase>(user);
5763
- if (!callSite) continue ;
5764
- if (!callSite->isCallee (&*use))
5765
+ if (!callSite)
5766
+ continue ;
5767
+ if (!callSite->isCallee (&*ui))
5765
5768
continue ;
5766
5769
5767
5770
// If the return types don't match exactly, then we can't
@@ -5830,6 +5833,10 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old,
5830
5833
if (callSite->getDebugLoc ())
5831
5834
newCall->setDebugLoc (callSite->getDebugLoc ());
5832
5835
5836
+ callSitesToBeRemovedFromParent.push_back (callSite);
5837
+ }
5838
+
5839
+ for (auto *callSite : callSitesToBeRemovedFromParent) {
5833
5840
callSite->eraseFromParent ();
5834
5841
}
5835
5842
}
0 commit comments