From 613eac2854cf34bab22eddc813cf38b89cbe8b8a Mon Sep 17 00:00:00 2001 From: Premanand M Rao Date: Fri, 18 Sep 2020 09:55:21 -0700 Subject: [PATCH] [SYCL] Use a copy to avoid invalidated access This fixes a bug introduced in PR #2430 where the iterator might get invalidated between accesses. Signed-off-by: Premanand M Rao --- clang/lib/CodeGen/CodeGenModule.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b98d2027bd647..a8da0b910092b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2273,12 +2273,13 @@ void CodeGenModule::EmitDeferred() { auto DDI = DeferredDecls.find(AliaseeName); // Emit what is aliased first. if (DDI != DeferredDecls.end()) { - llvm::GlobalValue *AliaseeGV = dyn_cast( - GetAddrOfGlobal(DDI->second, ForDefinition)); + GlobalDecl GD = DDI->second; + llvm::GlobalValue *AliaseeGV = + dyn_cast(GetAddrOfGlobal(GD, ForDefinition)); if (!AliaseeGV) - AliaseeGV = GetGlobalValue(getMangledName(DDI->second)); + AliaseeGV = GetGlobalValue(getMangledName(GD)); assert(AliaseeGV); - EmitGlobalDefinition(DDI->second, AliaseeGV); + EmitGlobalDefinition(GD, AliaseeGV); // Remove the entry just added to the DeferredDeclsToEmit // since we have emitted it. DeferredDeclsToEmit.pop_back();