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 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 42 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 43 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 44 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 45 | bool operator()(T Kind) { |
| 46 | for (auto KindEl : Arr) |
| 47 | if (KindEl == Kind) |
| 48 | return true; |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | private: |
| 53 | ArrayRef<T> Arr; |
| 54 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 55 | struct MatchesAlways { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 56 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 57 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 61 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 62 | |
| 63 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 64 | /// clauses and their data-sharing attributes. |
| 65 | class DSAStackTy { |
| 66 | public: |
| 67 | struct DSAVarData { |
| 68 | OpenMPDirectiveKind DKind; |
| 69 | OpenMPClauseKind CKind; |
| 70 | DeclRefExpr *RefExpr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 71 | SourceLocation ImplicitDSALoc; |
| 72 | DSAVarData() |
| 73 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
| 74 | ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 75 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 76 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 77 | private: |
| 78 | struct DSAInfo { |
| 79 | OpenMPClauseKind Attributes; |
| 80 | DeclRefExpr *RefExpr; |
| 81 | }; |
| 82 | typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 83 | typedef llvm::SmallDenseMap<VarDecl *, DeclRefExpr *, 64> AlignedMapTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 84 | |
| 85 | struct SharingMapTy { |
| 86 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 87 | AlignedMapTy AlignedMap; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 88 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 89 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 90 | OpenMPDirectiveKind Directive; |
| 91 | DeclarationNameInfo DirectiveName; |
| 92 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 93 | SourceLocation ConstructLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 94 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 95 | Scope *CurScope, SourceLocation Loc) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 96 | : SharingMap(), AlignedMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 97 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
| 98 | ConstructLoc(Loc) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 99 | SharingMapTy() |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 100 | : SharingMap(), AlignedMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 101 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
| 102 | ConstructLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 106 | |
| 107 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 108 | StackTy Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 109 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 110 | |
| 111 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 112 | |
| 113 | DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 114 | |
| 115 | /// \brief Checks if the variable is a local for OpenMP region. |
| 116 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 117 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 118 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 119 | explicit DSAStackTy(Sema &S) : Stack(1), SemaRef(S) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 120 | |
| 121 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 122 | Scope *CurScope, SourceLocation Loc) { |
| 123 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 124 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | void pop() { |
| 128 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 129 | Stack.pop_back(); |
| 130 | } |
| 131 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 132 | /// \brief If 'aligned' declaration for given variable \a D was not seen yet, |
Alp Toker | 15e62a3 | 2014-06-06 12:02:07 +0000 | [diff] [blame] | 133 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 134 | /// for diagnostics. |
| 135 | DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE); |
| 136 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 137 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
| 138 | void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); |
| 139 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 140 | /// \brief Returns data sharing attributes from top of the stack for the |
| 141 | /// specified declaration. |
| 142 | DSAVarData getTopDSA(VarDecl *D); |
| 143 | /// \brief Returns data-sharing attributes for the specified declaration. |
| 144 | DSAVarData getImplicitDSA(VarDecl *D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 145 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 146 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 147 | /// predicate. |
| 148 | template <class ClausesPredicate, class DirectivesPredicate> |
| 149 | DSAVarData hasDSA(VarDecl *D, ClausesPredicate CPred, |
| 150 | DirectivesPredicate DPred); |
| 151 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 152 | /// match specified \a CPred predicate in any innermost directive which |
| 153 | /// matches \a DPred predicate. |
| 154 | template <class ClausesPredicate, class DirectivesPredicate> |
| 155 | DSAVarData hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 156 | DirectivesPredicate DPred); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 157 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 158 | /// \brief Returns currently analyzed directive. |
| 159 | OpenMPDirectiveKind getCurrentDirective() const { |
| 160 | return Stack.back().Directive; |
| 161 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 162 | /// \brief Returns parent directive. |
| 163 | OpenMPDirectiveKind getParentDirective() const { |
| 164 | if (Stack.size() > 2) |
| 165 | return Stack[Stack.size() - 2].Directive; |
| 166 | return OMPD_unknown; |
| 167 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 168 | |
| 169 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 170 | void setDefaultDSANone(SourceLocation Loc) { |
| 171 | Stack.back().DefaultAttr = DSA_none; |
| 172 | Stack.back().DefaultAttrLoc = Loc; |
| 173 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 174 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 175 | void setDefaultDSAShared(SourceLocation Loc) { |
| 176 | Stack.back().DefaultAttr = DSA_shared; |
| 177 | Stack.back().DefaultAttrLoc = Loc; |
| 178 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 179 | |
| 180 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 181 | return Stack.back().DefaultAttr; |
| 182 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 183 | SourceLocation getDefaultDSALocation() const { |
| 184 | return Stack.back().DefaultAttrLoc; |
| 185 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 186 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 187 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 188 | bool isThreadPrivate(VarDecl *D) { |
| 189 | DSAVarData DVar = getTopDSA(D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 190 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 194 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 195 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 196 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 197 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 198 | |
| 199 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 200 | VarDecl *D) { |
| 201 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 202 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 203 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 204 | // in a region but not in construct] |
| 205 | // File-scope or namespace-scope variables referenced in called routines |
| 206 | // in the region are shared unless they appear in a threadprivate |
| 207 | // directive. |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 208 | if (!D->isFunctionOrMethodVarDecl()) |
| 209 | DVar.CKind = OMPC_shared; |
| 210 | |
| 211 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 212 | // in a region but not in construct] |
| 213 | // Variables with static storage duration that are declared in called |
| 214 | // routines in the region are shared. |
| 215 | if (D->hasGlobalStorage()) |
| 216 | DVar.CKind = OMPC_shared; |
| 217 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 218 | return DVar; |
| 219 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 220 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 221 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 222 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 223 | // in a Construct, C/C++, predetermined, p.1] |
| 224 | // Variables with automatic storage duration that are declared in a scope |
| 225 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 226 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 227 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 228 | DVar.CKind = OMPC_private; |
| 229 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 232 | // Explicitly specified attributes and local variables with predetermined |
| 233 | // attributes. |
| 234 | if (Iter->SharingMap.count(D)) { |
| 235 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 236 | DVar.CKind = Iter->SharingMap[D].Attributes; |
| 237 | return DVar; |
| 238 | } |
| 239 | |
| 240 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 241 | // in a Construct, C/C++, implicitly determined, p.1] |
| 242 | // In a parallel or task construct, the data-sharing attributes of these |
| 243 | // variables are determined by the default clause, if present. |
| 244 | switch (Iter->DefaultAttr) { |
| 245 | case DSA_shared: |
| 246 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 247 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 248 | return DVar; |
| 249 | case DSA_none: |
| 250 | return DVar; |
| 251 | case DSA_unspecified: |
| 252 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 253 | // in a Construct, implicitly determined, p.2] |
| 254 | // In a parallel construct, if no default clause is present, these |
| 255 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 256 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 257 | if (isOpenMPParallelDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 258 | DVar.CKind = OMPC_shared; |
| 259 | return DVar; |
| 260 | } |
| 261 | |
| 262 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 263 | // in a Construct, implicitly determined, p.4] |
| 264 | // In a task construct, if no default clause is present, a variable that in |
| 265 | // the enclosing context is determined to be shared by all implicit tasks |
| 266 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 267 | if (DVar.DKind == OMPD_task) { |
| 268 | DSAVarData DVarTemp; |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 269 | for (StackTy::reverse_iterator I = std::next(Iter), |
| 270 | EE = std::prev(Stack.rend()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 271 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 272 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 273 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 274 | // in a Construct, implicitly determined, p.6] |
| 275 | // In a task construct, if no default clause is present, a variable |
| 276 | // whose data-sharing attribute is not determined by the rules above is |
| 277 | // firstprivate. |
| 278 | DVarTemp = getDSA(I, D); |
| 279 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 280 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 281 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 282 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 283 | return DVar; |
| 284 | } |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 285 | if (isOpenMPParallelDirective(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 286 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 287 | } |
| 288 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 289 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 290 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 291 | return DVar; |
| 292 | } |
| 293 | } |
| 294 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 295 | // in a Construct, implicitly determined, p.3] |
| 296 | // For constructs other than task, if no default clause is present, these |
| 297 | // variables inherit their data-sharing attributes from the enclosing |
| 298 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 299 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 302 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 303 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
| 304 | auto It = Stack.back().AlignedMap.find(D); |
| 305 | if (It == Stack.back().AlignedMap.end()) { |
| 306 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 307 | Stack.back().AlignedMap[D] = NewDE; |
| 308 | return nullptr; |
| 309 | } else { |
| 310 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 311 | return It->second; |
| 312 | } |
| 313 | return nullptr; |
| 314 | } |
| 315 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 316 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
| 317 | if (A == OMPC_threadprivate) { |
| 318 | Stack[0].SharingMap[D].Attributes = A; |
| 319 | Stack[0].SharingMap[D].RefExpr = E; |
| 320 | } else { |
| 321 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 322 | Stack.back().SharingMap[D].Attributes = A; |
| 323 | Stack.back().SharingMap[D].RefExpr = E; |
| 324 | } |
| 325 | } |
| 326 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 327 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 328 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 329 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 330 | Scope *TopScope = nullptr; |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 331 | while (I != E && !isOpenMPParallelDirective(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 332 | ++I; |
| 333 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 334 | if (I == E) |
| 335 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 336 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 337 | Scope *CurScope = getCurScope(); |
| 338 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 339 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 340 | } |
| 341 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 342 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 343 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D) { |
| 347 | DSAVarData DVar; |
| 348 | |
| 349 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 350 | // in a Construct, C/C++, predetermined, p.1] |
| 351 | // Variables appearing in threadprivate directives are threadprivate. |
| 352 | if (D->getTLSKind() != VarDecl::TLS_None) { |
| 353 | DVar.CKind = OMPC_threadprivate; |
| 354 | return DVar; |
| 355 | } |
| 356 | if (Stack[0].SharingMap.count(D)) { |
| 357 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 358 | DVar.CKind = OMPC_threadprivate; |
| 359 | return DVar; |
| 360 | } |
| 361 | |
| 362 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 363 | // in a Construct, C/C++, predetermined, p.1] |
| 364 | // Variables with automatic storage duration that are declared in a scope |
| 365 | // inside the construct are private. |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 366 | OpenMPDirectiveKind Kind = getCurrentDirective(); |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 367 | if (!isOpenMPParallelDirective(Kind)) { |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 368 | if (isOpenMPLocal(D, std::next(Stack.rbegin())) && D->isLocalVarDecl() && |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 369 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 370 | DVar.CKind = OMPC_private; |
| 371 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 372 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 376 | // in a Construct, C/C++, predetermined, p.4] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 377 | // Static data members are shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 378 | if (D->isStaticDataMember()) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 379 | // Variables with const-qualified type having no mutable member may be |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 380 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 381 | DSAVarData DVarTemp = |
| 382 | hasDSA(D, MatchesAnyClause(OMPC_firstprivate), MatchesAlways()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 383 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 384 | return DVar; |
| 385 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 386 | DVar.CKind = OMPC_shared; |
| 387 | return DVar; |
| 388 | } |
| 389 | |
| 390 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 391 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 392 | while (Type->isArrayType()) { |
| 393 | QualType ElemType = cast<ArrayType>(Type.getTypePtr())->getElementType(); |
| 394 | Type = ElemType.getNonReferenceType().getCanonicalType(); |
| 395 | } |
| 396 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 397 | // in a Construct, C/C++, predetermined, p.6] |
| 398 | // Variables with const qualified type having no mutable member are |
| 399 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 400 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 401 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 402 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 403 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 404 | // Variables with const-qualified type having no mutable member may be |
| 405 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 406 | DSAVarData DVarTemp = |
| 407 | hasDSA(D, MatchesAnyClause(OMPC_firstprivate), MatchesAlways()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 408 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 409 | return DVar; |
| 410 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 411 | DVar.CKind = OMPC_shared; |
| 412 | return DVar; |
| 413 | } |
| 414 | |
| 415 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 416 | // in a Construct, C/C++, predetermined, p.7] |
| 417 | // Variables with static storage duration that are declared in a scope |
| 418 | // inside the construct are shared. |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 419 | if (D->isStaticLocal()) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 420 | DVar.CKind = OMPC_shared; |
| 421 | return DVar; |
| 422 | } |
| 423 | |
| 424 | // Explicitly specified attributes and local variables with predetermined |
| 425 | // attributes. |
| 426 | if (Stack.back().SharingMap.count(D)) { |
| 427 | DVar.RefExpr = Stack.back().SharingMap[D].RefExpr; |
| 428 | DVar.CKind = Stack.back().SharingMap[D].Attributes; |
| 429 | } |
| 430 | |
| 431 | return DVar; |
| 432 | } |
| 433 | |
| 434 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D) { |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 435 | return getDSA(std::next(Stack.rbegin()), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 438 | template <class ClausesPredicate, class DirectivesPredicate> |
| 439 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
| 440 | DirectivesPredicate DPred) { |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 441 | for (StackTy::reverse_iterator I = std::next(Stack.rbegin()), |
| 442 | E = std::prev(Stack.rend()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 443 | I != E; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 444 | if (!DPred(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 445 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 446 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 447 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 448 | return DVar; |
| 449 | } |
| 450 | return DSAVarData(); |
| 451 | } |
| 452 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 453 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 454 | DSAStackTy::DSAVarData DSAStackTy::hasInnermostDSA(VarDecl *D, |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 455 | ClausesPredicate CPred, |
| 456 | DirectivesPredicate DPred) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 457 | for (auto I = Stack.rbegin(), EE = std::prev(Stack.rend()); I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 458 | if (!DPred(I->Directive)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 459 | continue; |
| 460 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 461 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 462 | return DVar; |
| 463 | return DSAVarData(); |
| 464 | } |
| 465 | return DSAVarData(); |
| 466 | } |
| 467 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 468 | void Sema::InitDataSharingAttributesStack() { |
| 469 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 470 | } |
| 471 | |
| 472 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 473 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 474 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 475 | |
| 476 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 477 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 478 | Scope *CurScope, SourceLocation Loc) { |
| 479 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 480 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 481 | } |
| 482 | |
| 483 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 484 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 485 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 486 | // clause requires an accessible, unambiguous default constructor for the |
| 487 | // class type, unless the list item is also specified in a firstprivate |
| 488 | // clause. |
| 489 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
| 490 | for (auto C : D->clauses()) { |
| 491 | if (auto Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 492 | for (auto VarRef : Clause->varlists()) { |
| 493 | if (VarRef->isValueDependent() || VarRef->isTypeDependent()) |
| 494 | continue; |
| 495 | auto VD = cast<VarDecl>(cast<DeclRefExpr>(VarRef)->getDecl()); |
| 496 | auto DVar = DSAStack->getTopDSA(VD); |
| 497 | if (DVar.CKind == OMPC_lastprivate) { |
| 498 | SourceLocation ELoc = VarRef->getExprLoc(); |
| 499 | auto Type = VarRef->getType(); |
| 500 | if (Type->isArrayType()) |
| 501 | Type = QualType(Type->getArrayElementTypeNoTypeQual(), 0); |
| 502 | CXXRecordDecl *RD = |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 503 | getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
| 504 | // FIXME This code must be replaced by actual constructing of the |
| 505 | // lastprivate variable. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 506 | if (RD) { |
| 507 | CXXConstructorDecl *CD = LookupDefaultConstructor(RD); |
| 508 | PartialDiagnostic PD = |
| 509 | PartialDiagnostic(PartialDiagnostic::NullDiagnostic()); |
| 510 | if (!CD || |
| 511 | CheckConstructorAccess( |
| 512 | ELoc, CD, InitializedEntity::InitializeTemporary(Type), |
| 513 | CD->getAccess(), PD) == AR_inaccessible || |
| 514 | CD->isDeleted()) { |
| 515 | Diag(ELoc, diag::err_omp_required_method) |
| 516 | << getOpenMPClauseName(OMPC_lastprivate) << 0; |
| 517 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 518 | VarDecl::DeclarationOnly; |
| 519 | Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl |
| 520 | : diag::note_defined_here) |
| 521 | << VD; |
| 522 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 523 | continue; |
| 524 | } |
| 525 | MarkFunctionReferenced(ELoc, CD); |
| 526 | DiagnoseUseOfDecl(CD, ELoc); |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 534 | DSAStack->pop(); |
| 535 | DiscardCleanupsInEvaluationContext(); |
| 536 | PopExpressionEvaluationContext(); |
| 537 | } |
| 538 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 539 | namespace { |
| 540 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 541 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 542 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 543 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 544 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 545 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 546 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 547 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 548 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 549 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 550 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 551 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 552 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 553 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 554 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 555 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 556 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 557 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 558 | |
| 559 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 560 | CXXScopeSpec &ScopeSpec, |
| 561 | const DeclarationNameInfo &Id) { |
| 562 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 563 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 564 | |
| 565 | if (Lookup.isAmbiguous()) |
| 566 | return ExprError(); |
| 567 | |
| 568 | VarDecl *VD; |
| 569 | if (!Lookup.isSingleResult()) { |
| 570 | VarDeclFilterCCC Validator(*this); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 571 | if (TypoCorrection Corrected = |
| 572 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, Validator, |
| 573 | CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 574 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 575 | PDiag(Lookup.empty() |
| 576 | ? diag::err_undeclared_var_use_suggest |
| 577 | : diag::err_omp_expected_var_arg_suggest) |
| 578 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 579 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 580 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 581 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 582 | : diag::err_omp_expected_var_arg) |
| 583 | << Id.getName(); |
| 584 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 585 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 586 | } else { |
| 587 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 588 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 589 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 590 | return ExprError(); |
| 591 | } |
| 592 | } |
| 593 | Lookup.suppressDiagnostics(); |
| 594 | |
| 595 | // OpenMP [2.9.2, Syntax, C/C++] |
| 596 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 597 | if (!VD->hasGlobalStorage()) { |
| 598 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 599 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 600 | bool IsDecl = |
| 601 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 602 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 603 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 604 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 605 | return ExprError(); |
| 606 | } |
| 607 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 608 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 609 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 610 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 611 | // A threadprivate directive for file-scope variables must appear outside |
| 612 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 613 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 614 | !getCurLexicalContext()->isTranslationUnit()) { |
| 615 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 616 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 617 | bool IsDecl = |
| 618 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 619 | Diag(VD->getLocation(), |
| 620 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 621 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 622 | return ExprError(); |
| 623 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 624 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 625 | // A threadprivate directive for static class member variables must appear |
| 626 | // in the class definition, in the same scope in which the member |
| 627 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 628 | if (CanonicalVD->isStaticDataMember() && |
| 629 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 630 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 631 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 632 | bool IsDecl = |
| 633 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 634 | Diag(VD->getLocation(), |
| 635 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 636 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 637 | return ExprError(); |
| 638 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 639 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 640 | // A threadprivate directive for namespace-scope variables must appear |
| 641 | // outside any definition or declaration other than the namespace |
| 642 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 643 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 644 | (!getCurLexicalContext()->isFileContext() || |
| 645 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 646 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 647 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 648 | bool IsDecl = |
| 649 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 650 | Diag(VD->getLocation(), |
| 651 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 652 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 653 | return ExprError(); |
| 654 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 655 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 656 | // A threadprivate directive for static block-scope variables must appear |
| 657 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 658 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 659 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 660 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 661 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 662 | bool IsDecl = |
| 663 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 664 | Diag(VD->getLocation(), |
| 665 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 666 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 667 | return ExprError(); |
| 668 | } |
| 669 | |
| 670 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 671 | // A threadprivate directive must lexically precede all references to any |
| 672 | // of the variables in its list. |
| 673 | if (VD->isUsed()) { |
| 674 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 675 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 676 | return ExprError(); |
| 677 | } |
| 678 | |
| 679 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 680 | ExprResult DE = BuildDeclRefExpr(VD, ExprType, VK_LValue, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 681 | return DE; |
| 682 | } |
| 683 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 684 | Sema::DeclGroupPtrTy |
| 685 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 686 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 687 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 688 | CurContext->addDecl(D); |
| 689 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 690 | } |
| 691 | return DeclGroupPtrTy(); |
| 692 | } |
| 693 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 694 | namespace { |
| 695 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 696 | Sema &SemaRef; |
| 697 | |
| 698 | public: |
| 699 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 700 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 701 | if (VD->hasLocalStorage()) { |
| 702 | SemaRef.Diag(E->getLocStart(), |
| 703 | diag::err_omp_local_var_in_threadprivate_init) |
| 704 | << E->getSourceRange(); |
| 705 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 706 | << VD << VD->getSourceRange(); |
| 707 | return true; |
| 708 | } |
| 709 | } |
| 710 | return false; |
| 711 | } |
| 712 | bool VisitStmt(const Stmt *S) { |
| 713 | for (auto Child : S->children()) { |
| 714 | if (Child && Visit(Child)) |
| 715 | return true; |
| 716 | } |
| 717 | return false; |
| 718 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 719 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 720 | }; |
| 721 | } // namespace |
| 722 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 723 | OMPThreadPrivateDecl * |
| 724 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 725 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 726 | for (auto &RefExpr : VarList) { |
| 727 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 728 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 729 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 730 | |
| 731 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 732 | // A threadprivate variable must not have an incomplete type. |
| 733 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 734 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 735 | continue; |
| 736 | } |
| 737 | |
| 738 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 739 | // A threadprivate variable must not have a reference type. |
| 740 | if (VD->getType()->isReferenceType()) { |
| 741 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 742 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 743 | bool IsDecl = |
| 744 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 745 | Diag(VD->getLocation(), |
| 746 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 747 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 748 | continue; |
| 749 | } |
| 750 | |
Richard Smith | fd3834f | 2013-04-13 02:43:54 +0000 | [diff] [blame] | 751 | // Check if this is a TLS variable. |
| 752 | if (VD->getTLSKind()) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 753 | Diag(ILoc, diag::err_omp_var_thread_local) << VD; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 754 | bool IsDecl = |
| 755 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 756 | Diag(VD->getLocation(), |
| 757 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 758 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 759 | continue; |
| 760 | } |
| 761 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 762 | // Check if initial value of threadprivate variable reference variable with |
| 763 | // local storage (it is not supported by runtime). |
| 764 | if (auto Init = VD->getAnyInitializer()) { |
| 765 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 766 | if (Checker.Visit(Init)) |
| 767 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 770 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 771 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 772 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 773 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 774 | if (!Vars.empty()) { |
| 775 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 776 | Vars); |
| 777 | D->setAccess(AS_public); |
| 778 | } |
| 779 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 780 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 781 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 782 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 783 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 784 | bool IsLoopIterVar = false) { |
| 785 | if (DVar.RefExpr) { |
| 786 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 787 | << getOpenMPClauseName(DVar.CKind); |
| 788 | return; |
| 789 | } |
| 790 | enum { |
| 791 | PDSA_StaticMemberShared, |
| 792 | PDSA_StaticLocalVarShared, |
| 793 | PDSA_LoopIterVarPrivate, |
| 794 | PDSA_LoopIterVarLinear, |
| 795 | PDSA_LoopIterVarLastprivate, |
| 796 | PDSA_ConstVarShared, |
| 797 | PDSA_GlobalVarShared, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 798 | PDSA_LocalVarPrivate, |
| 799 | PDSA_Implicit |
| 800 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 801 | bool ReportHint = false; |
| 802 | if (IsLoopIterVar) { |
| 803 | if (DVar.CKind == OMPC_private) |
| 804 | Reason = PDSA_LoopIterVarPrivate; |
| 805 | else if (DVar.CKind == OMPC_lastprivate) |
| 806 | Reason = PDSA_LoopIterVarLastprivate; |
| 807 | else |
| 808 | Reason = PDSA_LoopIterVarLinear; |
| 809 | } else if (VD->isStaticLocal()) |
| 810 | Reason = PDSA_StaticLocalVarShared; |
| 811 | else if (VD->isStaticDataMember()) |
| 812 | Reason = PDSA_StaticMemberShared; |
| 813 | else if (VD->isFileVarDecl()) |
| 814 | Reason = PDSA_GlobalVarShared; |
| 815 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 816 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 817 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 818 | ReportHint = true; |
| 819 | Reason = PDSA_LocalVarPrivate; |
| 820 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 821 | if (Reason != PDSA_Implicit) { |
| 822 | SemaRef.Diag(VD->getLocation(), diag::note_omp_predetermined_dsa) |
| 823 | << Reason << ReportHint |
| 824 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 825 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 826 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 827 | << getOpenMPClauseName(DVar.CKind); |
| 828 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 831 | namespace { |
| 832 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 833 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 834 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 835 | bool ErrorFound; |
| 836 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 837 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 838 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 839 | public: |
| 840 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 841 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 842 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 843 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 844 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 845 | |
| 846 | SourceLocation ELoc = E->getExprLoc(); |
| 847 | |
| 848 | OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); |
| 849 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD); |
| 850 | if (DVar.CKind != OMPC_unknown) { |
| 851 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared && |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 852 | !Stack->isThreadPrivate(VD) && !DVar.RefExpr) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 853 | ImplicitFirstprivate.push_back(DVar.RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 854 | return; |
| 855 | } |
| 856 | // The default(none) clause requires that each variable that is referenced |
| 857 | // in the construct, and does not have a predetermined data-sharing |
| 858 | // attribute, must have its data-sharing attribute explicitly determined |
| 859 | // by being listed in a data-sharing attribute clause. |
| 860 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 861 | (isOpenMPParallelDirective(DKind) || DKind == OMPD_task)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 862 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 863 | SemaRef.Diag(ELoc, diag::err_omp_no_dsa_for_variable) << VD; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 864 | return; |
| 865 | } |
| 866 | |
| 867 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 868 | // A list item that appears in a reduction clause of the innermost |
| 869 | // enclosing worksharing or parallel construct may not be accessed in an |
| 870 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 871 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 872 | MatchesAlways()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 873 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 874 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 875 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 876 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 877 | return; |
| 878 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 879 | |
| 880 | // Define implicit data-sharing attributes for task. |
| 881 | DVar = Stack->getImplicitDSA(VD); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 882 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
| 883 | ImplicitFirstprivate.push_back(DVar.RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 887 | for (auto C : S->clauses()) |
| 888 | if (C) |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 889 | for (StmtRange R = C->children(); R; ++R) |
| 890 | if (Stmt *Child = *R) |
| 891 | Visit(Child); |
| 892 | } |
| 893 | void VisitStmt(Stmt *S) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 894 | for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I != E; |
| 895 | ++I) |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 896 | if (Stmt *Child = *I) |
| 897 | if (!isa<OMPExecutableDirective>(Child)) |
| 898 | Visit(Child); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 899 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 900 | |
| 901 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 902 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 903 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 904 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 905 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 906 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 907 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 908 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 909 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 910 | switch (DKind) { |
| 911 | case OMPD_parallel: { |
| 912 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 913 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 914 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 915 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 916 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 917 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 918 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 919 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 920 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 921 | break; |
| 922 | } |
| 923 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 924 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 925 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 926 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 927 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 928 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 929 | break; |
| 930 | } |
| 931 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 932 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 933 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 934 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 935 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 936 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 937 | break; |
| 938 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 939 | case OMPD_sections: { |
| 940 | Sema::CapturedParamNameType Params[] = { |
| 941 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 942 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 943 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 944 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 945 | break; |
| 946 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 947 | case OMPD_section: { |
| 948 | Sema::CapturedParamNameType Params[] = { |
| 949 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 950 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 951 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 952 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 953 | break; |
| 954 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 955 | case OMPD_single: { |
| 956 | Sema::CapturedParamNameType Params[] = { |
| 957 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 958 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 959 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 960 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 961 | break; |
| 962 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 963 | case OMPD_threadprivate: |
| 964 | case OMPD_task: |
| 965 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 966 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 967 | llvm_unreachable("Unknown OpenMP directive"); |
| 968 | } |
| 969 | } |
| 970 | |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 971 | bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 972 | OpenMPDirectiveKind CurrentRegion, |
| 973 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame^] | 974 | // Allowed nesting of constructs |
| 975 | // +------------------+-----------------+------------------------------------+ |
| 976 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 977 | // +------------------+-----------------+------------------------------------+ |
| 978 | // | parallel | parallel | * | |
| 979 | // | parallel | for | * | |
| 980 | // | parallel | simd | * | |
| 981 | // | parallel | sections | * | |
| 982 | // | parallel | section | + | |
| 983 | // | parallel | single | * | |
| 984 | // +------------------+-----------------+------------------------------------+ |
| 985 | // | for | parallel | * | |
| 986 | // | for | for | + | |
| 987 | // | for | simd | * | |
| 988 | // | for | sections | + | |
| 989 | // | for | section | + | |
| 990 | // | for | single | + | |
| 991 | // +------------------+-----------------+------------------------------------+ |
| 992 | // | simd | parallel | | |
| 993 | // | simd | for | | |
| 994 | // | simd | simd | | |
| 995 | // | simd | sections | | |
| 996 | // | simd | section | | |
| 997 | // | simd | single | | |
| 998 | // +------------------+-----------------+------------------------------------+ |
| 999 | // | sections | parallel | * | |
| 1000 | // | sections | for | + | |
| 1001 | // | sections | simd | * | |
| 1002 | // | sections | sections | + | |
| 1003 | // | sections | section | * | |
| 1004 | // | sections | single | + | |
| 1005 | // +------------------+-----------------+------------------------------------+ |
| 1006 | // | section | parallel | * | |
| 1007 | // | section | for | + | |
| 1008 | // | section | simd | * | |
| 1009 | // | section | sections | + | |
| 1010 | // | section | section | + | |
| 1011 | // | section | single | + | |
| 1012 | // +------------------+-----------------+------------------------------------+ |
| 1013 | // | single | parallel | * | |
| 1014 | // | single | for | + | |
| 1015 | // | single | simd | * | |
| 1016 | // | single | sections | + | |
| 1017 | // | single | section | + | |
| 1018 | // | single | single | + | |
| 1019 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1020 | if (Stack->getCurScope()) { |
| 1021 | auto ParentRegion = Stack->getParentDirective(); |
| 1022 | bool NestingProhibited = false; |
| 1023 | bool CloseNesting = true; |
| 1024 | bool ShouldBeInParallelRegion = false; |
| 1025 | if (isOpenMPSimdDirective(ParentRegion)) { |
| 1026 | // OpenMP [2.16, Nesting of Regions] |
| 1027 | // OpenMP constructs may not be nested inside a simd region. |
| 1028 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 1029 | return true; |
| 1030 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1031 | if (CurrentRegion == OMPD_section) { |
| 1032 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 1033 | // Orphaned section directives are prohibited. That is, the section |
| 1034 | // directives must appear within the sections construct and must not be |
| 1035 | // encountered elsewhere in the sections region. |
| 1036 | if (ParentRegion != OMPD_sections) { |
| 1037 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 1038 | << (ParentRegion != OMPD_unknown) |
| 1039 | << getOpenMPDirectiveName(ParentRegion); |
| 1040 | return true; |
| 1041 | } |
| 1042 | return false; |
| 1043 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1044 | if (isOpenMPWorksharingDirective(CurrentRegion) && |
| 1045 | !isOpenMPParallelDirective(CurrentRegion) && |
| 1046 | !isOpenMPSimdDirective(CurrentRegion)) { |
| 1047 | // OpenMP [2.16, Nesting of Regions] |
| 1048 | // A worksharing region may not be closely nested inside a worksharing, |
| 1049 | // explicit task, critical, ordered, atomic, or master region. |
| 1050 | // TODO |
| 1051 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) && |
| 1052 | !isOpenMPSimdDirective(ParentRegion); |
| 1053 | ShouldBeInParallelRegion = true; |
| 1054 | } |
| 1055 | if (NestingProhibited) { |
| 1056 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
| 1057 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << true |
| 1058 | << getOpenMPDirectiveName(CurrentRegion) << ShouldBeInParallelRegion; |
| 1059 | return true; |
| 1060 | } |
| 1061 | } |
| 1062 | return false; |
| 1063 | } |
| 1064 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1065 | StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, |
| 1066 | ArrayRef<OMPClause *> Clauses, |
| 1067 | Stmt *AStmt, |
| 1068 | SourceLocation StartLoc, |
| 1069 | SourceLocation EndLoc) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1070 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 1071 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1072 | StmtResult Res = StmtError(); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1073 | if (CheckNestingOfRegions(*this, DSAStack, Kind, StartLoc)) |
| 1074 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1075 | |
| 1076 | // Check default data sharing attributes for referenced variables. |
| 1077 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 1078 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 1079 | if (DSAChecker.isErrorFound()) |
| 1080 | return StmtError(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1081 | // Generate list of implicitly defined firstprivate variables. |
| 1082 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
| 1083 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
| 1084 | |
| 1085 | bool ErrorFound = false; |
| 1086 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1087 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 1088 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 1089 | SourceLocation(), SourceLocation())) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1090 | ClausesWithImplicit.push_back(Implicit); |
| 1091 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1092 | DSAChecker.getImplicitFirstprivate().size(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1093 | } else |
| 1094 | ErrorFound = true; |
| 1095 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1096 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1097 | switch (Kind) { |
| 1098 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1099 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1100 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1101 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1102 | case OMPD_simd: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1103 | Res = |
| 1104 | ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1105 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1106 | case OMPD_for: |
| 1107 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 1108 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1109 | case OMPD_sections: |
| 1110 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1111 | EndLoc); |
| 1112 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1113 | case OMPD_section: |
| 1114 | assert(ClausesWithImplicit.empty() && |
| 1115 | "No clauses is allowed for 'omp section' directive"); |
| 1116 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 1117 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1118 | case OMPD_single: |
| 1119 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1120 | EndLoc); |
| 1121 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1122 | case OMPD_threadprivate: |
| 1123 | case OMPD_task: |
| 1124 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1125 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1126 | llvm_unreachable("Unknown OpenMP directive"); |
| 1127 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1128 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1129 | if (ErrorFound) |
| 1130 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1131 | return Res; |
| 1132 | } |
| 1133 | |
| 1134 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 1135 | Stmt *AStmt, |
| 1136 | SourceLocation StartLoc, |
| 1137 | SourceLocation EndLoc) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1138 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 1139 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 1140 | // 1.2.2 OpenMP Language Terminology |
| 1141 | // Structured block - An executable statement with a single entry at the |
| 1142 | // top and a single exit at the bottom. |
| 1143 | // The point of exit cannot be a branch out of the structured block. |
| 1144 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 1145 | CS->getCapturedDecl()->setNothrow(); |
| 1146 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1147 | getCurFunction()->setHasBranchProtectedScope(); |
| 1148 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1149 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 1150 | AStmt); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1153 | namespace { |
| 1154 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 1155 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 1156 | /// for IR generation. |
| 1157 | class OpenMPIterationSpaceChecker { |
| 1158 | /// \brief Reference to Sema. |
| 1159 | Sema &SemaRef; |
| 1160 | /// \brief A location for diagnostics (when there is no some better location). |
| 1161 | SourceLocation DefaultLoc; |
| 1162 | /// \brief A location for diagnostics (when increment is not compatible). |
| 1163 | SourceLocation ConditionLoc; |
| 1164 | /// \brief A source location for referring to condition later. |
| 1165 | SourceRange ConditionSrcRange; |
| 1166 | /// \brief Loop variable. |
| 1167 | VarDecl *Var; |
| 1168 | /// \brief Lower bound (initializer for the var). |
| 1169 | Expr *LB; |
| 1170 | /// \brief Upper bound. |
| 1171 | Expr *UB; |
| 1172 | /// \brief Loop step (increment). |
| 1173 | Expr *Step; |
| 1174 | /// \brief This flag is true when condition is one of: |
| 1175 | /// Var < UB |
| 1176 | /// Var <= UB |
| 1177 | /// UB > Var |
| 1178 | /// UB >= Var |
| 1179 | bool TestIsLessOp; |
| 1180 | /// \brief This flag is true when condition is strict ( < or > ). |
| 1181 | bool TestIsStrictOp; |
| 1182 | /// \brief This flag is true when step is subtracted on each iteration. |
| 1183 | bool SubtractStep; |
| 1184 | |
| 1185 | public: |
| 1186 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 1187 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
| 1188 | ConditionSrcRange(SourceRange()), Var(nullptr), LB(nullptr), |
| 1189 | UB(nullptr), Step(nullptr), TestIsLessOp(false), TestIsStrictOp(false), |
| 1190 | SubtractStep(false) {} |
| 1191 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 1192 | /// variable - #Var and its initialization value - #LB. |
| 1193 | bool CheckInit(Stmt *S); |
| 1194 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 1195 | /// for less/greater and for strict/non-strict comparison. |
| 1196 | bool CheckCond(Expr *S); |
| 1197 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 1198 | /// does not conform, otherwise save loop step (#Step). |
| 1199 | bool CheckInc(Expr *S); |
| 1200 | /// \brief Return the loop counter variable. |
| 1201 | VarDecl *GetLoopVar() const { return Var; } |
| 1202 | /// \brief Return true if any expression is dependent. |
| 1203 | bool Dependent() const; |
| 1204 | |
| 1205 | private: |
| 1206 | /// \brief Check the right-hand side of an assignment in the increment |
| 1207 | /// expression. |
| 1208 | bool CheckIncRHS(Expr *RHS); |
| 1209 | /// \brief Helper to set loop counter variable and its initializer. |
| 1210 | bool SetVarAndLB(VarDecl *NewVar, Expr *NewLB); |
| 1211 | /// \brief Helper to set upper bound. |
| 1212 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, const SourceRange &SR, |
| 1213 | const SourceLocation &SL); |
| 1214 | /// \brief Helper to set loop increment. |
| 1215 | bool SetStep(Expr *NewStep, bool Subtract); |
| 1216 | }; |
| 1217 | |
| 1218 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 1219 | if (!Var) { |
| 1220 | assert(!LB && !UB && !Step); |
| 1221 | return false; |
| 1222 | } |
| 1223 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 1224 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 1225 | } |
| 1226 | |
| 1227 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, Expr *NewLB) { |
| 1228 | // State consistency checking to ensure correct usage. |
| 1229 | assert(Var == nullptr && LB == nullptr && UB == nullptr && Step == nullptr && |
| 1230 | !TestIsLessOp && !TestIsStrictOp); |
| 1231 | if (!NewVar || !NewLB) |
| 1232 | return true; |
| 1233 | Var = NewVar; |
| 1234 | LB = NewLB; |
| 1235 | return false; |
| 1236 | } |
| 1237 | |
| 1238 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
| 1239 | const SourceRange &SR, |
| 1240 | const SourceLocation &SL) { |
| 1241 | // State consistency checking to ensure correct usage. |
| 1242 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 1243 | !TestIsLessOp && !TestIsStrictOp); |
| 1244 | if (!NewUB) |
| 1245 | return true; |
| 1246 | UB = NewUB; |
| 1247 | TestIsLessOp = LessOp; |
| 1248 | TestIsStrictOp = StrictOp; |
| 1249 | ConditionSrcRange = SR; |
| 1250 | ConditionLoc = SL; |
| 1251 | return false; |
| 1252 | } |
| 1253 | |
| 1254 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 1255 | // State consistency checking to ensure correct usage. |
| 1256 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 1257 | if (!NewStep) |
| 1258 | return true; |
| 1259 | if (!NewStep->isValueDependent()) { |
| 1260 | // Check that the step is integer expression. |
| 1261 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 1262 | ExprResult Val = |
| 1263 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 1264 | if (Val.isInvalid()) |
| 1265 | return true; |
| 1266 | NewStep = Val.get(); |
| 1267 | |
| 1268 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 1269 | // If test-expr is of form var relational-op b and relational-op is < or |
| 1270 | // <= then incr-expr must cause var to increase on each iteration of the |
| 1271 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 1272 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 1273 | // the loop. |
| 1274 | // If test-expr is of form b relational-op var and relational-op is < or |
| 1275 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 1276 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 1277 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 1278 | // the loop. |
| 1279 | llvm::APSInt Result; |
| 1280 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 1281 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 1282 | bool IsConstNeg = |
| 1283 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
| 1284 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 1285 | if (UB && (IsConstZero || |
| 1286 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
| 1287 | : (!IsConstNeg || (IsUnsigned && !Subtract))))) { |
| 1288 | SemaRef.Diag(NewStep->getExprLoc(), |
| 1289 | diag::err_omp_loop_incr_not_compatible) |
| 1290 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 1291 | SemaRef.Diag(ConditionLoc, |
| 1292 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 1293 | << TestIsLessOp << ConditionSrcRange; |
| 1294 | return true; |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | Step = NewStep; |
| 1299 | SubtractStep = Subtract; |
| 1300 | return false; |
| 1301 | } |
| 1302 | |
| 1303 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S) { |
| 1304 | // Check init-expr for canonical loop form and save loop counter |
| 1305 | // variable - #Var and its initialization value - #LB. |
| 1306 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 1307 | // var = lb |
| 1308 | // integer-type var = lb |
| 1309 | // random-access-iterator-type var = lb |
| 1310 | // pointer-type var = lb |
| 1311 | // |
| 1312 | if (!S) { |
| 1313 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 1314 | return true; |
| 1315 | } |
| 1316 | if (Expr *E = dyn_cast<Expr>(S)) |
| 1317 | S = E->IgnoreParens(); |
| 1318 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 1319 | if (BO->getOpcode() == BO_Assign) |
| 1320 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
| 1321 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), BO->getLHS()); |
| 1322 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 1323 | if (DS->isSingleDecl()) { |
| 1324 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
| 1325 | if (Var->hasInit()) { |
| 1326 | // Accept non-canonical init form here but emit ext. warning. |
| 1327 | if (Var->getInitStyle() != VarDecl::CInit) |
| 1328 | SemaRef.Diag(S->getLocStart(), |
| 1329 | diag::ext_omp_loop_not_canonical_init) |
| 1330 | << S->getSourceRange(); |
| 1331 | return SetVarAndLB(Var, Var->getInit()); |
| 1332 | } |
| 1333 | } |
| 1334 | } |
| 1335 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 1336 | if (CE->getOperator() == OO_Equal) |
| 1337 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
| 1338 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), CE->getArg(1)); |
| 1339 | |
| 1340 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 1341 | << S->getSourceRange(); |
| 1342 | return true; |
| 1343 | } |
| 1344 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1345 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1346 | /// variable (which may be the loop variable) if possible. |
| 1347 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 1348 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 1349 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1350 | E = E->IgnoreParenImpCasts(); |
| 1351 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 1352 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
| 1353 | if (Ctor->isCopyConstructor() && CE->getNumArgs() == 1 && |
| 1354 | CE->getArg(0) != nullptr) |
| 1355 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 1356 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 1357 | if (!DRE) |
| 1358 | return nullptr; |
| 1359 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 1360 | } |
| 1361 | |
| 1362 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 1363 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 1364 | // less/greater and for strict/non-strict comparison. |
| 1365 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 1366 | // var relational-op b |
| 1367 | // b relational-op var |
| 1368 | // |
| 1369 | if (!S) { |
| 1370 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 1371 | return true; |
| 1372 | } |
| 1373 | S = S->IgnoreParenImpCasts(); |
| 1374 | SourceLocation CondLoc = S->getLocStart(); |
| 1375 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 1376 | if (BO->isRelationalOp()) { |
| 1377 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 1378 | return SetUB(BO->getRHS(), |
| 1379 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 1380 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 1381 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 1382 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 1383 | return SetUB(BO->getLHS(), |
| 1384 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 1385 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 1386 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 1387 | } |
| 1388 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 1389 | if (CE->getNumArgs() == 2) { |
| 1390 | auto Op = CE->getOperator(); |
| 1391 | switch (Op) { |
| 1392 | case OO_Greater: |
| 1393 | case OO_GreaterEqual: |
| 1394 | case OO_Less: |
| 1395 | case OO_LessEqual: |
| 1396 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 1397 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 1398 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 1399 | CE->getOperatorLoc()); |
| 1400 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 1401 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 1402 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 1403 | CE->getOperatorLoc()); |
| 1404 | break; |
| 1405 | default: |
| 1406 | break; |
| 1407 | } |
| 1408 | } |
| 1409 | } |
| 1410 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 1411 | << S->getSourceRange() << Var; |
| 1412 | return true; |
| 1413 | } |
| 1414 | |
| 1415 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 1416 | // RHS of canonical loop form increment can be: |
| 1417 | // var + incr |
| 1418 | // incr + var |
| 1419 | // var - incr |
| 1420 | // |
| 1421 | RHS = RHS->IgnoreParenImpCasts(); |
| 1422 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 1423 | if (BO->isAdditiveOp()) { |
| 1424 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 1425 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 1426 | return SetStep(BO->getRHS(), !IsAdd); |
| 1427 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 1428 | return SetStep(BO->getLHS(), false); |
| 1429 | } |
| 1430 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 1431 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 1432 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 1433 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 1434 | return SetStep(CE->getArg(1), !IsAdd); |
| 1435 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 1436 | return SetStep(CE->getArg(0), false); |
| 1437 | } |
| 1438 | } |
| 1439 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 1440 | << RHS->getSourceRange() << Var; |
| 1441 | return true; |
| 1442 | } |
| 1443 | |
| 1444 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 1445 | // Check incr-expr for canonical loop form and return true if it |
| 1446 | // does not conform. |
| 1447 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 1448 | // ++var |
| 1449 | // var++ |
| 1450 | // --var |
| 1451 | // var-- |
| 1452 | // var += incr |
| 1453 | // var -= incr |
| 1454 | // var = var + incr |
| 1455 | // var = incr + var |
| 1456 | // var = var - incr |
| 1457 | // |
| 1458 | if (!S) { |
| 1459 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 1460 | return true; |
| 1461 | } |
| 1462 | S = S->IgnoreParens(); |
| 1463 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 1464 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 1465 | return SetStep( |
| 1466 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 1467 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 1468 | false); |
| 1469 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 1470 | switch (BO->getOpcode()) { |
| 1471 | case BO_AddAssign: |
| 1472 | case BO_SubAssign: |
| 1473 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 1474 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 1475 | break; |
| 1476 | case BO_Assign: |
| 1477 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 1478 | return CheckIncRHS(BO->getRHS()); |
| 1479 | break; |
| 1480 | default: |
| 1481 | break; |
| 1482 | } |
| 1483 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 1484 | switch (CE->getOperator()) { |
| 1485 | case OO_PlusPlus: |
| 1486 | case OO_MinusMinus: |
| 1487 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 1488 | return SetStep( |
| 1489 | SemaRef.ActOnIntegerConstant( |
| 1490 | CE->getLocStart(), |
| 1491 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 1492 | false); |
| 1493 | break; |
| 1494 | case OO_PlusEqual: |
| 1495 | case OO_MinusEqual: |
| 1496 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 1497 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 1498 | break; |
| 1499 | case OO_Equal: |
| 1500 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 1501 | return CheckIncRHS(CE->getArg(1)); |
| 1502 | break; |
| 1503 | default: |
| 1504 | break; |
| 1505 | } |
| 1506 | } |
| 1507 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 1508 | << S->getSourceRange() << Var; |
| 1509 | return true; |
| 1510 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1511 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1512 | |
| 1513 | /// \brief Called on a for stmt to check and extract its iteration space |
| 1514 | /// for further processing (such as collapsing). |
| 1515 | static bool CheckOpenMPIterationSpace(OpenMPDirectiveKind DKind, Stmt *S, |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 1516 | Sema &SemaRef, DSAStackTy &DSA, |
| 1517 | unsigned CurrentNestedLoopCount, |
| 1518 | unsigned NestedLoopCount, |
| 1519 | Expr *NestedLoopCountExpr) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1520 | // OpenMP [2.6, Canonical Loop Form] |
| 1521 | // for (init-expr; test-expr; incr-expr) structured-block |
| 1522 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 1523 | if (!For) { |
| 1524 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 1525 | << (NestedLoopCountExpr != nullptr) << getOpenMPDirectiveName(DKind) |
| 1526 | << NestedLoopCount << (CurrentNestedLoopCount > 0) |
| 1527 | << CurrentNestedLoopCount; |
| 1528 | if (NestedLoopCount > 1) |
| 1529 | SemaRef.Diag(NestedLoopCountExpr->getExprLoc(), |
| 1530 | diag::note_omp_collapse_expr) |
| 1531 | << NestedLoopCountExpr->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1532 | return true; |
| 1533 | } |
| 1534 | assert(For->getBody()); |
| 1535 | |
| 1536 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 1537 | |
| 1538 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1539 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1540 | if (ISC.CheckInit(Init)) { |
| 1541 | return true; |
| 1542 | } |
| 1543 | |
| 1544 | bool HasErrors = false; |
| 1545 | |
| 1546 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1547 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1548 | |
| 1549 | // OpenMP [2.6, Canonical Loop Form] |
| 1550 | // Var is one of the following: |
| 1551 | // A variable of signed or unsigned integer type. |
| 1552 | // For C++, a variable of a random access iterator type. |
| 1553 | // For C, a variable of a pointer type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1554 | auto VarType = Var->getType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1555 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 1556 | !VarType->isPointerType() && |
| 1557 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 1558 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 1559 | << SemaRef.getLangOpts().CPlusPlus; |
| 1560 | HasErrors = true; |
| 1561 | } |
| 1562 | |
| 1563 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 1564 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 1565 | // The loop iteration variable in the associated for-loop of a simd construct |
| 1566 | // with just one associated for-loop may be listed in a linear clause with a |
| 1567 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1568 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 1569 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1570 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1571 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 1572 | DVar.CKind != OMPC_linear && DVar.CKind != OMPC_lastprivate) || |
| 1573 | (isOpenMPWorksharingDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 1574 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1575 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1576 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
| 1577 | << getOpenMPClauseName(DVar.CKind); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1578 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1579 | HasErrors = true; |
| 1580 | } else { |
| 1581 | // Make the loop iteration variable private by default. |
| 1582 | DSA.addDSA(Var, nullptr, OMPC_private); |
| 1583 | } |
| 1584 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1585 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1586 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1587 | // Check test-expr. |
| 1588 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 1589 | |
| 1590 | // Check incr-expr. |
| 1591 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 1592 | |
| 1593 | if (ISC.Dependent()) |
| 1594 | return HasErrors; |
| 1595 | |
| 1596 | // FIXME: Build loop's iteration space representation. |
| 1597 | return HasErrors; |
| 1598 | } |
| 1599 | |
| 1600 | /// \brief A helper routine to skip no-op (attributed, compound) stmts get the |
| 1601 | /// next nested for loop. If \a IgnoreCaptured is true, it skips captured stmt |
| 1602 | /// to get the first for loop. |
| 1603 | static Stmt *IgnoreContainerStmts(Stmt *S, bool IgnoreCaptured) { |
| 1604 | if (IgnoreCaptured) |
| 1605 | if (auto CapS = dyn_cast_or_null<CapturedStmt>(S)) |
| 1606 | S = CapS->getCapturedStmt(); |
| 1607 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 1608 | // All loops associated with the construct must be perfectly nested; that is, |
| 1609 | // there must be no intervening code nor any OpenMP directive between any two |
| 1610 | // loops. |
| 1611 | while (true) { |
| 1612 | if (auto AS = dyn_cast_or_null<AttributedStmt>(S)) |
| 1613 | S = AS->getSubStmt(); |
| 1614 | else if (auto CS = dyn_cast_or_null<CompoundStmt>(S)) { |
| 1615 | if (CS->size() != 1) |
| 1616 | break; |
| 1617 | S = CS->body_back(); |
| 1618 | } else |
| 1619 | break; |
| 1620 | } |
| 1621 | return S; |
| 1622 | } |
| 1623 | |
| 1624 | /// \brief Called on a for stmt to check itself and nested loops (if any). |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1625 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 1626 | /// number of collapsed loops otherwise. |
| 1627 | static unsigned CheckOpenMPLoop(OpenMPDirectiveKind DKind, |
| 1628 | Expr *NestedLoopCountExpr, Stmt *AStmt, |
| 1629 | Sema &SemaRef, DSAStackTy &DSA) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 1630 | unsigned NestedLoopCount = 1; |
| 1631 | if (NestedLoopCountExpr) { |
| 1632 | // Found 'collapse' clause - calculate collapse number. |
| 1633 | llvm::APSInt Result; |
| 1634 | if (NestedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 1635 | NestedLoopCount = Result.getLimitedValue(); |
| 1636 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1637 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 1638 | // 'for simd', etc.). |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1639 | Stmt *CurStmt = IgnoreContainerStmts(AStmt, true); |
| 1640 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 1641 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
| 1642 | NestedLoopCount, NestedLoopCountExpr)) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1643 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1644 | // Move on to the next nested for loop, or to the loop body. |
| 1645 | CurStmt = IgnoreContainerStmts(cast<ForStmt>(CurStmt)->getBody(), false); |
| 1646 | } |
| 1647 | |
| 1648 | // FIXME: Build resulting iteration space for IR generation (collapsing |
| 1649 | // iteration spaces when loop count > 1 ('collapse' clause)). |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1650 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 1653 | static Expr *GetCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1654 | auto CollapseFilter = [](const OMPClause *C) -> bool { |
| 1655 | return C->getClauseKind() == OMPC_collapse; |
| 1656 | }; |
| 1657 | OMPExecutableDirective::filtered_clause_iterator<decltype(CollapseFilter)> I( |
| 1658 | Clauses, CollapseFilter); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 1659 | if (I) |
| 1660 | return cast<OMPCollapseClause>(*I)->getNumForLoops(); |
| 1661 | return nullptr; |
| 1662 | } |
| 1663 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1664 | StmtResult Sema::ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1665 | Stmt *AStmt, SourceLocation StartLoc, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1666 | SourceLocation EndLoc) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1667 | // In presence of clause 'collapse', it will define the nested loops number. |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1668 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 1669 | OMPD_simd, GetCollapseNumberExpr(Clauses), AStmt, *this, *DSAStack); |
| 1670 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1671 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1672 | |
| 1673 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1674 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 1675 | Clauses, AStmt); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1678 | StmtResult Sema::ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, |
| 1679 | Stmt *AStmt, SourceLocation StartLoc, |
| 1680 | SourceLocation EndLoc) { |
| 1681 | // In presence of clause 'collapse', it will define the nested loops number. |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1682 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 1683 | OMPD_for, GetCollapseNumberExpr(Clauses), AStmt, *this, *DSAStack); |
| 1684 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1685 | return StmtError(); |
| 1686 | |
| 1687 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1688 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 1689 | Clauses, AStmt); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1692 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 1693 | Stmt *AStmt, |
| 1694 | SourceLocation StartLoc, |
| 1695 | SourceLocation EndLoc) { |
| 1696 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 1697 | auto BaseStmt = AStmt; |
| 1698 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 1699 | BaseStmt = CS->getCapturedStmt(); |
| 1700 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 1701 | auto S = C->children(); |
| 1702 | if (!S) |
| 1703 | return StmtError(); |
| 1704 | // All associated statements must be '#pragma omp section' except for |
| 1705 | // the first one. |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1706 | for (++S; S; ++S) { |
| 1707 | auto SectionStmt = *S; |
| 1708 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 1709 | if (SectionStmt) |
| 1710 | Diag(SectionStmt->getLocStart(), |
| 1711 | diag::err_omp_sections_substmt_not_section); |
| 1712 | return StmtError(); |
| 1713 | } |
| 1714 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1715 | } else { |
| 1716 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 1717 | return StmtError(); |
| 1718 | } |
| 1719 | |
| 1720 | getCurFunction()->setHasBranchProtectedScope(); |
| 1721 | |
| 1722 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 1723 | AStmt); |
| 1724 | } |
| 1725 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1726 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 1727 | SourceLocation StartLoc, |
| 1728 | SourceLocation EndLoc) { |
| 1729 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 1730 | |
| 1731 | getCurFunction()->setHasBranchProtectedScope(); |
| 1732 | |
| 1733 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 1734 | } |
| 1735 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1736 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 1737 | Stmt *AStmt, |
| 1738 | SourceLocation StartLoc, |
| 1739 | SourceLocation EndLoc) { |
| 1740 | getCurFunction()->setHasBranchProtectedScope(); |
| 1741 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 1742 | } |
| 1743 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1744 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1745 | SourceLocation StartLoc, |
| 1746 | SourceLocation LParenLoc, |
| 1747 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1748 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1749 | switch (Kind) { |
| 1750 | case OMPC_if: |
| 1751 | Res = ActOnOpenMPIfClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 1752 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1753 | case OMPC_num_threads: |
| 1754 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 1755 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1756 | case OMPC_safelen: |
| 1757 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 1758 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1759 | case OMPC_collapse: |
| 1760 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 1761 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1762 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1763 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1764 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1765 | case OMPC_private: |
| 1766 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1767 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1768 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1769 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1770 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1771 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1772 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1773 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1774 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 1775 | case OMPC_nowait: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1776 | case OMPC_threadprivate: |
| 1777 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1778 | llvm_unreachable("Clause is not allowed."); |
| 1779 | } |
| 1780 | return Res; |
| 1781 | } |
| 1782 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1783 | OMPClause *Sema::ActOnOpenMPIfClause(Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1784 | SourceLocation LParenLoc, |
| 1785 | SourceLocation EndLoc) { |
| 1786 | Expr *ValExpr = Condition; |
| 1787 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 1788 | !Condition->isInstantiationDependent() && |
| 1789 | !Condition->containsUnexpandedParameterPack()) { |
| 1790 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1791 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1792 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1793 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1794 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1795 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | return new (Context) OMPIfClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 1799 | } |
| 1800 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1801 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 1802 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1803 | if (!Op) |
| 1804 | return ExprError(); |
| 1805 | |
| 1806 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 1807 | public: |
| 1808 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1809 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1810 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 1811 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1812 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 1813 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1814 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 1815 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1816 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 1817 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1818 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 1819 | QualType T, |
| 1820 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1821 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 1822 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1823 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 1824 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1825 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1826 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1827 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1828 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 1829 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1830 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 1831 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1832 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 1833 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1834 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1835 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1836 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1837 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 1838 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1839 | llvm_unreachable("conversion functions are permitted"); |
| 1840 | } |
| 1841 | } ConvertDiagnoser; |
| 1842 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 1843 | } |
| 1844 | |
| 1845 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 1846 | SourceLocation StartLoc, |
| 1847 | SourceLocation LParenLoc, |
| 1848 | SourceLocation EndLoc) { |
| 1849 | Expr *ValExpr = NumThreads; |
| 1850 | if (!NumThreads->isValueDependent() && !NumThreads->isTypeDependent() && |
| 1851 | !NumThreads->isInstantiationDependent() && |
| 1852 | !NumThreads->containsUnexpandedParameterPack()) { |
| 1853 | SourceLocation NumThreadsLoc = NumThreads->getLocStart(); |
| 1854 | ExprResult Val = |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1855 | PerformOpenMPImplicitIntegerConversion(NumThreadsLoc, NumThreads); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1856 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1857 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1858 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1859 | ValExpr = Val.get(); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1860 | |
| 1861 | // OpenMP [2.5, Restrictions] |
| 1862 | // The num_threads expression must evaluate to a positive integer value. |
| 1863 | llvm::APSInt Result; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1864 | if (ValExpr->isIntegerConstantExpr(Result, Context) && Result.isSigned() && |
| 1865 | !Result.isStrictlyPositive()) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1866 | Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause) |
| 1867 | << "num_threads" << NumThreads->getSourceRange(); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1868 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1869 | } |
| 1870 | } |
| 1871 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1872 | return new (Context) |
| 1873 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1876 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 1877 | OpenMPClauseKind CKind) { |
| 1878 | if (!E) |
| 1879 | return ExprError(); |
| 1880 | if (E->isValueDependent() || E->isTypeDependent() || |
| 1881 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1882 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1883 | llvm::APSInt Result; |
| 1884 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 1885 | if (ICE.isInvalid()) |
| 1886 | return ExprError(); |
| 1887 | if (!Result.isStrictlyPositive()) { |
| 1888 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| 1889 | << getOpenMPClauseName(CKind) << E->getSourceRange(); |
| 1890 | return ExprError(); |
| 1891 | } |
| 1892 | return ICE; |
| 1893 | } |
| 1894 | |
| 1895 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 1896 | SourceLocation LParenLoc, |
| 1897 | SourceLocation EndLoc) { |
| 1898 | // OpenMP [2.8.1, simd construct, Description] |
| 1899 | // The parameter of the safelen clause must be a constant |
| 1900 | // positive integer expression. |
| 1901 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 1902 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1903 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1904 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1905 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1906 | } |
| 1907 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1908 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 1909 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1910 | SourceLocation LParenLoc, |
| 1911 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1912 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1913 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1914 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1915 | // The parameter of the collapse clause must be a constant |
| 1916 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1917 | ExprResult NumForLoopsResult = |
| 1918 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 1919 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1920 | return nullptr; |
| 1921 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1922 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1923 | } |
| 1924 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1925 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 1926 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 1927 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1928 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1929 | switch (Kind) { |
| 1930 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1931 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1932 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 1933 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1934 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1935 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1936 | Res = ActOnOpenMPProcBindClause( |
| 1937 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 1938 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1939 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1940 | case OMPC_if: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1941 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1942 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1943 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1944 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1945 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1946 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1947 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1948 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1949 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1950 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1951 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1952 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1953 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1954 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 1955 | case OMPC_nowait: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1956 | case OMPC_threadprivate: |
| 1957 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1958 | llvm_unreachable("Clause is not allowed."); |
| 1959 | } |
| 1960 | return Res; |
| 1961 | } |
| 1962 | |
| 1963 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1964 | SourceLocation KindKwLoc, |
| 1965 | SourceLocation StartLoc, |
| 1966 | SourceLocation LParenLoc, |
| 1967 | SourceLocation EndLoc) { |
| 1968 | if (Kind == OMPC_DEFAULT_unknown) { |
| 1969 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 1970 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 1971 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 1972 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 1973 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1974 | Values += "'"; |
| 1975 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 1976 | Values += "'"; |
| 1977 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 1978 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1979 | Values += " or "; |
| 1980 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 1981 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1982 | break; |
| 1983 | default: |
| 1984 | Values += Sep; |
| 1985 | break; |
| 1986 | } |
| 1987 | } |
| 1988 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1989 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1990 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1991 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1992 | switch (Kind) { |
| 1993 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1994 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1995 | break; |
| 1996 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1997 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1998 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1999 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2000 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2001 | break; |
| 2002 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2003 | return new (Context) |
| 2004 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2005 | } |
| 2006 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 2007 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 2008 | SourceLocation KindKwLoc, |
| 2009 | SourceLocation StartLoc, |
| 2010 | SourceLocation LParenLoc, |
| 2011 | SourceLocation EndLoc) { |
| 2012 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 2013 | std::string Values; |
| 2014 | std::string Sep(", "); |
| 2015 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 2016 | Values += "'"; |
| 2017 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 2018 | Values += "'"; |
| 2019 | switch (i) { |
| 2020 | case OMPC_PROC_BIND_unknown - 2: |
| 2021 | Values += " or "; |
| 2022 | break; |
| 2023 | case OMPC_PROC_BIND_unknown - 1: |
| 2024 | break; |
| 2025 | default: |
| 2026 | Values += Sep; |
| 2027 | break; |
| 2028 | } |
| 2029 | } |
| 2030 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2031 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 2032 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 2033 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2034 | return new (Context) |
| 2035 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2038 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 2039 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 2040 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 2041 | SourceLocation ArgumentLoc, SourceLocation CommaLoc, |
| 2042 | SourceLocation EndLoc) { |
| 2043 | OMPClause *Res = nullptr; |
| 2044 | switch (Kind) { |
| 2045 | case OMPC_schedule: |
| 2046 | Res = ActOnOpenMPScheduleClause( |
| 2047 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
| 2048 | LParenLoc, ArgumentLoc, CommaLoc, EndLoc); |
| 2049 | break; |
| 2050 | case OMPC_if: |
| 2051 | case OMPC_num_threads: |
| 2052 | case OMPC_safelen: |
| 2053 | case OMPC_collapse: |
| 2054 | case OMPC_default: |
| 2055 | case OMPC_proc_bind: |
| 2056 | case OMPC_private: |
| 2057 | case OMPC_firstprivate: |
| 2058 | case OMPC_lastprivate: |
| 2059 | case OMPC_shared: |
| 2060 | case OMPC_reduction: |
| 2061 | case OMPC_linear: |
| 2062 | case OMPC_aligned: |
| 2063 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2064 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2065 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 2066 | case OMPC_nowait: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2067 | case OMPC_threadprivate: |
| 2068 | case OMPC_unknown: |
| 2069 | llvm_unreachable("Clause is not allowed."); |
| 2070 | } |
| 2071 | return Res; |
| 2072 | } |
| 2073 | |
| 2074 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 2075 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 2076 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 2077 | SourceLocation EndLoc) { |
| 2078 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 2079 | std::string Values; |
| 2080 | std::string Sep(", "); |
| 2081 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 2082 | Values += "'"; |
| 2083 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 2084 | Values += "'"; |
| 2085 | switch (i) { |
| 2086 | case OMPC_SCHEDULE_unknown - 2: |
| 2087 | Values += " or "; |
| 2088 | break; |
| 2089 | case OMPC_SCHEDULE_unknown - 1: |
| 2090 | break; |
| 2091 | default: |
| 2092 | Values += Sep; |
| 2093 | break; |
| 2094 | } |
| 2095 | } |
| 2096 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 2097 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 2098 | return nullptr; |
| 2099 | } |
| 2100 | Expr *ValExpr = ChunkSize; |
| 2101 | if (ChunkSize) { |
| 2102 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 2103 | !ChunkSize->isInstantiationDependent() && |
| 2104 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 2105 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 2106 | ExprResult Val = |
| 2107 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 2108 | if (Val.isInvalid()) |
| 2109 | return nullptr; |
| 2110 | |
| 2111 | ValExpr = Val.get(); |
| 2112 | |
| 2113 | // OpenMP [2.7.1, Restrictions] |
| 2114 | // chunk_size must be a loop invariant integer expression with a positive |
| 2115 | // value. |
| 2116 | llvm::APSInt Result; |
| 2117 | if (ValExpr->isIntegerConstantExpr(Result, Context) && |
| 2118 | Result.isSigned() && !Result.isStrictlyPositive()) { |
| 2119 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 2120 | << "schedule" << ChunkSize->getSourceRange(); |
| 2121 | return nullptr; |
| 2122 | } |
| 2123 | } |
| 2124 | } |
| 2125 | |
| 2126 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
| 2127 | EndLoc, Kind, ValExpr); |
| 2128 | } |
| 2129 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2130 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 2131 | SourceLocation StartLoc, |
| 2132 | SourceLocation EndLoc) { |
| 2133 | OMPClause *Res = nullptr; |
| 2134 | switch (Kind) { |
| 2135 | case OMPC_ordered: |
| 2136 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 2137 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 2138 | case OMPC_nowait: |
| 2139 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 2140 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2141 | case OMPC_if: |
| 2142 | case OMPC_num_threads: |
| 2143 | case OMPC_safelen: |
| 2144 | case OMPC_collapse: |
| 2145 | case OMPC_schedule: |
| 2146 | case OMPC_private: |
| 2147 | case OMPC_firstprivate: |
| 2148 | case OMPC_lastprivate: |
| 2149 | case OMPC_shared: |
| 2150 | case OMPC_reduction: |
| 2151 | case OMPC_linear: |
| 2152 | case OMPC_aligned: |
| 2153 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2154 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2155 | case OMPC_default: |
| 2156 | case OMPC_proc_bind: |
| 2157 | case OMPC_threadprivate: |
| 2158 | case OMPC_unknown: |
| 2159 | llvm_unreachable("Clause is not allowed."); |
| 2160 | } |
| 2161 | return Res; |
| 2162 | } |
| 2163 | |
| 2164 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 2165 | SourceLocation EndLoc) { |
| 2166 | return new (Context) OMPOrderedClause(StartLoc, EndLoc); |
| 2167 | } |
| 2168 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 2169 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 2170 | SourceLocation EndLoc) { |
| 2171 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 2172 | } |
| 2173 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2174 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 2175 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 2176 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 2177 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
| 2178 | const DeclarationNameInfo &ReductionId) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 2179 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2180 | switch (Kind) { |
| 2181 | case OMPC_private: |
| 2182 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 2183 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2184 | case OMPC_firstprivate: |
| 2185 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 2186 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2187 | case OMPC_lastprivate: |
| 2188 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 2189 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2190 | case OMPC_shared: |
| 2191 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 2192 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2193 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2194 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 2195 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2196 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 2197 | case OMPC_linear: |
| 2198 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 2199 | ColonLoc, EndLoc); |
| 2200 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 2201 | case OMPC_aligned: |
| 2202 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 2203 | ColonLoc, EndLoc); |
| 2204 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 2205 | case OMPC_copyin: |
| 2206 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 2207 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2208 | case OMPC_copyprivate: |
| 2209 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 2210 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2211 | case OMPC_if: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 2212 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 2213 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 2214 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2215 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 2216 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2217 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2218 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 2219 | case OMPC_nowait: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2220 | case OMPC_threadprivate: |
| 2221 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2222 | llvm_unreachable("Clause is not allowed."); |
| 2223 | } |
| 2224 | return Res; |
| 2225 | } |
| 2226 | |
| 2227 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 2228 | SourceLocation StartLoc, |
| 2229 | SourceLocation LParenLoc, |
| 2230 | SourceLocation EndLoc) { |
| 2231 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2232 | for (auto &RefExpr : VarList) { |
| 2233 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 2234 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2235 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2236 | Vars.push_back(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2237 | continue; |
| 2238 | } |
| 2239 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2240 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2241 | // OpenMP [2.1, C/C++] |
| 2242 | // A list item is a variable name. |
| 2243 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 2244 | // A variable that is part of another variable (as an array or |
| 2245 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2246 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2247 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2248 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2249 | continue; |
| 2250 | } |
| 2251 | Decl *D = DE->getDecl(); |
| 2252 | VarDecl *VD = cast<VarDecl>(D); |
| 2253 | |
| 2254 | QualType Type = VD->getType(); |
| 2255 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 2256 | // It will be analyzed later. |
| 2257 | Vars.push_back(DE); |
| 2258 | continue; |
| 2259 | } |
| 2260 | |
| 2261 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 2262 | // A variable that appears in a private clause must not have an incomplete |
| 2263 | // type or a reference type. |
| 2264 | if (RequireCompleteType(ELoc, Type, |
| 2265 | diag::err_omp_private_incomplete_type)) { |
| 2266 | continue; |
| 2267 | } |
| 2268 | if (Type->isReferenceType()) { |
| 2269 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2270 | << getOpenMPClauseName(OMPC_private) << Type; |
| 2271 | bool IsDecl = |
| 2272 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2273 | Diag(VD->getLocation(), |
| 2274 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2275 | << VD; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2276 | continue; |
| 2277 | } |
| 2278 | |
| 2279 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 2280 | // A variable of class type (or array thereof) that appears in a private |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2281 | // clause requires an accessible, unambiguous default constructor for the |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2282 | // class type. |
| 2283 | while (Type.getNonReferenceType()->isArrayType()) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2284 | Type = cast<ArrayType>(Type.getNonReferenceType().getTypePtr()) |
| 2285 | ->getElementType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2286 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 2287 | CXXRecordDecl *RD = getLangOpts().CPlusPlus |
| 2288 | ? Type.getNonReferenceType()->getAsCXXRecordDecl() |
| 2289 | : nullptr; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2290 | // FIXME This code must be replaced by actual constructing/destructing of |
| 2291 | // the private variable. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2292 | if (RD) { |
| 2293 | CXXConstructorDecl *CD = LookupDefaultConstructor(RD); |
| 2294 | PartialDiagnostic PD = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2295 | PartialDiagnostic(PartialDiagnostic::NullDiagnostic()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2296 | if (!CD || |
| 2297 | CheckConstructorAccess(ELoc, CD, |
| 2298 | InitializedEntity::InitializeTemporary(Type), |
| 2299 | CD->getAccess(), PD) == AR_inaccessible || |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2300 | CD->isDeleted()) { |
| 2301 | Diag(ELoc, diag::err_omp_required_method) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2302 | << getOpenMPClauseName(OMPC_private) << 0; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2303 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 2304 | VarDecl::DeclarationOnly; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2305 | Diag(VD->getLocation(), |
| 2306 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2307 | << VD; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2308 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 2309 | continue; |
| 2310 | } |
| 2311 | MarkFunctionReferenced(ELoc, CD); |
| 2312 | DiagnoseUseOfDecl(CD, ELoc); |
| 2313 | |
| 2314 | CXXDestructorDecl *DD = RD->getDestructor(); |
| 2315 | if (DD) { |
| 2316 | if (CheckDestructorAccess(ELoc, DD, PD) == AR_inaccessible || |
| 2317 | DD->isDeleted()) { |
| 2318 | Diag(ELoc, diag::err_omp_required_method) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2319 | << getOpenMPClauseName(OMPC_private) << 4; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2320 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 2321 | VarDecl::DeclarationOnly; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2322 | Diag(VD->getLocation(), |
| 2323 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2324 | << VD; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2325 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 2326 | continue; |
| 2327 | } |
| 2328 | MarkFunctionReferenced(ELoc, DD); |
| 2329 | DiagnoseUseOfDecl(DD, ELoc); |
| 2330 | } |
| 2331 | } |
| 2332 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2333 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 2334 | // in a Construct] |
| 2335 | // Variables with the predetermined data-sharing attributes may not be |
| 2336 | // listed in data-sharing attributes clauses, except for the cases |
| 2337 | // listed below. For these exceptions only, listing a predetermined |
| 2338 | // variable in a data-sharing attribute clause is allowed and overrides |
| 2339 | // the variable's predetermined data-sharing attributes. |
| 2340 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD); |
| 2341 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2342 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 2343 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2344 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2345 | continue; |
| 2346 | } |
| 2347 | |
| 2348 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2349 | Vars.push_back(DE); |
| 2350 | } |
| 2351 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2352 | if (Vars.empty()) |
| 2353 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2354 | |
| 2355 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 2356 | } |
| 2357 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2358 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 2359 | SourceLocation StartLoc, |
| 2360 | SourceLocation LParenLoc, |
| 2361 | SourceLocation EndLoc) { |
| 2362 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2363 | for (auto &RefExpr : VarList) { |
| 2364 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 2365 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2366 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2367 | Vars.push_back(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2368 | continue; |
| 2369 | } |
| 2370 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2371 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2372 | // OpenMP [2.1, C/C++] |
| 2373 | // A list item is a variable name. |
| 2374 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 2375 | // A variable that is part of another variable (as an array or |
| 2376 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2377 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2378 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2379 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2380 | continue; |
| 2381 | } |
| 2382 | Decl *D = DE->getDecl(); |
| 2383 | VarDecl *VD = cast<VarDecl>(D); |
| 2384 | |
| 2385 | QualType Type = VD->getType(); |
| 2386 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 2387 | // It will be analyzed later. |
| 2388 | Vars.push_back(DE); |
| 2389 | continue; |
| 2390 | } |
| 2391 | |
| 2392 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 2393 | // A variable that appears in a private clause must not have an incomplete |
| 2394 | // type or a reference type. |
| 2395 | if (RequireCompleteType(ELoc, Type, |
| 2396 | diag::err_omp_firstprivate_incomplete_type)) { |
| 2397 | continue; |
| 2398 | } |
| 2399 | if (Type->isReferenceType()) { |
| 2400 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2401 | << getOpenMPClauseName(OMPC_firstprivate) << Type; |
| 2402 | bool IsDecl = |
| 2403 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2404 | Diag(VD->getLocation(), |
| 2405 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2406 | << VD; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2407 | continue; |
| 2408 | } |
| 2409 | |
| 2410 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 2411 | // A variable of class type (or array thereof) that appears in a private |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2412 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2413 | // class type. |
| 2414 | Type = Context.getBaseElementType(Type); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 2415 | CXXRecordDecl *RD = getLangOpts().CPlusPlus |
| 2416 | ? Type.getNonReferenceType()->getAsCXXRecordDecl() |
| 2417 | : nullptr; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2418 | // FIXME This code must be replaced by actual constructing/destructing of |
| 2419 | // the firstprivate variable. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2420 | if (RD) { |
| 2421 | CXXConstructorDecl *CD = LookupCopyingConstructor(RD, 0); |
| 2422 | PartialDiagnostic PD = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2423 | PartialDiagnostic(PartialDiagnostic::NullDiagnostic()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2424 | if (!CD || |
| 2425 | CheckConstructorAccess(ELoc, CD, |
| 2426 | InitializedEntity::InitializeTemporary(Type), |
| 2427 | CD->getAccess(), PD) == AR_inaccessible || |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2428 | CD->isDeleted()) { |
| 2429 | Diag(ELoc, diag::err_omp_required_method) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2430 | << getOpenMPClauseName(OMPC_firstprivate) << 1; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2431 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 2432 | VarDecl::DeclarationOnly; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2433 | Diag(VD->getLocation(), |
| 2434 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2435 | << VD; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2436 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 2437 | continue; |
| 2438 | } |
| 2439 | MarkFunctionReferenced(ELoc, CD); |
| 2440 | DiagnoseUseOfDecl(CD, ELoc); |
| 2441 | |
| 2442 | CXXDestructorDecl *DD = RD->getDestructor(); |
| 2443 | if (DD) { |
| 2444 | if (CheckDestructorAccess(ELoc, DD, PD) == AR_inaccessible || |
| 2445 | DD->isDeleted()) { |
| 2446 | Diag(ELoc, diag::err_omp_required_method) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2447 | << getOpenMPClauseName(OMPC_firstprivate) << 4; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2448 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 2449 | VarDecl::DeclarationOnly; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2450 | Diag(VD->getLocation(), |
| 2451 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2452 | << VD; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2453 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 2454 | continue; |
| 2455 | } |
| 2456 | MarkFunctionReferenced(ELoc, DD); |
| 2457 | DiagnoseUseOfDecl(DD, ELoc); |
| 2458 | } |
| 2459 | } |
| 2460 | |
| 2461 | // If StartLoc and EndLoc are invalid - this is an implicit firstprivate |
| 2462 | // variable and it was checked already. |
| 2463 | if (StartLoc.isValid() && EndLoc.isValid()) { |
| 2464 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD); |
| 2465 | Type = Type.getNonReferenceType().getCanonicalType(); |
| 2466 | bool IsConstant = Type.isConstant(Context); |
| 2467 | Type = Context.getBaseElementType(Type); |
| 2468 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 2469 | // A list item that specifies a given variable may not appear in more |
| 2470 | // than one clause on the same directive, except that a variable may be |
| 2471 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2472 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2473 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2474 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2475 | << getOpenMPClauseName(DVar.CKind) |
| 2476 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2477 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2478 | continue; |
| 2479 | } |
| 2480 | |
| 2481 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 2482 | // in a Construct] |
| 2483 | // Variables with the predetermined data-sharing attributes may not be |
| 2484 | // listed in data-sharing attributes clauses, except for the cases |
| 2485 | // listed below. For these exceptions only, listing a predetermined |
| 2486 | // variable in a data-sharing attribute clause is allowed and overrides |
| 2487 | // the variable's predetermined data-sharing attributes. |
| 2488 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 2489 | // in a Construct, C/C++, p.2] |
| 2490 | // Variables with const-qualified type having no mutable member may be |
| 2491 | // listed in a firstprivate clause, even if they are static data members. |
| 2492 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 2493 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 2494 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2495 | << getOpenMPClauseName(DVar.CKind) |
| 2496 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2497 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2498 | continue; |
| 2499 | } |
| 2500 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2501 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2502 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 2503 | // A list item that is private within a parallel region must not appear |
| 2504 | // in a firstprivate clause on a worksharing construct if any of the |
| 2505 | // worksharing regions arising from the worksharing construct ever bind |
| 2506 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2507 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 2508 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2509 | DVar = DSAStack->getImplicitDSA(VD); |
| 2510 | if (DVar.CKind != OMPC_shared) { |
| 2511 | Diag(ELoc, diag::err_omp_required_access) |
| 2512 | << getOpenMPClauseName(OMPC_firstprivate) |
| 2513 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2514 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2515 | continue; |
| 2516 | } |
| 2517 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2518 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 2519 | // A list item that appears in a reduction clause of a parallel construct |
| 2520 | // must not appear in a firstprivate clause on a worksharing or task |
| 2521 | // construct if any of the worksharing or task regions arising from the |
| 2522 | // worksharing or task construct ever bind to any of the parallel regions |
| 2523 | // arising from the parallel construct. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2524 | // TODO |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2525 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 2526 | // A list item that appears in a reduction clause in worksharing |
| 2527 | // construct must not appear in a firstprivate clause in a task construct |
| 2528 | // encountered during execution of any of the worksharing regions arising |
| 2529 | // from the worksharing construct. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2530 | // TODO |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 2534 | Vars.push_back(DE); |
| 2535 | } |
| 2536 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2537 | if (Vars.empty()) |
| 2538 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2539 | |
| 2540 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 2541 | Vars); |
| 2542 | } |
| 2543 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2544 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 2545 | SourceLocation StartLoc, |
| 2546 | SourceLocation LParenLoc, |
| 2547 | SourceLocation EndLoc) { |
| 2548 | SmallVector<Expr *, 8> Vars; |
| 2549 | for (auto &RefExpr : VarList) { |
| 2550 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 2551 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 2552 | // It will be analyzed later. |
| 2553 | Vars.push_back(RefExpr); |
| 2554 | continue; |
| 2555 | } |
| 2556 | |
| 2557 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 2558 | // OpenMP [2.1, C/C++] |
| 2559 | // A list item is a variable name. |
| 2560 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 2561 | // A variable that is part of another variable (as an array or structure |
| 2562 | // element) cannot appear in a lastprivate clause. |
| 2563 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 2564 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 2565 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 2566 | continue; |
| 2567 | } |
| 2568 | Decl *D = DE->getDecl(); |
| 2569 | VarDecl *VD = cast<VarDecl>(D); |
| 2570 | |
| 2571 | QualType Type = VD->getType(); |
| 2572 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 2573 | // It will be analyzed later. |
| 2574 | Vars.push_back(DE); |
| 2575 | continue; |
| 2576 | } |
| 2577 | |
| 2578 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 2579 | // A variable that appears in a lastprivate clause must not have an |
| 2580 | // incomplete type or a reference type. |
| 2581 | if (RequireCompleteType(ELoc, Type, |
| 2582 | diag::err_omp_lastprivate_incomplete_type)) { |
| 2583 | continue; |
| 2584 | } |
| 2585 | if (Type->isReferenceType()) { |
| 2586 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 2587 | << getOpenMPClauseName(OMPC_lastprivate) << Type; |
| 2588 | bool IsDecl = |
| 2589 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2590 | Diag(VD->getLocation(), |
| 2591 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2592 | << VD; |
| 2593 | continue; |
| 2594 | } |
| 2595 | |
| 2596 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 2597 | // in a Construct] |
| 2598 | // Variables with the predetermined data-sharing attributes may not be |
| 2599 | // listed in data-sharing attributes clauses, except for the cases |
| 2600 | // listed below. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2601 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD); |
| 2602 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 2603 | DVar.CKind != OMPC_firstprivate && |
| 2604 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 2605 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 2606 | << getOpenMPClauseName(DVar.CKind) |
| 2607 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2608 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2609 | continue; |
| 2610 | } |
| 2611 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2612 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 2613 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 2614 | // A list item that is private within a parallel region, or that appears in |
| 2615 | // the reduction clause of a parallel construct, must not appear in a |
| 2616 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 2617 | // worksharing regions ever binds to any of the corresponding parallel |
| 2618 | // regions. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2619 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 2620 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2621 | DVar = DSAStack->getImplicitDSA(VD); |
| 2622 | if (DVar.CKind != OMPC_shared) { |
| 2623 | Diag(ELoc, diag::err_omp_required_access) |
| 2624 | << getOpenMPClauseName(OMPC_lastprivate) |
| 2625 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2626 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2627 | continue; |
| 2628 | } |
| 2629 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2630 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2631 | // A variable of class type (or array thereof) that appears in a |
| 2632 | // lastprivate clause requires an accessible, unambiguous default |
| 2633 | // constructor for the class type, unless the list item is also specified |
| 2634 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2635 | // A variable of class type (or array thereof) that appears in a |
| 2636 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 2637 | // operator for the class type. |
| 2638 | while (Type.getNonReferenceType()->isArrayType()) |
| 2639 | Type = cast<ArrayType>(Type.getNonReferenceType().getTypePtr()) |
| 2640 | ->getElementType(); |
| 2641 | CXXRecordDecl *RD = getLangOpts().CPlusPlus |
| 2642 | ? Type.getNonReferenceType()->getAsCXXRecordDecl() |
| 2643 | : nullptr; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2644 | // FIXME This code must be replaced by actual copying and destructing of the |
| 2645 | // lastprivate variable. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2646 | if (RD) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2647 | CXXMethodDecl *MD = LookupCopyingAssignment(RD, 0, false, 0); |
| 2648 | DeclAccessPair FoundDecl = DeclAccessPair::make(MD, MD->getAccess()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2649 | if (MD) { |
| 2650 | if (CheckMemberAccess(ELoc, RD, FoundDecl) == AR_inaccessible || |
| 2651 | MD->isDeleted()) { |
| 2652 | Diag(ELoc, diag::err_omp_required_method) |
| 2653 | << getOpenMPClauseName(OMPC_lastprivate) << 2; |
| 2654 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 2655 | VarDecl::DeclarationOnly; |
| 2656 | Diag(VD->getLocation(), |
| 2657 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2658 | << VD; |
| 2659 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 2660 | continue; |
| 2661 | } |
| 2662 | MarkFunctionReferenced(ELoc, MD); |
| 2663 | DiagnoseUseOfDecl(MD, ELoc); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2664 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2665 | |
| 2666 | CXXDestructorDecl *DD = RD->getDestructor(); |
| 2667 | if (DD) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2668 | PartialDiagnostic PD = |
| 2669 | PartialDiagnostic(PartialDiagnostic::NullDiagnostic()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2670 | if (CheckDestructorAccess(ELoc, DD, PD) == AR_inaccessible || |
| 2671 | DD->isDeleted()) { |
| 2672 | Diag(ELoc, diag::err_omp_required_method) |
| 2673 | << getOpenMPClauseName(OMPC_lastprivate) << 4; |
| 2674 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 2675 | VarDecl::DeclarationOnly; |
| 2676 | Diag(VD->getLocation(), |
| 2677 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2678 | << VD; |
| 2679 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 2680 | continue; |
| 2681 | } |
| 2682 | MarkFunctionReferenced(ELoc, DD); |
| 2683 | DiagnoseUseOfDecl(DD, ELoc); |
| 2684 | } |
| 2685 | } |
| 2686 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2687 | if (DVar.CKind != OMPC_firstprivate) |
| 2688 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2689 | Vars.push_back(DE); |
| 2690 | } |
| 2691 | |
| 2692 | if (Vars.empty()) |
| 2693 | return nullptr; |
| 2694 | |
| 2695 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 2696 | Vars); |
| 2697 | } |
| 2698 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2699 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 2700 | SourceLocation StartLoc, |
| 2701 | SourceLocation LParenLoc, |
| 2702 | SourceLocation EndLoc) { |
| 2703 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2704 | for (auto &RefExpr : VarList) { |
| 2705 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 2706 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2707 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2708 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2709 | continue; |
| 2710 | } |
| 2711 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2712 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2713 | // OpenMP [2.1, C/C++] |
| 2714 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 2715 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 2716 | // A variable that is part of another variable (as an array or structure |
| 2717 | // element) cannot appear in a shared unless it is a static data member |
| 2718 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2719 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2720 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2721 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2722 | continue; |
| 2723 | } |
| 2724 | Decl *D = DE->getDecl(); |
| 2725 | VarDecl *VD = cast<VarDecl>(D); |
| 2726 | |
| 2727 | QualType Type = VD->getType(); |
| 2728 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 2729 | // It will be analyzed later. |
| 2730 | Vars.push_back(DE); |
| 2731 | continue; |
| 2732 | } |
| 2733 | |
| 2734 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 2735 | // in a Construct] |
| 2736 | // Variables with the predetermined data-sharing attributes may not be |
| 2737 | // listed in data-sharing attributes clauses, except for the cases |
| 2738 | // listed below. For these exceptions only, listing a predetermined |
| 2739 | // variable in a data-sharing attribute clause is allowed and overrides |
| 2740 | // the variable's predetermined data-sharing attributes. |
| 2741 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2742 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 2743 | DVar.RefExpr) { |
| 2744 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 2745 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2746 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2747 | continue; |
| 2748 | } |
| 2749 | |
| 2750 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 2751 | Vars.push_back(DE); |
| 2752 | } |
| 2753 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2754 | if (Vars.empty()) |
| 2755 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2756 | |
| 2757 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 2758 | } |
| 2759 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2760 | namespace { |
| 2761 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 2762 | DSAStackTy *Stack; |
| 2763 | |
| 2764 | public: |
| 2765 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 2766 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 2767 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD); |
| 2768 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 2769 | return false; |
| 2770 | if (DVar.CKind != OMPC_unknown) |
| 2771 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2772 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2773 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2774 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2775 | return true; |
| 2776 | return false; |
| 2777 | } |
| 2778 | return false; |
| 2779 | } |
| 2780 | bool VisitStmt(Stmt *S) { |
| 2781 | for (auto Child : S->children()) { |
| 2782 | if (Child && Visit(Child)) |
| 2783 | return true; |
| 2784 | } |
| 2785 | return false; |
| 2786 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2787 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2788 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2789 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2790 | |
| 2791 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 2792 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 2793 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 2794 | CXXScopeSpec &ReductionIdScopeSpec, |
| 2795 | const DeclarationNameInfo &ReductionId) { |
| 2796 | // TODO: Allow scope specification search when 'declare reduction' is |
| 2797 | // supported. |
| 2798 | assert(ReductionIdScopeSpec.isEmpty() && |
| 2799 | "No support for scoped reduction identifiers yet."); |
| 2800 | |
| 2801 | auto DN = ReductionId.getName(); |
| 2802 | auto OOK = DN.getCXXOverloadedOperator(); |
| 2803 | BinaryOperatorKind BOK = BO_Comma; |
| 2804 | |
| 2805 | // OpenMP [2.14.3.6, reduction clause] |
| 2806 | // C |
| 2807 | // reduction-identifier is either an identifier or one of the following |
| 2808 | // operators: +, -, *, &, |, ^, && and || |
| 2809 | // C++ |
| 2810 | // reduction-identifier is either an id-expression or one of the following |
| 2811 | // operators: +, -, *, &, |, ^, && and || |
| 2812 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 2813 | switch (OOK) { |
| 2814 | case OO_Plus: |
| 2815 | case OO_Minus: |
| 2816 | BOK = BO_AddAssign; |
| 2817 | break; |
| 2818 | case OO_Star: |
| 2819 | BOK = BO_MulAssign; |
| 2820 | break; |
| 2821 | case OO_Amp: |
| 2822 | BOK = BO_AndAssign; |
| 2823 | break; |
| 2824 | case OO_Pipe: |
| 2825 | BOK = BO_OrAssign; |
| 2826 | break; |
| 2827 | case OO_Caret: |
| 2828 | BOK = BO_XorAssign; |
| 2829 | break; |
| 2830 | case OO_AmpAmp: |
| 2831 | BOK = BO_LAnd; |
| 2832 | break; |
| 2833 | case OO_PipePipe: |
| 2834 | BOK = BO_LOr; |
| 2835 | break; |
| 2836 | default: |
| 2837 | if (auto II = DN.getAsIdentifierInfo()) { |
| 2838 | if (II->isStr("max")) |
| 2839 | BOK = BO_GT; |
| 2840 | else if (II->isStr("min")) |
| 2841 | BOK = BO_LT; |
| 2842 | } |
| 2843 | break; |
| 2844 | } |
| 2845 | SourceRange ReductionIdRange; |
| 2846 | if (ReductionIdScopeSpec.isValid()) { |
| 2847 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 2848 | } |
| 2849 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 2850 | if (BOK == BO_Comma) { |
| 2851 | // Not allowed reduction identifier is found. |
| 2852 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 2853 | << ReductionIdRange; |
| 2854 | return nullptr; |
| 2855 | } |
| 2856 | |
| 2857 | SmallVector<Expr *, 8> Vars; |
| 2858 | for (auto RefExpr : VarList) { |
| 2859 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 2860 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 2861 | // It will be analyzed later. |
| 2862 | Vars.push_back(RefExpr); |
| 2863 | continue; |
| 2864 | } |
| 2865 | |
| 2866 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 2867 | RefExpr->isInstantiationDependent() || |
| 2868 | RefExpr->containsUnexpandedParameterPack()) { |
| 2869 | // It will be analyzed later. |
| 2870 | Vars.push_back(RefExpr); |
| 2871 | continue; |
| 2872 | } |
| 2873 | |
| 2874 | auto ELoc = RefExpr->getExprLoc(); |
| 2875 | auto ERange = RefExpr->getSourceRange(); |
| 2876 | // OpenMP [2.1, C/C++] |
| 2877 | // A list item is a variable or array section, subject to the restrictions |
| 2878 | // specified in Section 2.4 on page 42 and in each of the sections |
| 2879 | // describing clauses and directives for which a list appears. |
| 2880 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 2881 | // A variable that is part of another variable (as an array or |
| 2882 | // structure element) cannot appear in a private clause. |
| 2883 | auto DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 2884 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 2885 | Diag(ELoc, diag::err_omp_expected_var_name) << ERange; |
| 2886 | continue; |
| 2887 | } |
| 2888 | auto D = DE->getDecl(); |
| 2889 | auto VD = cast<VarDecl>(D); |
| 2890 | auto Type = VD->getType(); |
| 2891 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 2892 | // A variable that appears in a private clause must not have an incomplete |
| 2893 | // type or a reference type. |
| 2894 | if (RequireCompleteType(ELoc, Type, |
| 2895 | diag::err_omp_reduction_incomplete_type)) |
| 2896 | continue; |
| 2897 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 2898 | // Arrays may not appear in a reduction clause. |
| 2899 | if (Type.getNonReferenceType()->isArrayType()) { |
| 2900 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
| 2901 | bool IsDecl = |
| 2902 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2903 | Diag(VD->getLocation(), |
| 2904 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2905 | << VD; |
| 2906 | continue; |
| 2907 | } |
| 2908 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 2909 | // A list item that appears in a reduction clause must not be |
| 2910 | // const-qualified. |
| 2911 | if (Type.getNonReferenceType().isConstant(Context)) { |
| 2912 | Diag(ELoc, diag::err_omp_const_variable) |
| 2913 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
| 2914 | bool IsDecl = |
| 2915 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2916 | Diag(VD->getLocation(), |
| 2917 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2918 | << VD; |
| 2919 | continue; |
| 2920 | } |
| 2921 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 2922 | // If a list-item is a reference type then it must bind to the same object |
| 2923 | // for all threads of the team. |
| 2924 | VarDecl *VDDef = VD->getDefinition(); |
| 2925 | if (Type->isReferenceType() && VDDef) { |
| 2926 | DSARefChecker Check(DSAStack); |
| 2927 | if (Check.Visit(VDDef->getInit())) { |
| 2928 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 2929 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 2930 | continue; |
| 2931 | } |
| 2932 | } |
| 2933 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 2934 | // The type of a list item that appears in a reduction clause must be valid |
| 2935 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 2936 | // of the list item must be an allowed arithmetic data type: char, int, |
| 2937 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 2938 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 2939 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 2940 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 2941 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 2942 | !(Type->isScalarType() || |
| 2943 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 2944 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 2945 | << getLangOpts().CPlusPlus; |
| 2946 | bool IsDecl = |
| 2947 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2948 | Diag(VD->getLocation(), |
| 2949 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2950 | << VD; |
| 2951 | continue; |
| 2952 | } |
| 2953 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 2954 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 2955 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 2956 | bool IsDecl = |
| 2957 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2958 | Diag(VD->getLocation(), |
| 2959 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2960 | << VD; |
| 2961 | continue; |
| 2962 | } |
| 2963 | bool Suppress = getDiagnostics().getSuppressAllDiagnostics(); |
| 2964 | getDiagnostics().setSuppressAllDiagnostics(true); |
| 2965 | ExprResult ReductionOp = |
| 2966 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 2967 | RefExpr, RefExpr); |
| 2968 | getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 2969 | if (ReductionOp.isInvalid()) { |
| 2970 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2971 | << ReductionIdRange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2972 | bool IsDecl = |
| 2973 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2974 | Diag(VD->getLocation(), |
| 2975 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2976 | << VD; |
| 2977 | continue; |
| 2978 | } |
| 2979 | |
| 2980 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 2981 | // in a Construct] |
| 2982 | // Variables with the predetermined data-sharing attributes may not be |
| 2983 | // listed in data-sharing attributes clauses, except for the cases |
| 2984 | // listed below. For these exceptions only, listing a predetermined |
| 2985 | // variable in a data-sharing attribute clause is allowed and overrides |
| 2986 | // the variable's predetermined data-sharing attributes. |
| 2987 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 2988 | // Any number of reduction clauses can be specified on the directive, |
| 2989 | // but a list item can appear only once in the reduction clauses for that |
| 2990 | // directive. |
| 2991 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD); |
| 2992 | if (DVar.CKind == OMPC_reduction) { |
| 2993 | Diag(ELoc, diag::err_omp_once_referenced) |
| 2994 | << getOpenMPClauseName(OMPC_reduction); |
| 2995 | if (DVar.RefExpr) { |
| 2996 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
| 2997 | } |
| 2998 | } else if (DVar.CKind != OMPC_unknown) { |
| 2999 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 3000 | << getOpenMPClauseName(DVar.CKind) |
| 3001 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3002 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 3003 | continue; |
| 3004 | } |
| 3005 | |
| 3006 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 3007 | // A list item that appears in a reduction clause of a worksharing |
| 3008 | // construct must be shared in the parallel regions to which any of the |
| 3009 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3010 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3011 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 3012 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3013 | DVar = DSAStack->getImplicitDSA(VD); |
| 3014 | if (DVar.CKind != OMPC_shared) { |
| 3015 | Diag(ELoc, diag::err_omp_required_access) |
| 3016 | << getOpenMPClauseName(OMPC_reduction) |
| 3017 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3018 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3019 | continue; |
| 3020 | } |
| 3021 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 3022 | |
| 3023 | CXXRecordDecl *RD = getLangOpts().CPlusPlus |
| 3024 | ? Type.getNonReferenceType()->getAsCXXRecordDecl() |
| 3025 | : nullptr; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3026 | // FIXME This code must be replaced by actual constructing/destructing of |
| 3027 | // the reduction variable. |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 3028 | if (RD) { |
| 3029 | CXXConstructorDecl *CD = LookupDefaultConstructor(RD); |
| 3030 | PartialDiagnostic PD = |
| 3031 | PartialDiagnostic(PartialDiagnostic::NullDiagnostic()); |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3032 | if (!CD || |
| 3033 | CheckConstructorAccess(ELoc, CD, |
| 3034 | InitializedEntity::InitializeTemporary(Type), |
| 3035 | CD->getAccess(), PD) == AR_inaccessible || |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 3036 | CD->isDeleted()) { |
| 3037 | Diag(ELoc, diag::err_omp_required_method) |
| 3038 | << getOpenMPClauseName(OMPC_reduction) << 0; |
| 3039 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 3040 | VarDecl::DeclarationOnly; |
| 3041 | Diag(VD->getLocation(), |
| 3042 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 3043 | << VD; |
| 3044 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 3045 | continue; |
| 3046 | } |
| 3047 | MarkFunctionReferenced(ELoc, CD); |
| 3048 | DiagnoseUseOfDecl(CD, ELoc); |
| 3049 | |
| 3050 | CXXDestructorDecl *DD = RD->getDestructor(); |
| 3051 | if (DD) { |
| 3052 | if (CheckDestructorAccess(ELoc, DD, PD) == AR_inaccessible || |
| 3053 | DD->isDeleted()) { |
| 3054 | Diag(ELoc, diag::err_omp_required_method) |
| 3055 | << getOpenMPClauseName(OMPC_reduction) << 4; |
| 3056 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 3057 | VarDecl::DeclarationOnly; |
| 3058 | Diag(VD->getLocation(), |
| 3059 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 3060 | << VD; |
| 3061 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 3062 | continue; |
| 3063 | } |
| 3064 | MarkFunctionReferenced(ELoc, DD); |
| 3065 | DiagnoseUseOfDecl(DD, ELoc); |
| 3066 | } |
| 3067 | } |
| 3068 | |
| 3069 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
| 3070 | Vars.push_back(DE); |
| 3071 | } |
| 3072 | |
| 3073 | if (Vars.empty()) |
| 3074 | return nullptr; |
| 3075 | |
| 3076 | return OMPReductionClause::Create( |
| 3077 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
| 3078 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId); |
| 3079 | } |
| 3080 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 3081 | OMPClause *Sema::ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 3082 | SourceLocation StartLoc, |
| 3083 | SourceLocation LParenLoc, |
| 3084 | SourceLocation ColonLoc, |
| 3085 | SourceLocation EndLoc) { |
| 3086 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3087 | for (auto &RefExpr : VarList) { |
| 3088 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 3089 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 3090 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3091 | Vars.push_back(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 3092 | continue; |
| 3093 | } |
| 3094 | |
| 3095 | // OpenMP [2.14.3.7, linear clause] |
| 3096 | // A list item that appears in a linear clause is subject to the private |
| 3097 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 3098 | // noted. In addition, the value of the new list item on each iteration |
| 3099 | // of the associated loop(s) corresponds to the value of the original |
| 3100 | // list item before entering the construct plus the logical number of |
| 3101 | // the iteration times linear-step. |
| 3102 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3103 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 3104 | // OpenMP [2.1, C/C++] |
| 3105 | // A list item is a variable name. |
| 3106 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 3107 | // A variable that is part of another variable (as an array or |
| 3108 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3109 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 3110 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3111 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 3112 | continue; |
| 3113 | } |
| 3114 | |
| 3115 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 3116 | |
| 3117 | // OpenMP [2.14.3.7, linear clause] |
| 3118 | // A list-item cannot appear in more than one linear clause. |
| 3119 | // A list-item that appears in a linear clause cannot appear in any |
| 3120 | // other data-sharing attribute clause. |
| 3121 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD); |
| 3122 | if (DVar.RefExpr) { |
| 3123 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 3124 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3125 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 3126 | continue; |
| 3127 | } |
| 3128 | |
| 3129 | QualType QType = VD->getType(); |
| 3130 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 3131 | // It will be analyzed later. |
| 3132 | Vars.push_back(DE); |
| 3133 | continue; |
| 3134 | } |
| 3135 | |
| 3136 | // A variable must not have an incomplete type or a reference type. |
| 3137 | if (RequireCompleteType(ELoc, QType, |
| 3138 | diag::err_omp_linear_incomplete_type)) { |
| 3139 | continue; |
| 3140 | } |
| 3141 | if (QType->isReferenceType()) { |
| 3142 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 3143 | << getOpenMPClauseName(OMPC_linear) << QType; |
| 3144 | bool IsDecl = |
| 3145 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 3146 | Diag(VD->getLocation(), |
| 3147 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 3148 | << VD; |
| 3149 | continue; |
| 3150 | } |
| 3151 | |
| 3152 | // A list item must not be const-qualified. |
| 3153 | if (QType.isConstant(Context)) { |
| 3154 | Diag(ELoc, diag::err_omp_const_variable) |
| 3155 | << getOpenMPClauseName(OMPC_linear); |
| 3156 | bool IsDecl = |
| 3157 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 3158 | Diag(VD->getLocation(), |
| 3159 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 3160 | << VD; |
| 3161 | continue; |
| 3162 | } |
| 3163 | |
| 3164 | // A list item must be of integral or pointer type. |
| 3165 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 3166 | const Type *Ty = QType.getTypePtrOrNull(); |
| 3167 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 3168 | !Ty->isPointerType())) { |
| 3169 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 3170 | bool IsDecl = |
| 3171 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 3172 | Diag(VD->getLocation(), |
| 3173 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 3174 | << VD; |
| 3175 | continue; |
| 3176 | } |
| 3177 | |
| 3178 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 3179 | Vars.push_back(DE); |
| 3180 | } |
| 3181 | |
| 3182 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 3183 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 3184 | |
| 3185 | Expr *StepExpr = Step; |
| 3186 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 3187 | !Step->isInstantiationDependent() && |
| 3188 | !Step->containsUnexpandedParameterPack()) { |
| 3189 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3190 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 3191 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 3192 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3193 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 3194 | |
| 3195 | // Warn about zero linear step (it would be probably better specified as |
| 3196 | // making corresponding variables 'const'). |
| 3197 | llvm::APSInt Result; |
| 3198 | if (StepExpr->isIntegerConstantExpr(Result, Context) && |
| 3199 | !Result.isNegative() && !Result.isStrictlyPositive()) |
| 3200 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 3201 | << (Vars.size() > 1); |
| 3202 | } |
| 3203 | |
| 3204 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 3205 | Vars, StepExpr); |
| 3206 | } |
| 3207 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 3208 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 3209 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 3210 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 3211 | |
| 3212 | SmallVector<Expr *, 8> Vars; |
| 3213 | for (auto &RefExpr : VarList) { |
| 3214 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 3215 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 3216 | // It will be analyzed later. |
| 3217 | Vars.push_back(RefExpr); |
| 3218 | continue; |
| 3219 | } |
| 3220 | |
| 3221 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 3222 | // OpenMP [2.1, C/C++] |
| 3223 | // A list item is a variable name. |
| 3224 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 3225 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 3226 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 3227 | continue; |
| 3228 | } |
| 3229 | |
| 3230 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 3231 | |
| 3232 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3233 | // The type of list items appearing in the aligned clause must be |
| 3234 | // array, pointer, reference to array, or reference to pointer. |
| 3235 | QualType QType = DE->getType() |
| 3236 | .getNonReferenceType() |
| 3237 | .getUnqualifiedType() |
| 3238 | .getCanonicalType(); |
| 3239 | const Type *Ty = QType.getTypePtrOrNull(); |
| 3240 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 3241 | !Ty->isPointerType())) { |
| 3242 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 3243 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 3244 | bool IsDecl = |
| 3245 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 3246 | Diag(VD->getLocation(), |
| 3247 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 3248 | << VD; |
| 3249 | continue; |
| 3250 | } |
| 3251 | |
| 3252 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3253 | // A list-item cannot appear in more than one aligned clause. |
| 3254 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 3255 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 3256 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3257 | << getOpenMPClauseName(OMPC_aligned); |
| 3258 | continue; |
| 3259 | } |
| 3260 | |
| 3261 | Vars.push_back(DE); |
| 3262 | } |
| 3263 | |
| 3264 | // OpenMP [2.8.1, simd construct, Description] |
| 3265 | // The parameter of the aligned clause, alignment, must be a constant |
| 3266 | // positive integer expression. |
| 3267 | // If no optional parameter is specified, implementation-defined default |
| 3268 | // alignments for SIMD instructions on the target platforms are assumed. |
| 3269 | if (Alignment != nullptr) { |
| 3270 | ExprResult AlignResult = |
| 3271 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 3272 | if (AlignResult.isInvalid()) |
| 3273 | return nullptr; |
| 3274 | Alignment = AlignResult.get(); |
| 3275 | } |
| 3276 | if (Vars.empty()) |
| 3277 | return nullptr; |
| 3278 | |
| 3279 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 3280 | EndLoc, Vars, Alignment); |
| 3281 | } |
| 3282 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3283 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 3284 | SourceLocation StartLoc, |
| 3285 | SourceLocation LParenLoc, |
| 3286 | SourceLocation EndLoc) { |
| 3287 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3288 | for (auto &RefExpr : VarList) { |
| 3289 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 3290 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3291 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3292 | Vars.push_back(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3293 | continue; |
| 3294 | } |
| 3295 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3296 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3297 | // OpenMP [2.1, C/C++] |
| 3298 | // A list item is a variable name. |
| 3299 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 3300 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3301 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3302 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3303 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3304 | continue; |
| 3305 | } |
| 3306 | |
| 3307 | Decl *D = DE->getDecl(); |
| 3308 | VarDecl *VD = cast<VarDecl>(D); |
| 3309 | |
| 3310 | QualType Type = VD->getType(); |
| 3311 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 3312 | // It will be analyzed later. |
| 3313 | Vars.push_back(DE); |
| 3314 | continue; |
| 3315 | } |
| 3316 | |
| 3317 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 3318 | // A list item that appears in a copyin clause must be threadprivate. |
| 3319 | if (!DSAStack->isThreadPrivate(VD)) { |
| 3320 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3321 | << getOpenMPClauseName(OMPC_copyin) |
| 3322 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3323 | continue; |
| 3324 | } |
| 3325 | |
| 3326 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 3327 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3328 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3329 | // operator for the class type. |
| 3330 | Type = Context.getBaseElementType(Type); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 3331 | CXXRecordDecl *RD = |
| 3332 | getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3333 | // FIXME This code must be replaced by actual assignment of the |
| 3334 | // threadprivate variable. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3335 | if (RD) { |
| 3336 | CXXMethodDecl *MD = LookupCopyingAssignment(RD, 0, false, 0); |
| 3337 | DeclAccessPair FoundDecl = DeclAccessPair::make(MD, MD->getAccess()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3338 | if (MD) { |
| 3339 | if (CheckMemberAccess(ELoc, RD, FoundDecl) == AR_inaccessible || |
| 3340 | MD->isDeleted()) { |
| 3341 | Diag(ELoc, diag::err_omp_required_method) |
| 3342 | << getOpenMPClauseName(OMPC_copyin) << 2; |
| 3343 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 3344 | VarDecl::DeclarationOnly; |
| 3345 | Diag(VD->getLocation(), |
| 3346 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 3347 | << VD; |
| 3348 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 3349 | continue; |
| 3350 | } |
| 3351 | MarkFunctionReferenced(ELoc, MD); |
| 3352 | DiagnoseUseOfDecl(MD, ELoc); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3353 | } |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 3357 | Vars.push_back(DE); |
| 3358 | } |
| 3359 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3360 | if (Vars.empty()) |
| 3361 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3362 | |
| 3363 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 3364 | } |
| 3365 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 3366 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 3367 | SourceLocation StartLoc, |
| 3368 | SourceLocation LParenLoc, |
| 3369 | SourceLocation EndLoc) { |
| 3370 | SmallVector<Expr *, 8> Vars; |
| 3371 | for (auto &RefExpr : VarList) { |
| 3372 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 3373 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 3374 | // It will be analyzed later. |
| 3375 | Vars.push_back(RefExpr); |
| 3376 | continue; |
| 3377 | } |
| 3378 | |
| 3379 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 3380 | // OpenMP [2.1, C/C++] |
| 3381 | // A list item is a variable name. |
| 3382 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 3383 | // A list item that appears in a copyin clause must be threadprivate. |
| 3384 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 3385 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 3386 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 3387 | continue; |
| 3388 | } |
| 3389 | |
| 3390 | Decl *D = DE->getDecl(); |
| 3391 | VarDecl *VD = cast<VarDecl>(D); |
| 3392 | |
| 3393 | QualType Type = VD->getType(); |
| 3394 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 3395 | // It will be analyzed later. |
| 3396 | Vars.push_back(DE); |
| 3397 | continue; |
| 3398 | } |
| 3399 | |
| 3400 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 3401 | // A list item that appears in a copyprivate clause may not appear in a |
| 3402 | // private or firstprivate clause on the single construct. |
| 3403 | if (!DSAStack->isThreadPrivate(VD)) { |
| 3404 | auto DVar = DSAStack->getTopDSA(VD); |
| 3405 | if (DVar.CKind != OMPC_copyprivate && DVar.CKind != OMPC_unknown && |
| 3406 | !(DVar.CKind == OMPC_private && !DVar.RefExpr)) { |
| 3407 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 3408 | << getOpenMPClauseName(DVar.CKind) |
| 3409 | << getOpenMPClauseName(OMPC_copyprivate); |
| 3410 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 3411 | continue; |
| 3412 | } |
| 3413 | |
| 3414 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 3415 | // All list items that appear in a copyprivate clause must be either |
| 3416 | // threadprivate or private in the enclosing context. |
| 3417 | if (DVar.CKind == OMPC_unknown) { |
| 3418 | DVar = DSAStack->getImplicitDSA(VD); |
| 3419 | if (DVar.CKind == OMPC_shared) { |
| 3420 | Diag(ELoc, diag::err_omp_required_access) |
| 3421 | << getOpenMPClauseName(OMPC_copyprivate) |
| 3422 | << "threadprivate or private in the enclosing context"; |
| 3423 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 3424 | continue; |
| 3425 | } |
| 3426 | } |
| 3427 | } |
| 3428 | |
| 3429 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 3430 | // A variable of class type (or array thereof) that appears in a |
| 3431 | // copyin clause requires an accessible, unambiguous copy assignment |
| 3432 | // operator for the class type. |
| 3433 | Type = Context.getBaseElementType(Type); |
| 3434 | CXXRecordDecl *RD = |
| 3435 | getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
| 3436 | // FIXME This code must be replaced by actual assignment of the |
| 3437 | // threadprivate variable. |
| 3438 | if (RD) { |
| 3439 | CXXMethodDecl *MD = LookupCopyingAssignment(RD, 0, false, 0); |
| 3440 | DeclAccessPair FoundDecl = DeclAccessPair::make(MD, MD->getAccess()); |
| 3441 | if (MD) { |
| 3442 | if (CheckMemberAccess(ELoc, RD, FoundDecl) == AR_inaccessible || |
| 3443 | MD->isDeleted()) { |
| 3444 | Diag(ELoc, diag::err_omp_required_method) |
| 3445 | << getOpenMPClauseName(OMPC_copyprivate) << 2; |
| 3446 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 3447 | VarDecl::DeclarationOnly; |
| 3448 | Diag(VD->getLocation(), |
| 3449 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 3450 | << VD; |
| 3451 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 3452 | continue; |
| 3453 | } |
| 3454 | MarkFunctionReferenced(ELoc, MD); |
| 3455 | DiagnoseUseOfDecl(MD, ELoc); |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 3460 | // implicitly private. |
| 3461 | Vars.push_back(DE); |
| 3462 | } |
| 3463 | |
| 3464 | if (Vars.empty()) |
| 3465 | return nullptr; |
| 3466 | |
| 3467 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 3468 | } |
| 3469 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3470 | #undef DSAStack |