From 1c2e7d200df27e91631ba300965245518bfe252c Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 4 Mar 2021 13:52:30 -0800 Subject: [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!) --- clang/lib/CodeGen/CodeGenFunction.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp') 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 >::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(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 -- cgit v1.1