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