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