Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===// |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements semantic analysis for OpenMP directives and |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 11 | /// clauses. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 16 | #include "clang/AST/Decl.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclCXX.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 19 | #include "clang/AST/StmtCXX.h" |
| 20 | #include "clang/AST/StmtOpenMP.h" |
| 21 | #include "clang/AST/StmtVisitor.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 22 | #include "clang/Basic/OpenMPKinds.h" |
| 23 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 24 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 25 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 26 | #include "clang/Sema/Scope.h" |
| 27 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 28 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 29 | using namespace clang; |
| 30 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 31 | //===----------------------------------------------------------------------===// |
| 32 | // Stack of data-sharing attributes for variables |
| 33 | //===----------------------------------------------------------------------===// |
| 34 | |
| 35 | namespace { |
| 36 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 37 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 38 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 39 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 40 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 44 | /// clauses and their data-sharing attributes. |
| 45 | class DSAStackTy { |
| 46 | public: |
| 47 | struct DSAVarData { |
| 48 | OpenMPDirectiveKind DKind; |
| 49 | OpenMPClauseKind CKind; |
| 50 | DeclRefExpr *RefExpr; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 51 | DSAVarData() : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 52 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 53 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 54 | private: |
| 55 | struct DSAInfo { |
| 56 | OpenMPClauseKind Attributes; |
| 57 | DeclRefExpr *RefExpr; |
| 58 | }; |
| 59 | typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame^] | 60 | typedef llvm::SmallDenseMap<VarDecl *, DeclRefExpr *, 64> AlignedMapTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 61 | |
| 62 | struct SharingMapTy { |
| 63 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame^] | 64 | AlignedMapTy AlignedMap; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 65 | DefaultDataSharingAttributes DefaultAttr; |
| 66 | OpenMPDirectiveKind Directive; |
| 67 | DeclarationNameInfo DirectiveName; |
| 68 | Scope *CurScope; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 69 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 70 | Scope *CurScope) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame^] | 71 | : SharingMap(), AlignedMap(), DefaultAttr(DSA_unspecified), |
| 72 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope) { |
| 73 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 74 | SharingMapTy() |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame^] | 75 | : SharingMap(), AlignedMap(), DefaultAttr(DSA_unspecified), |
| 76 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 80 | |
| 81 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 82 | StackTy Stack; |
| 83 | Sema &Actions; |
| 84 | |
| 85 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 86 | |
| 87 | DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 88 | |
| 89 | /// \brief Checks if the variable is a local for OpenMP region. |
| 90 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 91 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 92 | public: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 93 | explicit DSAStackTy(Sema &S) : Stack(1), Actions(S) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 94 | |
| 95 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
| 96 | Scope *CurScope) { |
| 97 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope)); |
| 98 | } |
| 99 | |
| 100 | void pop() { |
| 101 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 102 | Stack.pop_back(); |
| 103 | } |
| 104 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame^] | 105 | /// \brief If 'aligned' declaration for given variable \a D was not seen yet, |
| 106 | /// add it and return NULL; otherwise return previous occurence's expression |
| 107 | /// for diagnostics. |
| 108 | DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE); |
| 109 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 110 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
| 111 | void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); |
| 112 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 113 | /// \brief Returns data sharing attributes from top of the stack for the |
| 114 | /// specified declaration. |
| 115 | DSAVarData getTopDSA(VarDecl *D); |
| 116 | /// \brief Returns data-sharing attributes for the specified declaration. |
| 117 | DSAVarData getImplicitDSA(VarDecl *D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 118 | /// \brief Checks if the specified variables has \a CKind data-sharing |
| 119 | /// attribute in \a DKind directive. |
| 120 | DSAVarData hasDSA(VarDecl *D, OpenMPClauseKind CKind, |
| 121 | OpenMPDirectiveKind DKind = OMPD_unknown); |
| 122 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 123 | /// \brief Returns currently analyzed directive. |
| 124 | OpenMPDirectiveKind getCurrentDirective() const { |
| 125 | return Stack.back().Directive; |
| 126 | } |
| 127 | |
| 128 | /// \brief Set default data sharing attribute to none. |
| 129 | void setDefaultDSANone() { Stack.back().DefaultAttr = DSA_none; } |
| 130 | /// \brief Set default data sharing attribute to shared. |
| 131 | void setDefaultDSAShared() { Stack.back().DefaultAttr = DSA_shared; } |
| 132 | |
| 133 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 134 | return Stack.back().DefaultAttr; |
| 135 | } |
| 136 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 137 | /// \brief Checks if the spewcified variable is threadprivate. |
| 138 | bool isThreadPrivate(VarDecl *D) { |
| 139 | DSAVarData DVar = getTopDSA(D); |
| 140 | return (DVar.CKind == OMPC_threadprivate || DVar.CKind == OMPC_copyin); |
| 141 | } |
| 142 | |
| 143 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 144 | Scope *getCurScope() { return Stack.back().CurScope; } |
| 145 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 146 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 147 | |
| 148 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 149 | VarDecl *D) { |
| 150 | DSAVarData DVar; |
| 151 | if (Iter == Stack.rend() - 1) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 152 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 153 | // in a region but not in construct] |
| 154 | // File-scope or namespace-scope variables referenced in called routines |
| 155 | // in the region are shared unless they appear in a threadprivate |
| 156 | // directive. |
| 157 | // TODO |
| 158 | if (!D->isFunctionOrMethodVarDecl()) |
| 159 | DVar.CKind = OMPC_shared; |
| 160 | |
| 161 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 162 | // in a region but not in construct] |
| 163 | // Variables with static storage duration that are declared in called |
| 164 | // routines in the region are shared. |
| 165 | if (D->hasGlobalStorage()) |
| 166 | DVar.CKind = OMPC_shared; |
| 167 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 168 | return DVar; |
| 169 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 170 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 171 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 172 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 173 | // in a Construct, C/C++, predetermined, p.1] |
| 174 | // Variables with automatic storage duration that are declared in a scope |
| 175 | // inside the construct are private. |
| 176 | if (DVar.DKind != OMPD_parallel) { |
| 177 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 178 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 179 | DVar.CKind = OMPC_private; |
| 180 | return DVar; |
| 181 | } |
| 182 | } |
| 183 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 184 | // Explicitly specified attributes and local variables with predetermined |
| 185 | // attributes. |
| 186 | if (Iter->SharingMap.count(D)) { |
| 187 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 188 | DVar.CKind = Iter->SharingMap[D].Attributes; |
| 189 | return DVar; |
| 190 | } |
| 191 | |
| 192 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 193 | // in a Construct, C/C++, implicitly determined, p.1] |
| 194 | // In a parallel or task construct, the data-sharing attributes of these |
| 195 | // variables are determined by the default clause, if present. |
| 196 | switch (Iter->DefaultAttr) { |
| 197 | case DSA_shared: |
| 198 | DVar.CKind = OMPC_shared; |
| 199 | return DVar; |
| 200 | case DSA_none: |
| 201 | return DVar; |
| 202 | case DSA_unspecified: |
| 203 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 204 | // in a Construct, implicitly determined, p.2] |
| 205 | // In a parallel construct, if no default clause is present, these |
| 206 | // variables are shared. |
| 207 | if (DVar.DKind == OMPD_parallel) { |
| 208 | DVar.CKind = OMPC_shared; |
| 209 | return DVar; |
| 210 | } |
| 211 | |
| 212 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 213 | // in a Construct, implicitly determined, p.4] |
| 214 | // In a task construct, if no default clause is present, a variable that in |
| 215 | // the enclosing context is determined to be shared by all implicit tasks |
| 216 | // bound to the current team is shared. |
| 217 | // TODO |
| 218 | if (DVar.DKind == OMPD_task) { |
| 219 | DSAVarData DVarTemp; |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 220 | for (StackTy::reverse_iterator I = std::next(Iter), |
| 221 | EE = std::prev(Stack.rend()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 222 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 223 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 224 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 225 | // in a Construct, implicitly determined, p.6] |
| 226 | // In a task construct, if no default clause is present, a variable |
| 227 | // whose data-sharing attribute is not determined by the rules above is |
| 228 | // firstprivate. |
| 229 | DVarTemp = getDSA(I, D); |
| 230 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 231 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 232 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 233 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 234 | return DVar; |
| 235 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 236 | if (I->Directive == OMPD_parallel) |
| 237 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 238 | } |
| 239 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 240 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 241 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 242 | return DVar; |
| 243 | } |
| 244 | } |
| 245 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 246 | // in a Construct, implicitly determined, p.3] |
| 247 | // For constructs other than task, if no default clause is present, these |
| 248 | // variables inherit their data-sharing attributes from the enclosing |
| 249 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 250 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame^] | 253 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 254 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
| 255 | auto It = Stack.back().AlignedMap.find(D); |
| 256 | if (It == Stack.back().AlignedMap.end()) { |
| 257 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 258 | Stack.back().AlignedMap[D] = NewDE; |
| 259 | return nullptr; |
| 260 | } else { |
| 261 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 262 | return It->second; |
| 263 | } |
| 264 | return nullptr; |
| 265 | } |
| 266 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 267 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
| 268 | if (A == OMPC_threadprivate) { |
| 269 | Stack[0].SharingMap[D].Attributes = A; |
| 270 | Stack[0].SharingMap[D].RefExpr = E; |
| 271 | } else { |
| 272 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 273 | Stack.back().SharingMap[D].Attributes = A; |
| 274 | Stack.back().SharingMap[D].RefExpr = E; |
| 275 | } |
| 276 | } |
| 277 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 278 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 279 | if (Stack.size() > 2) { |
| 280 | reverse_iterator I = Iter, E = Stack.rend() - 1; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 281 | Scope *TopScope = nullptr; |
Fraser Cormack | 111023c | 2014-04-15 08:59:09 +0000 | [diff] [blame] | 282 | while (I != E && I->Directive != OMPD_parallel) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 283 | ++I; |
| 284 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 285 | if (I == E) |
| 286 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 287 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 288 | Scope *CurScope = getCurScope(); |
| 289 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 290 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 291 | } |
| 292 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 293 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 294 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D) { |
| 298 | DSAVarData DVar; |
| 299 | |
| 300 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 301 | // in a Construct, C/C++, predetermined, p.1] |
| 302 | // Variables appearing in threadprivate directives are threadprivate. |
| 303 | if (D->getTLSKind() != VarDecl::TLS_None) { |
| 304 | DVar.CKind = OMPC_threadprivate; |
| 305 | return DVar; |
| 306 | } |
| 307 | if (Stack[0].SharingMap.count(D)) { |
| 308 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 309 | DVar.CKind = OMPC_threadprivate; |
| 310 | return DVar; |
| 311 | } |
| 312 | |
| 313 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 314 | // in a Construct, C/C++, predetermined, p.1] |
| 315 | // Variables with automatic storage duration that are declared in a scope |
| 316 | // inside the construct are private. |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 317 | OpenMPDirectiveKind Kind = getCurrentDirective(); |
| 318 | if (Kind != OMPD_parallel) { |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 319 | if (isOpenMPLocal(D, std::next(Stack.rbegin())) && D->isLocalVarDecl() && |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 320 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 321 | DVar.CKind = OMPC_private; |
| 322 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 323 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 327 | // in a Construct, C/C++, predetermined, p.4] |
| 328 | // Static data memebers are shared. |
| 329 | if (D->isStaticDataMember()) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 330 | // Variables with const-qualified type having no mutable member may be |
| 331 | // listed |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 332 | // in a firstprivate clause, even if they are static data members. |
| 333 | DSAVarData DVarTemp = hasDSA(D, OMPC_firstprivate); |
| 334 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 335 | return DVar; |
| 336 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 337 | DVar.CKind = OMPC_shared; |
| 338 | return DVar; |
| 339 | } |
| 340 | |
| 341 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
| 342 | bool IsConstant = Type.isConstant(Actions.getASTContext()); |
| 343 | while (Type->isArrayType()) { |
| 344 | QualType ElemType = cast<ArrayType>(Type.getTypePtr())->getElementType(); |
| 345 | Type = ElemType.getNonReferenceType().getCanonicalType(); |
| 346 | } |
| 347 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 348 | // in a Construct, C/C++, predetermined, p.6] |
| 349 | // Variables with const qualified type having no mutable member are |
| 350 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 351 | CXXRecordDecl *RD = |
| 352 | Actions.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 353 | if (IsConstant && |
| 354 | !(Actions.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
| 355 | // Variables with const-qualified type having no mutable member may be |
| 356 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 357 | DSAVarData DVarTemp = hasDSA(D, OMPC_firstprivate); |
| 358 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 359 | return DVar; |
| 360 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 361 | DVar.CKind = OMPC_shared; |
| 362 | return DVar; |
| 363 | } |
| 364 | |
| 365 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 366 | // in a Construct, C/C++, predetermined, p.7] |
| 367 | // Variables with static storage duration that are declared in a scope |
| 368 | // inside the construct are shared. |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 369 | if (D->isStaticLocal()) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 370 | DVar.CKind = OMPC_shared; |
| 371 | return DVar; |
| 372 | } |
| 373 | |
| 374 | // Explicitly specified attributes and local variables with predetermined |
| 375 | // attributes. |
| 376 | if (Stack.back().SharingMap.count(D)) { |
| 377 | DVar.RefExpr = Stack.back().SharingMap[D].RefExpr; |
| 378 | DVar.CKind = Stack.back().SharingMap[D].Attributes; |
| 379 | } |
| 380 | |
| 381 | return DVar; |
| 382 | } |
| 383 | |
| 384 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D) { |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 385 | return getDSA(std::next(Stack.rbegin()), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 388 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, OpenMPClauseKind CKind, |
| 389 | OpenMPDirectiveKind DKind) { |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 390 | for (StackTy::reverse_iterator I = std::next(Stack.rbegin()), |
| 391 | E = std::prev(Stack.rend()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 392 | I != E; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 393 | if (DKind != OMPD_unknown && DKind != I->Directive) |
| 394 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 395 | DSAVarData DVar = getDSA(I, D); |
| 396 | if (DVar.CKind == CKind) |
| 397 | return DVar; |
| 398 | } |
| 399 | return DSAVarData(); |
| 400 | } |
| 401 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 402 | void Sema::InitDataSharingAttributesStack() { |
| 403 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 404 | } |
| 405 | |
| 406 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 407 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 408 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 409 | |
| 410 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 411 | const DeclarationNameInfo &DirName, |
| 412 | Scope *CurScope) { |
| 413 | DSAStack->push(DKind, DirName, CurScope); |
| 414 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 415 | } |
| 416 | |
| 417 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
| 418 | DSAStack->pop(); |
| 419 | DiscardCleanupsInEvaluationContext(); |
| 420 | PopExpressionEvaluationContext(); |
| 421 | } |
| 422 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 423 | namespace { |
| 424 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 425 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 426 | private: |
| 427 | Sema &Actions; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 428 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 429 | public: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 430 | VarDeclFilterCCC(Sema &S) : Actions(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 431 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 432 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 433 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 434 | return VD->hasGlobalStorage() && |
| 435 | Actions.isDeclInScope(ND, Actions.getCurLexicalContext(), |
| 436 | Actions.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 437 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 438 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 439 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 440 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 441 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 442 | |
| 443 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 444 | CXXScopeSpec &ScopeSpec, |
| 445 | const DeclarationNameInfo &Id) { |
| 446 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 447 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 448 | |
| 449 | if (Lookup.isAmbiguous()) |
| 450 | return ExprError(); |
| 451 | |
| 452 | VarDecl *VD; |
| 453 | if (!Lookup.isSingleResult()) { |
| 454 | VarDeclFilterCCC Validator(*this); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 455 | if (TypoCorrection Corrected = |
| 456 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, Validator, |
| 457 | CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 458 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 459 | PDiag(Lookup.empty() |
| 460 | ? diag::err_undeclared_var_use_suggest |
| 461 | : diag::err_omp_expected_var_arg_suggest) |
| 462 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 463 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 464 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 465 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 466 | : diag::err_omp_expected_var_arg) |
| 467 | << Id.getName(); |
| 468 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 469 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 470 | } else { |
| 471 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 472 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 473 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 474 | return ExprError(); |
| 475 | } |
| 476 | } |
| 477 | Lookup.suppressDiagnostics(); |
| 478 | |
| 479 | // OpenMP [2.9.2, Syntax, C/C++] |
| 480 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 481 | if (!VD->hasGlobalStorage()) { |
| 482 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 483 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 484 | bool IsDecl = |
| 485 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 486 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 487 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 488 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 489 | return ExprError(); |
| 490 | } |
| 491 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 492 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 493 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 494 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 495 | // A threadprivate directive for file-scope variables must appear outside |
| 496 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 497 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 498 | !getCurLexicalContext()->isTranslationUnit()) { |
| 499 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 500 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 501 | bool IsDecl = |
| 502 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 503 | Diag(VD->getLocation(), |
| 504 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 505 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 506 | return ExprError(); |
| 507 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 508 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 509 | // A threadprivate directive for static class member variables must appear |
| 510 | // in the class definition, in the same scope in which the member |
| 511 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 512 | if (CanonicalVD->isStaticDataMember() && |
| 513 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 514 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 515 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 516 | bool IsDecl = |
| 517 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 518 | Diag(VD->getLocation(), |
| 519 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 520 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 521 | return ExprError(); |
| 522 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 523 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 524 | // A threadprivate directive for namespace-scope variables must appear |
| 525 | // outside any definition or declaration other than the namespace |
| 526 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 527 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 528 | (!getCurLexicalContext()->isFileContext() || |
| 529 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 530 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 531 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 532 | bool IsDecl = |
| 533 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 534 | Diag(VD->getLocation(), |
| 535 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 536 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 537 | return ExprError(); |
| 538 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 539 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 540 | // A threadprivate directive for static block-scope variables must appear |
| 541 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 542 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 543 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 544 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 545 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 546 | bool IsDecl = |
| 547 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 548 | Diag(VD->getLocation(), |
| 549 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 550 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 551 | return ExprError(); |
| 552 | } |
| 553 | |
| 554 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 555 | // A threadprivate directive must lexically precede all references to any |
| 556 | // of the variables in its list. |
| 557 | if (VD->isUsed()) { |
| 558 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 559 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 560 | return ExprError(); |
| 561 | } |
| 562 | |
| 563 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 564 | ExprResult DE = BuildDeclRefExpr(VD, ExprType, VK_LValue, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 565 | return DE; |
| 566 | } |
| 567 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 568 | Sema::DeclGroupPtrTy |
| 569 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 570 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 571 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 572 | CurContext->addDecl(D); |
| 573 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 574 | } |
| 575 | return DeclGroupPtrTy(); |
| 576 | } |
| 577 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 578 | namespace { |
| 579 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 580 | Sema &SemaRef; |
| 581 | |
| 582 | public: |
| 583 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 584 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 585 | if (VD->hasLocalStorage()) { |
| 586 | SemaRef.Diag(E->getLocStart(), |
| 587 | diag::err_omp_local_var_in_threadprivate_init) |
| 588 | << E->getSourceRange(); |
| 589 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 590 | << VD << VD->getSourceRange(); |
| 591 | return true; |
| 592 | } |
| 593 | } |
| 594 | return false; |
| 595 | } |
| 596 | bool VisitStmt(const Stmt *S) { |
| 597 | for (auto Child : S->children()) { |
| 598 | if (Child && Visit(Child)) |
| 599 | return true; |
| 600 | } |
| 601 | return false; |
| 602 | } |
| 603 | LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
| 604 | }; |
| 605 | } // namespace |
| 606 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 607 | OMPThreadPrivateDecl * |
| 608 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 609 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 610 | for (auto &RefExpr : VarList) { |
| 611 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 612 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 613 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 614 | |
| 615 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 616 | // A threadprivate variable must not have an incomplete type. |
| 617 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 618 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 619 | continue; |
| 620 | } |
| 621 | |
| 622 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 623 | // A threadprivate variable must not have a reference type. |
| 624 | if (VD->getType()->isReferenceType()) { |
| 625 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 626 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 627 | bool IsDecl = |
| 628 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 629 | Diag(VD->getLocation(), |
| 630 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 631 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 632 | continue; |
| 633 | } |
| 634 | |
Richard Smith | fd3834f | 2013-04-13 02:43:54 +0000 | [diff] [blame] | 635 | // Check if this is a TLS variable. |
| 636 | if (VD->getTLSKind()) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 637 | Diag(ILoc, diag::err_omp_var_thread_local) << VD; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 638 | bool IsDecl = |
| 639 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 640 | Diag(VD->getLocation(), |
| 641 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 642 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 643 | continue; |
| 644 | } |
| 645 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 646 | // Check if initial value of threadprivate variable reference variable with |
| 647 | // local storage (it is not supported by runtime). |
| 648 | if (auto Init = VD->getAnyInitializer()) { |
| 649 | LocalVarRefChecker Checker(*this); |
| 650 | if (Checker.Visit(Init)) continue; |
| 651 | } |
| 652 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 653 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 654 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 655 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 656 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 657 | if (!Vars.empty()) { |
| 658 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 659 | Vars); |
| 660 | D->setAccess(AS_public); |
| 661 | } |
| 662 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 663 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 664 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 665 | namespace { |
| 666 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 667 | DSAStackTy *Stack; |
| 668 | Sema &Actions; |
| 669 | bool ErrorFound; |
| 670 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 671 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 672 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 673 | public: |
| 674 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 675 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 676 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 677 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 678 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 679 | |
| 680 | SourceLocation ELoc = E->getExprLoc(); |
| 681 | |
| 682 | OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); |
| 683 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD); |
| 684 | if (DVar.CKind != OMPC_unknown) { |
| 685 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared && |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 686 | !Stack->isThreadPrivate(VD) && !DVar.RefExpr) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 687 | ImplicitFirstprivate.push_back(DVar.RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 688 | return; |
| 689 | } |
| 690 | // The default(none) clause requires that each variable that is referenced |
| 691 | // in the construct, and does not have a predetermined data-sharing |
| 692 | // attribute, must have its data-sharing attribute explicitly determined |
| 693 | // by being listed in a data-sharing attribute clause. |
| 694 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
| 695 | (DKind == OMPD_parallel || DKind == OMPD_task)) { |
| 696 | ErrorFound = true; |
| 697 | Actions.Diag(ELoc, diag::err_omp_no_dsa_for_variable) << VD; |
| 698 | return; |
| 699 | } |
| 700 | |
| 701 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 702 | // A list item that appears in a reduction clause of the innermost |
| 703 | // enclosing worksharing or parallel construct may not be accessed in an |
| 704 | // explicit task. |
| 705 | // TODO: |
| 706 | |
| 707 | // Define implicit data-sharing attributes for task. |
| 708 | DVar = Stack->getImplicitDSA(VD); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 709 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
| 710 | ImplicitFirstprivate.push_back(DVar.RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 714 | for (auto C : S->clauses()) |
| 715 | if (C) |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 716 | for (StmtRange R = C->children(); R; ++R) |
| 717 | if (Stmt *Child = *R) |
| 718 | Visit(Child); |
| 719 | } |
| 720 | void VisitStmt(Stmt *S) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 721 | for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I != E; |
| 722 | ++I) |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 723 | if (Stmt *Child = *I) |
| 724 | if (!isa<OMPExecutableDirective>(Child)) |
| 725 | Visit(Child); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 726 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 727 | |
| 728 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 729 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 730 | |
| 731 | DSAAttrChecker(DSAStackTy *S, Sema &Actions, CapturedStmt *CS) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 732 | : Stack(S), Actions(Actions), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 733 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 734 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 735 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 736 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, SourceLocation Loc, |
| 737 | Scope *CurScope) { |
| 738 | switch (DKind) { |
| 739 | case OMPD_parallel: { |
| 740 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 741 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 742 | Sema::CapturedParamNameType Params[3] = { |
| 743 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 744 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 745 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 746 | }; |
| 747 | ActOnCapturedRegionStart(Loc, CurScope, CR_OpenMP, Params); |
| 748 | break; |
| 749 | } |
| 750 | case OMPD_simd: { |
| 751 | Sema::CapturedParamNameType Params[1] = { |
| 752 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 753 | }; |
| 754 | ActOnCapturedRegionStart(Loc, CurScope, CR_OpenMP, Params); |
| 755 | break; |
| 756 | } |
| 757 | case OMPD_threadprivate: |
| 758 | case OMPD_task: |
| 759 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 760 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 761 | llvm_unreachable("Unknown OpenMP directive"); |
| 762 | } |
| 763 | } |
| 764 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 765 | StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, |
| 766 | ArrayRef<OMPClause *> Clauses, |
| 767 | Stmt *AStmt, |
| 768 | SourceLocation StartLoc, |
| 769 | SourceLocation EndLoc) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 770 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 771 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 772 | StmtResult Res = StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 773 | |
| 774 | // Check default data sharing attributes for referenced variables. |
| 775 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 776 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 777 | if (DSAChecker.isErrorFound()) |
| 778 | return StmtError(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 779 | // Generate list of implicitly defined firstprivate variables. |
| 780 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
| 781 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
| 782 | |
| 783 | bool ErrorFound = false; |
| 784 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 785 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 786 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 787 | SourceLocation(), SourceLocation())) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 788 | ClausesWithImplicit.push_back(Implicit); |
| 789 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 790 | DSAChecker.getImplicitFirstprivate().size(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 791 | } else |
| 792 | ErrorFound = true; |
| 793 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 794 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 795 | switch (Kind) { |
| 796 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 797 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 798 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 799 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 800 | case OMPD_simd: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 801 | Res = |
| 802 | ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 803 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 804 | case OMPD_threadprivate: |
| 805 | case OMPD_task: |
| 806 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 807 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 808 | llvm_unreachable("Unknown OpenMP directive"); |
| 809 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 810 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 811 | if (ErrorFound) |
| 812 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 813 | return Res; |
| 814 | } |
| 815 | |
| 816 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 817 | Stmt *AStmt, |
| 818 | SourceLocation StartLoc, |
| 819 | SourceLocation EndLoc) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 820 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 821 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 822 | // 1.2.2 OpenMP Language Terminology |
| 823 | // Structured block - An executable statement with a single entry at the |
| 824 | // top and a single exit at the bottom. |
| 825 | // The point of exit cannot be a branch out of the structured block. |
| 826 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 827 | CS->getCapturedDecl()->setNothrow(); |
| 828 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 829 | getCurFunction()->setHasBranchProtectedScope(); |
| 830 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 831 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 832 | AStmt); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 833 | } |
| 834 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 835 | StmtResult Sema::ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 836 | Stmt *AStmt, SourceLocation StartLoc, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 837 | SourceLocation EndLoc) { |
| 838 | Stmt *CStmt = AStmt; |
| 839 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(CStmt)) |
| 840 | CStmt = CS->getCapturedStmt(); |
| 841 | while (AttributedStmt *AS = dyn_cast_or_null<AttributedStmt>(CStmt)) |
| 842 | CStmt = AS->getSubStmt(); |
| 843 | ForStmt *For = dyn_cast<ForStmt>(CStmt); |
| 844 | if (!For) { |
| 845 | Diag(CStmt->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 846 | << getOpenMPDirectiveName(OMPD_simd); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 847 | return StmtError(); |
| 848 | } |
| 849 | |
| 850 | // FIXME: Checking loop canonical form, collapsing etc. |
| 851 | |
| 852 | getCurFunction()->setHasBranchProtectedScope(); |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 853 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 856 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 857 | SourceLocation StartLoc, |
| 858 | SourceLocation LParenLoc, |
| 859 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 860 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 861 | switch (Kind) { |
| 862 | case OMPC_if: |
| 863 | Res = ActOnOpenMPIfClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 864 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 865 | case OMPC_num_threads: |
| 866 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 867 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 868 | case OMPC_safelen: |
| 869 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 870 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 871 | case OMPC_collapse: |
| 872 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 873 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 874 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 875 | case OMPC_proc_bind: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 876 | case OMPC_private: |
| 877 | case OMPC_firstprivate: |
| 878 | case OMPC_shared: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 879 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame^] | 880 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 881 | case OMPC_copyin: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 882 | case OMPC_threadprivate: |
| 883 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 884 | llvm_unreachable("Clause is not allowed."); |
| 885 | } |
| 886 | return Res; |
| 887 | } |
| 888 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 889 | OMPClause *Sema::ActOnOpenMPIfClause(Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 890 | SourceLocation LParenLoc, |
| 891 | SourceLocation EndLoc) { |
| 892 | Expr *ValExpr = Condition; |
| 893 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 894 | !Condition->isInstantiationDependent() && |
| 895 | !Condition->containsUnexpandedParameterPack()) { |
| 896 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 897 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 898 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 899 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 900 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 901 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | return new (Context) OMPIfClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 905 | } |
| 906 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 907 | ExprResult Sema::PerformImplicitIntegerConversion(SourceLocation Loc, |
| 908 | Expr *Op) { |
| 909 | if (!Op) |
| 910 | return ExprError(); |
| 911 | |
| 912 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 913 | public: |
| 914 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 915 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 916 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 917 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 918 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 919 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 920 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 921 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 922 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 923 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 924 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 925 | QualType T, |
| 926 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 927 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 928 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 929 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 930 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 931 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 932 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 933 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 934 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 935 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 936 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 937 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 938 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 939 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 940 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 941 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 942 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 943 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 944 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 945 | llvm_unreachable("conversion functions are permitted"); |
| 946 | } |
| 947 | } ConvertDiagnoser; |
| 948 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 949 | } |
| 950 | |
| 951 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 952 | SourceLocation StartLoc, |
| 953 | SourceLocation LParenLoc, |
| 954 | SourceLocation EndLoc) { |
| 955 | Expr *ValExpr = NumThreads; |
| 956 | if (!NumThreads->isValueDependent() && !NumThreads->isTypeDependent() && |
| 957 | !NumThreads->isInstantiationDependent() && |
| 958 | !NumThreads->containsUnexpandedParameterPack()) { |
| 959 | SourceLocation NumThreadsLoc = NumThreads->getLocStart(); |
| 960 | ExprResult Val = |
| 961 | PerformImplicitIntegerConversion(NumThreadsLoc, NumThreads); |
| 962 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 963 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 964 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 965 | ValExpr = Val.get(); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 966 | |
| 967 | // OpenMP [2.5, Restrictions] |
| 968 | // The num_threads expression must evaluate to a positive integer value. |
| 969 | llvm::APSInt Result; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 970 | if (ValExpr->isIntegerConstantExpr(Result, Context) && Result.isSigned() && |
| 971 | !Result.isStrictlyPositive()) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 972 | Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause) |
| 973 | << "num_threads" << NumThreads->getSourceRange(); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 974 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 978 | return new (Context) |
| 979 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 980 | } |
| 981 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 982 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 983 | OpenMPClauseKind CKind) { |
| 984 | if (!E) |
| 985 | return ExprError(); |
| 986 | if (E->isValueDependent() || E->isTypeDependent() || |
| 987 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 988 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 989 | llvm::APSInt Result; |
| 990 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 991 | if (ICE.isInvalid()) |
| 992 | return ExprError(); |
| 993 | if (!Result.isStrictlyPositive()) { |
| 994 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| 995 | << getOpenMPClauseName(CKind) << E->getSourceRange(); |
| 996 | return ExprError(); |
| 997 | } |
| 998 | return ICE; |
| 999 | } |
| 1000 | |
| 1001 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 1002 | SourceLocation LParenLoc, |
| 1003 | SourceLocation EndLoc) { |
| 1004 | // OpenMP [2.8.1, simd construct, Description] |
| 1005 | // The parameter of the safelen clause must be a constant |
| 1006 | // positive integer expression. |
| 1007 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 1008 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1009 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1010 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1011 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1014 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *Num, SourceLocation StartLoc, |
| 1015 | SourceLocation LParenLoc, |
| 1016 | SourceLocation EndLoc) { |
| 1017 | // OpenMP [2.8.1, simd construct, Description] |
| 1018 | // The parameter of the collapse clause must be a constant |
| 1019 | // positive integer expression. |
| 1020 | ExprResult NumForLoops = |
| 1021 | VerifyPositiveIntegerConstantInClause(Num, OMPC_collapse); |
| 1022 | if (NumForLoops.isInvalid()) |
| 1023 | return nullptr; |
| 1024 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1025 | OMPCollapseClause(NumForLoops.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1028 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 1029 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 1030 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1031 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1032 | switch (Kind) { |
| 1033 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1034 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1035 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 1036 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1037 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1038 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1039 | Res = ActOnOpenMPProcBindClause( |
| 1040 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 1041 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1042 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1043 | case OMPC_if: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1044 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1045 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1046 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1047 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1048 | case OMPC_firstprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1049 | case OMPC_shared: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1050 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame^] | 1051 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1052 | case OMPC_copyin: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1053 | case OMPC_threadprivate: |
| 1054 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1055 | llvm_unreachable("Clause is not allowed."); |
| 1056 | } |
| 1057 | return Res; |
| 1058 | } |
| 1059 | |
| 1060 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1061 | SourceLocation KindKwLoc, |
| 1062 | SourceLocation StartLoc, |
| 1063 | SourceLocation LParenLoc, |
| 1064 | SourceLocation EndLoc) { |
| 1065 | if (Kind == OMPC_DEFAULT_unknown) { |
| 1066 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 1067 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 1068 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 1069 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 1070 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1071 | Values += "'"; |
| 1072 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 1073 | Values += "'"; |
| 1074 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 1075 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1076 | Values += " or "; |
| 1077 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 1078 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1079 | break; |
| 1080 | default: |
| 1081 | Values += Sep; |
| 1082 | break; |
| 1083 | } |
| 1084 | } |
| 1085 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1086 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1087 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1088 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1089 | switch (Kind) { |
| 1090 | case OMPC_DEFAULT_none: |
| 1091 | DSAStack->setDefaultDSANone(); |
| 1092 | break; |
| 1093 | case OMPC_DEFAULT_shared: |
| 1094 | DSAStack->setDefaultDSAShared(); |
| 1095 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1096 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1097 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1098 | break; |
| 1099 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1100 | return new (Context) |
| 1101 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1104 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 1105 | SourceLocation KindKwLoc, |
| 1106 | SourceLocation StartLoc, |
| 1107 | SourceLocation LParenLoc, |
| 1108 | SourceLocation EndLoc) { |
| 1109 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 1110 | std::string Values; |
| 1111 | std::string Sep(", "); |
| 1112 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 1113 | Values += "'"; |
| 1114 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 1115 | Values += "'"; |
| 1116 | switch (i) { |
| 1117 | case OMPC_PROC_BIND_unknown - 2: |
| 1118 | Values += " or "; |
| 1119 | break; |
| 1120 | case OMPC_PROC_BIND_unknown - 1: |
| 1121 | break; |
| 1122 | default: |
| 1123 | Values += Sep; |
| 1124 | break; |
| 1125 | } |
| 1126 | } |
| 1127 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1128 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1129 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1130 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1131 | return new (Context) |
| 1132 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1135 | OMPClause * |
| 1136 | Sema::ActOnOpenMPVarListClause(OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, |
| 1137 | Expr *TailExpr, SourceLocation StartLoc, |
| 1138 | SourceLocation LParenLoc, |
| 1139 | SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1140 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1141 | switch (Kind) { |
| 1142 | case OMPC_private: |
| 1143 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 1144 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1145 | case OMPC_firstprivate: |
| 1146 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 1147 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1148 | case OMPC_shared: |
| 1149 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 1150 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1151 | case OMPC_linear: |
| 1152 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 1153 | ColonLoc, EndLoc); |
| 1154 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame^] | 1155 | case OMPC_aligned: |
| 1156 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 1157 | ColonLoc, EndLoc); |
| 1158 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1159 | case OMPC_copyin: |
| 1160 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 1161 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1162 | case OMPC_if: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1163 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1164 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1165 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1166 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1167 | case OMPC_proc_bind: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1168 | case OMPC_threadprivate: |
| 1169 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1170 | llvm_unreachable("Clause is not allowed."); |
| 1171 | } |
| 1172 | return Res; |
| 1173 | } |
| 1174 | |
| 1175 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1176 | SourceLocation StartLoc, |
| 1177 | SourceLocation LParenLoc, |
| 1178 | SourceLocation EndLoc) { |
| 1179 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1180 | for (auto &RefExpr : VarList) { |
| 1181 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 1182 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1183 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1184 | Vars.push_back(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1185 | continue; |
| 1186 | } |
| 1187 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1188 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1189 | // OpenMP [2.1, C/C++] |
| 1190 | // A list item is a variable name. |
| 1191 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 1192 | // A variable that is part of another variable (as an array or |
| 1193 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1194 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1195 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1196 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1197 | continue; |
| 1198 | } |
| 1199 | Decl *D = DE->getDecl(); |
| 1200 | VarDecl *VD = cast<VarDecl>(D); |
| 1201 | |
| 1202 | QualType Type = VD->getType(); |
| 1203 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 1204 | // It will be analyzed later. |
| 1205 | Vars.push_back(DE); |
| 1206 | continue; |
| 1207 | } |
| 1208 | |
| 1209 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 1210 | // A variable that appears in a private clause must not have an incomplete |
| 1211 | // type or a reference type. |
| 1212 | if (RequireCompleteType(ELoc, Type, |
| 1213 | diag::err_omp_private_incomplete_type)) { |
| 1214 | continue; |
| 1215 | } |
| 1216 | if (Type->isReferenceType()) { |
| 1217 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1218 | << getOpenMPClauseName(OMPC_private) << Type; |
| 1219 | bool IsDecl = |
| 1220 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1221 | Diag(VD->getLocation(), |
| 1222 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1223 | << VD; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1224 | continue; |
| 1225 | } |
| 1226 | |
| 1227 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 1228 | // A variable of class type (or array thereof) that appears in a private |
| 1229 | // clause requires an accesible, unambiguous default constructor for the |
| 1230 | // class type. |
| 1231 | while (Type.getNonReferenceType()->isArrayType()) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1232 | Type = cast<ArrayType>(Type.getNonReferenceType().getTypePtr()) |
| 1233 | ->getElementType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1234 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1235 | CXXRecordDecl *RD = getLangOpts().CPlusPlus |
| 1236 | ? Type.getNonReferenceType()->getAsCXXRecordDecl() |
| 1237 | : nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1238 | if (RD) { |
| 1239 | CXXConstructorDecl *CD = LookupDefaultConstructor(RD); |
| 1240 | PartialDiagnostic PD = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1241 | PartialDiagnostic(PartialDiagnostic::NullDiagnostic()); |
| 1242 | if (!CD || CheckConstructorAccess( |
| 1243 | ELoc, CD, InitializedEntity::InitializeTemporary(Type), |
| 1244 | CD->getAccess(), PD) == AR_inaccessible || |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1245 | CD->isDeleted()) { |
| 1246 | Diag(ELoc, diag::err_omp_required_method) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1247 | << getOpenMPClauseName(OMPC_private) << 0; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1248 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 1249 | VarDecl::DeclarationOnly; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1250 | Diag(VD->getLocation(), |
| 1251 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1252 | << VD; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1253 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 1254 | continue; |
| 1255 | } |
| 1256 | MarkFunctionReferenced(ELoc, CD); |
| 1257 | DiagnoseUseOfDecl(CD, ELoc); |
| 1258 | |
| 1259 | CXXDestructorDecl *DD = RD->getDestructor(); |
| 1260 | if (DD) { |
| 1261 | if (CheckDestructorAccess(ELoc, DD, PD) == AR_inaccessible || |
| 1262 | DD->isDeleted()) { |
| 1263 | Diag(ELoc, diag::err_omp_required_method) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1264 | << getOpenMPClauseName(OMPC_private) << 4; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1265 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 1266 | VarDecl::DeclarationOnly; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1267 | Diag(VD->getLocation(), |
| 1268 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1269 | << VD; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1270 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 1271 | continue; |
| 1272 | } |
| 1273 | MarkFunctionReferenced(ELoc, DD); |
| 1274 | DiagnoseUseOfDecl(DD, ELoc); |
| 1275 | } |
| 1276 | } |
| 1277 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1278 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1279 | // in a Construct] |
| 1280 | // Variables with the predetermined data-sharing attributes may not be |
| 1281 | // listed in data-sharing attributes clauses, except for the cases |
| 1282 | // listed below. For these exceptions only, listing a predetermined |
| 1283 | // variable in a data-sharing attribute clause is allowed and overrides |
| 1284 | // the variable's predetermined data-sharing attributes. |
| 1285 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD); |
| 1286 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1287 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 1288 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1289 | if (DVar.RefExpr) { |
| 1290 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1291 | << getOpenMPClauseName(DVar.CKind); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1292 | } else { |
| 1293 | Diag(VD->getLocation(), diag::note_omp_predetermined_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1294 | << getOpenMPClauseName(DVar.CKind); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1295 | } |
| 1296 | continue; |
| 1297 | } |
| 1298 | |
| 1299 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1300 | Vars.push_back(DE); |
| 1301 | } |
| 1302 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1303 | if (Vars.empty()) |
| 1304 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1305 | |
| 1306 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 1307 | } |
| 1308 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1309 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 1310 | SourceLocation StartLoc, |
| 1311 | SourceLocation LParenLoc, |
| 1312 | SourceLocation EndLoc) { |
| 1313 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1314 | for (auto &RefExpr : VarList) { |
| 1315 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 1316 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1317 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1318 | Vars.push_back(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1319 | continue; |
| 1320 | } |
| 1321 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1322 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1323 | // OpenMP [2.1, C/C++] |
| 1324 | // A list item is a variable name. |
| 1325 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 1326 | // A variable that is part of another variable (as an array or |
| 1327 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1328 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1329 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1330 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1331 | continue; |
| 1332 | } |
| 1333 | Decl *D = DE->getDecl(); |
| 1334 | VarDecl *VD = cast<VarDecl>(D); |
| 1335 | |
| 1336 | QualType Type = VD->getType(); |
| 1337 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 1338 | // It will be analyzed later. |
| 1339 | Vars.push_back(DE); |
| 1340 | continue; |
| 1341 | } |
| 1342 | |
| 1343 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 1344 | // A variable that appears in a private clause must not have an incomplete |
| 1345 | // type or a reference type. |
| 1346 | if (RequireCompleteType(ELoc, Type, |
| 1347 | diag::err_omp_firstprivate_incomplete_type)) { |
| 1348 | continue; |
| 1349 | } |
| 1350 | if (Type->isReferenceType()) { |
| 1351 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1352 | << getOpenMPClauseName(OMPC_firstprivate) << Type; |
| 1353 | bool IsDecl = |
| 1354 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1355 | Diag(VD->getLocation(), |
| 1356 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1357 | << VD; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1358 | continue; |
| 1359 | } |
| 1360 | |
| 1361 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 1362 | // A variable of class type (or array thereof) that appears in a private |
| 1363 | // clause requires an accesible, unambiguous copy constructor for the |
| 1364 | // class type. |
| 1365 | Type = Context.getBaseElementType(Type); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1366 | CXXRecordDecl *RD = getLangOpts().CPlusPlus |
| 1367 | ? Type.getNonReferenceType()->getAsCXXRecordDecl() |
| 1368 | : nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1369 | if (RD) { |
| 1370 | CXXConstructorDecl *CD = LookupCopyingConstructor(RD, 0); |
| 1371 | PartialDiagnostic PD = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1372 | PartialDiagnostic(PartialDiagnostic::NullDiagnostic()); |
| 1373 | if (!CD || CheckConstructorAccess( |
| 1374 | ELoc, CD, InitializedEntity::InitializeTemporary(Type), |
| 1375 | CD->getAccess(), PD) == AR_inaccessible || |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1376 | CD->isDeleted()) { |
| 1377 | Diag(ELoc, diag::err_omp_required_method) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1378 | << getOpenMPClauseName(OMPC_firstprivate) << 1; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1379 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 1380 | VarDecl::DeclarationOnly; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1381 | Diag(VD->getLocation(), |
| 1382 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1383 | << VD; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1384 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 1385 | continue; |
| 1386 | } |
| 1387 | MarkFunctionReferenced(ELoc, CD); |
| 1388 | DiagnoseUseOfDecl(CD, ELoc); |
| 1389 | |
| 1390 | CXXDestructorDecl *DD = RD->getDestructor(); |
| 1391 | if (DD) { |
| 1392 | if (CheckDestructorAccess(ELoc, DD, PD) == AR_inaccessible || |
| 1393 | DD->isDeleted()) { |
| 1394 | Diag(ELoc, diag::err_omp_required_method) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1395 | << getOpenMPClauseName(OMPC_firstprivate) << 4; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1396 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 1397 | VarDecl::DeclarationOnly; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1398 | Diag(VD->getLocation(), |
| 1399 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1400 | << VD; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1401 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 1402 | continue; |
| 1403 | } |
| 1404 | MarkFunctionReferenced(ELoc, DD); |
| 1405 | DiagnoseUseOfDecl(DD, ELoc); |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | // If StartLoc and EndLoc are invalid - this is an implicit firstprivate |
| 1410 | // variable and it was checked already. |
| 1411 | if (StartLoc.isValid() && EndLoc.isValid()) { |
| 1412 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD); |
| 1413 | Type = Type.getNonReferenceType().getCanonicalType(); |
| 1414 | bool IsConstant = Type.isConstant(Context); |
| 1415 | Type = Context.getBaseElementType(Type); |
| 1416 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 1417 | // A list item that specifies a given variable may not appear in more |
| 1418 | // than one clause on the same directive, except that a variable may be |
| 1419 | // specified in both firstprivate and lastprivate clauses. |
| 1420 | // TODO: add processing for lastprivate. |
| 1421 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
| 1422 | DVar.RefExpr) { |
| 1423 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1424 | << getOpenMPClauseName(DVar.CKind) |
| 1425 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1426 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1427 | << getOpenMPClauseName(DVar.CKind); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1428 | continue; |
| 1429 | } |
| 1430 | |
| 1431 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1432 | // in a Construct] |
| 1433 | // Variables with the predetermined data-sharing attributes may not be |
| 1434 | // listed in data-sharing attributes clauses, except for the cases |
| 1435 | // listed below. For these exceptions only, listing a predetermined |
| 1436 | // variable in a data-sharing attribute clause is allowed and overrides |
| 1437 | // the variable's predetermined data-sharing attributes. |
| 1438 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1439 | // in a Construct, C/C++, p.2] |
| 1440 | // Variables with const-qualified type having no mutable member may be |
| 1441 | // listed in a firstprivate clause, even if they are static data members. |
| 1442 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 1443 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 1444 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1445 | << getOpenMPClauseName(DVar.CKind) |
| 1446 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1447 | Diag(VD->getLocation(), diag::note_omp_predetermined_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1448 | << getOpenMPClauseName(DVar.CKind); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1449 | continue; |
| 1450 | } |
| 1451 | |
| 1452 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 1453 | // A list item that is private within a parallel region must not appear |
| 1454 | // in a firstprivate clause on a worksharing construct if any of the |
| 1455 | // worksharing regions arising from the worksharing construct ever bind |
| 1456 | // to any of the parallel regions arising from the parallel construct. |
| 1457 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 1458 | // A list item that appears in a reduction clause of a parallel construct |
| 1459 | // must not appear in a firstprivate clause on a worksharing or task |
| 1460 | // construct if any of the worksharing or task regions arising from the |
| 1461 | // worksharing or task construct ever bind to any of the parallel regions |
| 1462 | // arising from the parallel construct. |
| 1463 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 1464 | // A list item that appears in a reduction clause in worksharing |
| 1465 | // construct must not appear in a firstprivate clause in a task construct |
| 1466 | // encountered during execution of any of the worksharing regions arising |
| 1467 | // from the worksharing construct. |
| 1468 | // TODO: |
| 1469 | } |
| 1470 | |
| 1471 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 1472 | Vars.push_back(DE); |
| 1473 | } |
| 1474 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1475 | if (Vars.empty()) |
| 1476 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1477 | |
| 1478 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 1479 | Vars); |
| 1480 | } |
| 1481 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1482 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 1483 | SourceLocation StartLoc, |
| 1484 | SourceLocation LParenLoc, |
| 1485 | SourceLocation EndLoc) { |
| 1486 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1487 | for (auto &RefExpr : VarList) { |
| 1488 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 1489 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1490 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1491 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1492 | continue; |
| 1493 | } |
| 1494 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1495 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1496 | // OpenMP [2.1, C/C++] |
| 1497 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1498 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 1499 | // A variable that is part of another variable (as an array or structure |
| 1500 | // element) cannot appear in a shared unless it is a static data member |
| 1501 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1502 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1503 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1504 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1505 | continue; |
| 1506 | } |
| 1507 | Decl *D = DE->getDecl(); |
| 1508 | VarDecl *VD = cast<VarDecl>(D); |
| 1509 | |
| 1510 | QualType Type = VD->getType(); |
| 1511 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 1512 | // It will be analyzed later. |
| 1513 | Vars.push_back(DE); |
| 1514 | continue; |
| 1515 | } |
| 1516 | |
| 1517 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1518 | // in a Construct] |
| 1519 | // Variables with the predetermined data-sharing attributes may not be |
| 1520 | // listed in data-sharing attributes clauses, except for the cases |
| 1521 | // listed below. For these exceptions only, listing a predetermined |
| 1522 | // variable in a data-sharing attribute clause is allowed and overrides |
| 1523 | // the variable's predetermined data-sharing attributes. |
| 1524 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1525 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 1526 | DVar.RefExpr) { |
| 1527 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 1528 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1529 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1530 | << getOpenMPClauseName(DVar.CKind); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1531 | continue; |
| 1532 | } |
| 1533 | |
| 1534 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 1535 | Vars.push_back(DE); |
| 1536 | } |
| 1537 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1538 | if (Vars.empty()) |
| 1539 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1540 | |
| 1541 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 1542 | } |
| 1543 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1544 | OMPClause *Sema::ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 1545 | SourceLocation StartLoc, |
| 1546 | SourceLocation LParenLoc, |
| 1547 | SourceLocation ColonLoc, |
| 1548 | SourceLocation EndLoc) { |
| 1549 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1550 | for (auto &RefExpr : VarList) { |
| 1551 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 1552 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1553 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1554 | Vars.push_back(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1555 | continue; |
| 1556 | } |
| 1557 | |
| 1558 | // OpenMP [2.14.3.7, linear clause] |
| 1559 | // A list item that appears in a linear clause is subject to the private |
| 1560 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 1561 | // noted. In addition, the value of the new list item on each iteration |
| 1562 | // of the associated loop(s) corresponds to the value of the original |
| 1563 | // list item before entering the construct plus the logical number of |
| 1564 | // the iteration times linear-step. |
| 1565 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1566 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1567 | // OpenMP [2.1, C/C++] |
| 1568 | // A list item is a variable name. |
| 1569 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 1570 | // A variable that is part of another variable (as an array or |
| 1571 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1572 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1573 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1574 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1575 | continue; |
| 1576 | } |
| 1577 | |
| 1578 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1579 | |
| 1580 | // OpenMP [2.14.3.7, linear clause] |
| 1581 | // A list-item cannot appear in more than one linear clause. |
| 1582 | // A list-item that appears in a linear clause cannot appear in any |
| 1583 | // other data-sharing attribute clause. |
| 1584 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD); |
| 1585 | if (DVar.RefExpr) { |
| 1586 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 1587 | << getOpenMPClauseName(OMPC_linear); |
| 1588 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1589 | << getOpenMPClauseName(DVar.CKind); |
| 1590 | continue; |
| 1591 | } |
| 1592 | |
| 1593 | QualType QType = VD->getType(); |
| 1594 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1595 | // It will be analyzed later. |
| 1596 | Vars.push_back(DE); |
| 1597 | continue; |
| 1598 | } |
| 1599 | |
| 1600 | // A variable must not have an incomplete type or a reference type. |
| 1601 | if (RequireCompleteType(ELoc, QType, |
| 1602 | diag::err_omp_linear_incomplete_type)) { |
| 1603 | continue; |
| 1604 | } |
| 1605 | if (QType->isReferenceType()) { |
| 1606 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 1607 | << getOpenMPClauseName(OMPC_linear) << QType; |
| 1608 | bool IsDecl = |
| 1609 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1610 | Diag(VD->getLocation(), |
| 1611 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1612 | << VD; |
| 1613 | continue; |
| 1614 | } |
| 1615 | |
| 1616 | // A list item must not be const-qualified. |
| 1617 | if (QType.isConstant(Context)) { |
| 1618 | Diag(ELoc, diag::err_omp_const_variable) |
| 1619 | << getOpenMPClauseName(OMPC_linear); |
| 1620 | bool IsDecl = |
| 1621 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1622 | Diag(VD->getLocation(), |
| 1623 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1624 | << VD; |
| 1625 | continue; |
| 1626 | } |
| 1627 | |
| 1628 | // A list item must be of integral or pointer type. |
| 1629 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 1630 | const Type *Ty = QType.getTypePtrOrNull(); |
| 1631 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 1632 | !Ty->isPointerType())) { |
| 1633 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 1634 | bool IsDecl = |
| 1635 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1636 | Diag(VD->getLocation(), |
| 1637 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1638 | << VD; |
| 1639 | continue; |
| 1640 | } |
| 1641 | |
| 1642 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 1643 | Vars.push_back(DE); |
| 1644 | } |
| 1645 | |
| 1646 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1647 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1648 | |
| 1649 | Expr *StepExpr = Step; |
| 1650 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 1651 | !Step->isInstantiationDependent() && |
| 1652 | !Step->containsUnexpandedParameterPack()) { |
| 1653 | SourceLocation StepLoc = Step->getLocStart(); |
| 1654 | ExprResult Val = PerformImplicitIntegerConversion(StepLoc, Step); |
| 1655 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1656 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1657 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1658 | |
| 1659 | // Warn about zero linear step (it would be probably better specified as |
| 1660 | // making corresponding variables 'const'). |
| 1661 | llvm::APSInt Result; |
| 1662 | if (StepExpr->isIntegerConstantExpr(Result, Context) && |
| 1663 | !Result.isNegative() && !Result.isStrictlyPositive()) |
| 1664 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 1665 | << (Vars.size() > 1); |
| 1666 | } |
| 1667 | |
| 1668 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 1669 | Vars, StepExpr); |
| 1670 | } |
| 1671 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame^] | 1672 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 1673 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 1674 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 1675 | |
| 1676 | SmallVector<Expr *, 8> Vars; |
| 1677 | for (auto &RefExpr : VarList) { |
| 1678 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 1679 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 1680 | // It will be analyzed later. |
| 1681 | Vars.push_back(RefExpr); |
| 1682 | continue; |
| 1683 | } |
| 1684 | |
| 1685 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 1686 | // OpenMP [2.1, C/C++] |
| 1687 | // A list item is a variable name. |
| 1688 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 1689 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 1690 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 1691 | continue; |
| 1692 | } |
| 1693 | |
| 1694 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1695 | |
| 1696 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 1697 | // The type of list items appearing in the aligned clause must be |
| 1698 | // array, pointer, reference to array, or reference to pointer. |
| 1699 | QualType QType = DE->getType() |
| 1700 | .getNonReferenceType() |
| 1701 | .getUnqualifiedType() |
| 1702 | .getCanonicalType(); |
| 1703 | const Type *Ty = QType.getTypePtrOrNull(); |
| 1704 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 1705 | !Ty->isPointerType())) { |
| 1706 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 1707 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 1708 | bool IsDecl = |
| 1709 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1710 | Diag(VD->getLocation(), |
| 1711 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1712 | << VD; |
| 1713 | continue; |
| 1714 | } |
| 1715 | |
| 1716 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 1717 | // A list-item cannot appear in more than one aligned clause. |
| 1718 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 1719 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 1720 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1721 | << getOpenMPClauseName(OMPC_aligned); |
| 1722 | continue; |
| 1723 | } |
| 1724 | |
| 1725 | Vars.push_back(DE); |
| 1726 | } |
| 1727 | |
| 1728 | // OpenMP [2.8.1, simd construct, Description] |
| 1729 | // The parameter of the aligned clause, alignment, must be a constant |
| 1730 | // positive integer expression. |
| 1731 | // If no optional parameter is specified, implementation-defined default |
| 1732 | // alignments for SIMD instructions on the target platforms are assumed. |
| 1733 | if (Alignment != nullptr) { |
| 1734 | ExprResult AlignResult = |
| 1735 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 1736 | if (AlignResult.isInvalid()) |
| 1737 | return nullptr; |
| 1738 | Alignment = AlignResult.get(); |
| 1739 | } |
| 1740 | if (Vars.empty()) |
| 1741 | return nullptr; |
| 1742 | |
| 1743 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 1744 | EndLoc, Vars, Alignment); |
| 1745 | } |
| 1746 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1747 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 1748 | SourceLocation StartLoc, |
| 1749 | SourceLocation LParenLoc, |
| 1750 | SourceLocation EndLoc) { |
| 1751 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1752 | for (auto &RefExpr : VarList) { |
| 1753 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 1754 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1755 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1756 | Vars.push_back(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1757 | continue; |
| 1758 | } |
| 1759 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1760 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1761 | // OpenMP [2.1, C/C++] |
| 1762 | // A list item is a variable name. |
| 1763 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 1764 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1765 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1766 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1767 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1768 | continue; |
| 1769 | } |
| 1770 | |
| 1771 | Decl *D = DE->getDecl(); |
| 1772 | VarDecl *VD = cast<VarDecl>(D); |
| 1773 | |
| 1774 | QualType Type = VD->getType(); |
| 1775 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 1776 | // It will be analyzed later. |
| 1777 | Vars.push_back(DE); |
| 1778 | continue; |
| 1779 | } |
| 1780 | |
| 1781 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 1782 | // A list item that appears in a copyin clause must be threadprivate. |
| 1783 | if (!DSAStack->isThreadPrivate(VD)) { |
| 1784 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1785 | << getOpenMPClauseName(OMPC_copyin) |
| 1786 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1787 | continue; |
| 1788 | } |
| 1789 | |
| 1790 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 1791 | // A variable of class type (or array thereof) that appears in a |
| 1792 | // copyin clause requires an accesible, unambiguous copy assignment |
| 1793 | // operator for the class type. |
| 1794 | Type = Context.getBaseElementType(Type); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1795 | CXXRecordDecl *RD = |
| 1796 | getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1797 | if (RD) { |
| 1798 | CXXMethodDecl *MD = LookupCopyingAssignment(RD, 0, false, 0); |
| 1799 | DeclAccessPair FoundDecl = DeclAccessPair::make(MD, MD->getAccess()); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1800 | if (!MD || CheckMemberAccess(ELoc, RD, FoundDecl) == AR_inaccessible || |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1801 | MD->isDeleted()) { |
| 1802 | Diag(ELoc, diag::err_omp_required_method) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1803 | << getOpenMPClauseName(OMPC_copyin) << 2; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1804 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 1805 | VarDecl::DeclarationOnly; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1806 | Diag(VD->getLocation(), |
| 1807 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1808 | << VD; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1809 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 1810 | continue; |
| 1811 | } |
| 1812 | MarkFunctionReferenced(ELoc, MD); |
| 1813 | DiagnoseUseOfDecl(MD, ELoc); |
| 1814 | } |
| 1815 | |
| 1816 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 1817 | Vars.push_back(DE); |
| 1818 | } |
| 1819 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1820 | if (Vars.empty()) |
| 1821 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1822 | |
| 1823 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 1824 | } |
| 1825 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1826 | #undef DSAStack |