aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2021-03-04 13:52:30 -0800
committerReid Kleckner <rnk@google.com>2021-03-04 13:57:46 -0800
commit1c2e7d200df27e91631ba300965245518bfe252c (patch)
tree348e45175809c1a962955ad326a5a28e141f0e52 /clang/lib/CodeGen/CodeGenFunction.cpp
parent9899427174b4a6a42c64dcdf29e3f23e40a1fc19 (diff)
downloadllvm-1c2e7d200df27e91631ba300965245518bfe252c.zip
llvm-1c2e7d200df27e91631ba300965245518bfe252c.tar.gz
llvm-1c2e7d200df27e91631ba300965245518bfe252c.tar.bz2
[MS] Fix crash involving gnu stmt exprs and inalloca
Use a WeakTrackingVH to cope with the stmt emission logic that cleans up unreachable blocks. This invalidates the reference to the deferred replacement placeholder. Cope with it. Fixes PR25102 (from 2015!)
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 6d95adc..53bf69f 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -452,13 +452,13 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
if (CGM.getCodeGenOpts().EmitDeclMetadata)
EmitDeclMetadata();
- for (SmallVectorImpl<std::pair<llvm::Instruction *, llvm::Value *> >::iterator
- I = DeferredReplacements.begin(),
- E = DeferredReplacements.end();
- I != E; ++I) {
- I->first->replaceAllUsesWith(I->second);
- I->first->eraseFromParent();
+ for (const auto &R : DeferredReplacements) {
+ if (llvm::Value *Old = R.first) {
+ Old->replaceAllUsesWith(R.second);
+ cast<llvm::Instruction>(Old)->eraseFromParent();
+ }
}
+ DeferredReplacements.clear();
// Eliminate CleanupDestSlot alloca by replacing it with SSA values and
// PHIs if the current function is a coroutine. We don't do it for all