|
31 | 31 | #include "clang/Sema/SemaInternal.h" |
32 | 32 | #include "llvm/ADT/IndexedMap.h" |
33 | 33 | #include "llvm/ADT/PointerEmbeddedInt.h" |
| 34 | +#include "llvm/ADT/STLExtras.h" |
34 | 35 | #include "llvm/Frontend/OpenMP/OMPConstants.h" |
35 | 36 | using namespace clang; |
36 | 37 | using namespace llvm::omp; |
@@ -2010,7 +2011,23 @@ VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo, |
2010 | 2011 | // |
2011 | 2012 | if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) |
2012 | 2013 | return nullptr; |
2013 | | - return VD; |
| 2014 | + CapturedRegionScopeInfo *CSI = nullptr; |
| 2015 | + for (FunctionScopeInfo *FSI : llvm::drop_begin( |
| 2016 | + llvm::reverse(FunctionScopes), |
| 2017 | + CheckScopeInfo ? (FunctionScopes.size() - (StopAt + 1)) : 0)) { |
| 2018 | + if (!isa<CapturingScopeInfo>(FSI)) |
| 2019 | + return nullptr; |
| 2020 | + if (auto *RSI = dyn_cast<CapturedRegionScopeInfo>(FSI)) |
| 2021 | + if (RSI->CapRegionKind == CR_OpenMP) { |
| 2022 | + CSI = RSI; |
| 2023 | + break; |
| 2024 | + } |
| 2025 | + } |
| 2026 | + SmallVector<OpenMPDirectiveKind, 4> Regions; |
| 2027 | + getOpenMPCaptureRegions(Regions, |
| 2028 | + DSAStack->getDirective(CSI->OpenMPLevel)); |
| 2029 | + if (Regions[CSI->OpenMPCaptureLevel] != OMPD_task) |
| 2030 | + return VD; |
2014 | 2031 | } |
2015 | 2032 | } |
2016 | 2033 |
|
@@ -2151,15 +2168,18 @@ void Sema::setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, |
2151 | 2168 | FD->addAttr(OMPCaptureKindAttr::CreateImplicit(Context, OMPC)); |
2152 | 2169 | } |
2153 | 2170 |
|
2154 | | -bool Sema::isOpenMPTargetCapturedDecl(const ValueDecl *D, |
2155 | | - unsigned Level) const { |
| 2171 | +bool Sema::isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level, |
| 2172 | + unsigned CaptureLevel) const { |
2156 | 2173 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
2157 | 2174 | // Return true if the current level is no longer enclosed in a target region. |
2158 | 2175 |
|
| 2176 | + SmallVector<OpenMPDirectiveKind, 4> Regions; |
| 2177 | + getOpenMPCaptureRegions(Regions, DSAStack->getDirective(Level)); |
2159 | 2178 | const auto *VD = dyn_cast<VarDecl>(D); |
2160 | 2179 | return VD && !VD->hasLocalStorage() && |
2161 | 2180 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
2162 | | - Level); |
| 2181 | + Level) && |
| 2182 | + Regions[CaptureLevel] != OMPD_task; |
2163 | 2183 | } |
2164 | 2184 |
|
2165 | 2185 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
|
0 commit comments