diff options
| author | Alexey Bataev <a.bataev@hotmail.com> | 2018-03-07 18:17:06 +0000 |
|---|---|---|
| committer | Alexey Bataev <a.bataev@hotmail.com> | 2018-03-07 18:17:06 +0000 |
| commit | ab4ea225fe60b9adf6dd3d757fa75e6c7ca8731d (patch) | |
| tree | 732b8c55c7c31edd8e14d649a264fab12d80e9a0 /clang/lib/CodeGen/CGStmtOpenMP.cpp | |
| parent | 2d19f9036e67bc1a9ff3811953906a6b42cbd8d6 (diff) | |
| download | bcm5719-llvm-ab4ea225fe60b9adf6dd3d757fa75e6c7ca8731d.tar.gz bcm5719-llvm-ab4ea225fe60b9adf6dd3d757fa75e6c7ca8731d.zip | |
[OPENMP] Fix lifetime of the loop counters.
We may emit incorrect lifetime info during codegen for loop counters in
OpenMP constructs because of automatic scope cleanup when we needed
temporarily locations for private loop counters.
llvm-svn: 326922
Diffstat (limited to 'clang/lib/CodeGen/CGStmtOpenMP.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGStmtOpenMP.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index d9b4fa83a93..8d1f9c6f7b7 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -120,18 +120,18 @@ public: /// of used expression from loop statement. class OMPLoopScope : public CodeGenFunction::RunCleanupsScope { void emitPreInitStmt(CodeGenFunction &CGF, const OMPLoopDirective &S) { - CodeGenFunction::OMPPrivateScope PreCondScope(CGF); + CodeGenFunction::OMPMapVars PreCondVars; for (auto *E : S.counters()) { const auto *VD = cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl()); - (void)PreCondScope.addPrivate(VD, [&CGF, VD]() { - return CGF.CreateMemTemp(VD->getType().getNonReferenceType()); - }); + (void)PreCondVars.setVarAddr( + CGF, VD, CGF.CreateMemTemp(VD->getType().getNonReferenceType())); } - (void)PreCondScope.Privatize(); + (void)PreCondVars.apply(CGF); if (auto *PreInits = cast_or_null<DeclStmt>(S.getPreInits())) { for (const auto *I : PreInits->decls()) CGF.EmitVarDecl(cast<VarDecl>(*I)); } + PreCondVars.restore(CGF); } public: @@ -1475,25 +1475,25 @@ void CodeGenFunction::EmitOMPPrivateLoopCounters( for (auto *E : S.counters()) { auto *VD = cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl()); auto *PrivateVD = cast<VarDecl>(cast<DeclRefExpr>(*I)->getDecl()); - (void)LoopScope.addPrivate(VD, [&]() -> Address { - // Emit var without initialization. - if (!LocalDeclMap.count(PrivateVD)) { - auto VarEmission = EmitAutoVarAlloca(*PrivateVD); - EmitAutoVarCleanups(VarEmission); - } - DeclRefExpr DRE(const_cast<VarDecl *>(PrivateVD), - /*RefersToEnclosingVariableOrCapture=*/false, - (*I)->getType(), VK_LValue, (*I)->getExprLoc()); - return EmitLValue(&DRE).getAddress(); + // Emit var without initialization. + auto VarEmission = EmitAutoVarAlloca(*PrivateVD); + EmitAutoVarCleanups(VarEmission); + LocalDeclMap.erase(PrivateVD); + (void)LoopScope.addPrivate(VD, [&VarEmission]() { + return VarEmission.getAllocatedAddress(); }); if (LocalDeclMap.count(VD) || CapturedStmtInfo->lookup(VD) || VD->hasGlobalStorage()) { - (void)LoopScope.addPrivate(PrivateVD, [&]() -> Address { + (void)LoopScope.addPrivate(PrivateVD, [this, VD, E]() { DeclRefExpr DRE(const_cast<VarDecl *>(VD), LocalDeclMap.count(VD) || CapturedStmtInfo->lookup(VD), E->getType(), VK_LValue, E->getExprLoc()); return EmitLValue(&DRE).getAddress(); }); + } else { + (void)LoopScope.addPrivate(PrivateVD, [&VarEmission]() { + return VarEmission.getAllocatedAddress(); + }); } ++I; } @@ -1611,9 +1611,9 @@ void CodeGenFunction::EmitOMPSimdFinal( } } Address OrigAddr = Address::invalid(); - if (CED) + if (CED) { OrigAddr = EmitLValue(CED->getInit()->IgnoreImpCasts()).getAddress(); - else { + } else { DeclRefExpr DRE(const_cast<VarDecl *>(PrivateVD), /*RefersToEnclosingVariableOrCapture=*/false, (*IPC)->getType(), VK_LValue, (*IPC)->getExprLoc()); |

