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