File: | tools/clang/lib/Sema/SemaOpenMP.cpp |
Location: | line 1014, column 38 |
Description: | Called C++ object pointer is null |
1 | //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===// | |||
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 | |||
11 | /// clauses. | |||
12 | /// | |||
13 | //===----------------------------------------------------------------------===// | |||
14 | ||||
15 | #include "TreeTransform.h" | |||
16 | #include "clang/AST/ASTContext.h" | |||
17 | #include "clang/AST/ASTMutationListener.h" | |||
18 | #include "clang/AST/CXXInheritance.h" | |||
19 | #include "clang/AST/Decl.h" | |||
20 | #include "clang/AST/DeclCXX.h" | |||
21 | #include "clang/AST/DeclOpenMP.h" | |||
22 | #include "clang/AST/StmtCXX.h" | |||
23 | #include "clang/AST/StmtOpenMP.h" | |||
24 | #include "clang/AST/StmtVisitor.h" | |||
25 | #include "clang/AST/TypeOrdering.h" | |||
26 | #include "clang/Basic/OpenMPKinds.h" | |||
27 | #include "clang/Basic/TargetInfo.h" | |||
28 | #include "clang/Lex/Preprocessor.h" | |||
29 | #include "clang/Sema/Initialization.h" | |||
30 | #include "clang/Sema/Lookup.h" | |||
31 | #include "clang/Sema/Scope.h" | |||
32 | #include "clang/Sema/ScopeInfo.h" | |||
33 | #include "clang/Sema/SemaInternal.h" | |||
34 | using namespace clang; | |||
35 | ||||
36 | //===----------------------------------------------------------------------===// | |||
37 | // Stack of data-sharing attributes for variables | |||
38 | //===----------------------------------------------------------------------===// | |||
39 | ||||
40 | namespace { | |||
41 | /// \brief Default data sharing attributes, which can be applied to directive. | |||
42 | enum DefaultDataSharingAttributes { | |||
43 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. | |||
44 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. | |||
45 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. | |||
46 | }; | |||
47 | ||||
48 | /// \brief Stack for tracking declarations used in OpenMP directives and | |||
49 | /// clauses and their data-sharing attributes. | |||
50 | class DSAStackTy final { | |||
51 | public: | |||
52 | struct DSAVarData final { | |||
53 | OpenMPDirectiveKind DKind = OMPD_unknown; | |||
54 | OpenMPClauseKind CKind = OMPC_unknown; | |||
55 | Expr *RefExpr = nullptr; | |||
56 | DeclRefExpr *PrivateCopy = nullptr; | |||
57 | SourceLocation ImplicitDSALoc; | |||
58 | DSAVarData() {} | |||
59 | }; | |||
60 | typedef llvm::SmallVector<std::pair<Expr *, OverloadedOperatorKind>, 4> | |||
61 | OperatorOffsetTy; | |||
62 | ||||
63 | private: | |||
64 | struct DSAInfo final { | |||
65 | OpenMPClauseKind Attributes = OMPC_unknown; | |||
66 | /// Pointer to a reference expression and a flag which shows that the | |||
67 | /// variable is marked as lastprivate(true) or not (false). | |||
68 | llvm::PointerIntPair<Expr *, 1, bool> RefExpr; | |||
69 | DeclRefExpr *PrivateCopy = nullptr; | |||
70 | }; | |||
71 | typedef llvm::DenseMap<ValueDecl *, DSAInfo> DeclSAMapTy; | |||
72 | typedef llvm::DenseMap<ValueDecl *, Expr *> AlignedMapTy; | |||
73 | typedef std::pair<unsigned, VarDecl *> LCDeclInfo; | |||
74 | typedef llvm::DenseMap<ValueDecl *, LCDeclInfo> LoopControlVariablesMapTy; | |||
75 | typedef llvm::DenseMap< | |||
76 | ValueDecl *, OMPClauseMappableExprCommon::MappableExprComponentLists> | |||
77 | MappedExprComponentsTy; | |||
78 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> | |||
79 | CriticalsWithHintsTy; | |||
80 | typedef llvm::DenseMap<OMPDependClause *, OperatorOffsetTy> | |||
81 | DoacrossDependMapTy; | |||
82 | ||||
83 | struct SharingMapTy final { | |||
84 | DeclSAMapTy SharingMap; | |||
85 | AlignedMapTy AlignedMap; | |||
86 | MappedExprComponentsTy MappedExprComponents; | |||
87 | LoopControlVariablesMapTy LCVMap; | |||
88 | DefaultDataSharingAttributes DefaultAttr = DSA_unspecified; | |||
89 | SourceLocation DefaultAttrLoc; | |||
90 | OpenMPDirectiveKind Directive = OMPD_unknown; | |||
91 | DeclarationNameInfo DirectiveName; | |||
92 | Scope *CurScope = nullptr; | |||
93 | SourceLocation ConstructLoc; | |||
94 | /// Set of 'depend' clauses with 'sink|source' dependence kind. Required to | |||
95 | /// get the data (loop counters etc.) about enclosing loop-based construct. | |||
96 | /// This data is required during codegen. | |||
97 | DoacrossDependMapTy DoacrossDepends; | |||
98 | /// \brief first argument (Expr *) contains optional argument of the | |||
99 | /// 'ordered' clause, the second one is true if the regions has 'ordered' | |||
100 | /// clause, false otherwise. | |||
101 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; | |||
102 | bool NowaitRegion = false; | |||
103 | bool CancelRegion = false; | |||
104 | unsigned AssociatedLoops = 1; | |||
105 | SourceLocation InnerTeamsRegionLoc; | |||
106 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, | |||
107 | Scope *CurScope, SourceLocation Loc) | |||
108 | : Directive(DKind), DirectiveName(Name), CurScope(CurScope), | |||
109 | ConstructLoc(Loc) {} | |||
110 | SharingMapTy() {} | |||
111 | }; | |||
112 | ||||
113 | typedef SmallVector<SharingMapTy, 4> StackTy; | |||
114 | ||||
115 | /// \brief Stack of used declaration and their data-sharing attributes. | |||
116 | StackTy Stack; | |||
117 | /// \brief true, if check for DSA must be from parent directive, false, if | |||
118 | /// from current directive. | |||
119 | OpenMPClauseKind ClauseKindMode = OMPC_unknown; | |||
120 | Sema &SemaRef; | |||
121 | bool ForceCapturing = false; | |||
122 | CriticalsWithHintsTy Criticals; | |||
123 | ||||
124 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; | |||
125 | ||||
126 | DSAVarData getDSA(StackTy::reverse_iterator& Iter, ValueDecl *D); | |||
127 | ||||
128 | /// \brief Checks if the variable is a local for OpenMP region. | |||
129 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); | |||
130 | ||||
131 | public: | |||
132 | explicit DSAStackTy(Sema &S) : Stack(1), SemaRef(S) {} | |||
133 | ||||
134 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } | |||
135 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } | |||
136 | ||||
137 | bool isForceVarCapturing() const { return ForceCapturing; } | |||
138 | void setForceVarCapturing(bool V) { ForceCapturing = V; } | |||
139 | ||||
140 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, | |||
141 | Scope *CurScope, SourceLocation Loc) { | |||
142 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); | |||
143 | Stack.back().DefaultAttrLoc = Loc; | |||
144 | } | |||
145 | ||||
146 | void pop() { | |||
147 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!")((Stack.size() > 1 && "Data-sharing attributes stack is empty!" ) ? static_cast<void> (0) : __assert_fail ("Stack.size() > 1 && \"Data-sharing attributes stack is empty!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 147, __PRETTY_FUNCTION__)); | |||
148 | Stack.pop_back(); | |||
149 | } | |||
150 | ||||
151 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { | |||
152 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); | |||
153 | } | |||
154 | const std::pair<OMPCriticalDirective *, llvm::APSInt> | |||
155 | getCriticalWithHint(const DeclarationNameInfo &Name) const { | |||
156 | auto I = Criticals.find(Name.getAsString()); | |||
157 | if (I != Criticals.end()) | |||
158 | return I->second; | |||
159 | return std::make_pair(nullptr, llvm::APSInt()); | |||
160 | } | |||
161 | /// \brief If 'aligned' declaration for given variable \a D was not seen yet, | |||
162 | /// add it and return NULL; otherwise return previous occurrence's expression | |||
163 | /// for diagnostics. | |||
164 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); | |||
165 | ||||
166 | /// \brief Register specified variable as loop control variable. | |||
167 | void addLoopControlVariable(ValueDecl *D, VarDecl *Capture); | |||
168 | /// \brief Check if the specified variable is a loop control variable for | |||
169 | /// current region. | |||
170 | /// \return The index of the loop control variable in the list of associated | |||
171 | /// for-loops (from outer to inner). | |||
172 | LCDeclInfo isLoopControlVariable(ValueDecl *D); | |||
173 | /// \brief Check if the specified variable is a loop control variable for | |||
174 | /// parent region. | |||
175 | /// \return The index of the loop control variable in the list of associated | |||
176 | /// for-loops (from outer to inner). | |||
177 | LCDeclInfo isParentLoopControlVariable(ValueDecl *D); | |||
178 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in | |||
179 | /// parent directive. | |||
180 | ValueDecl *getParentLoopControlVariable(unsigned I); | |||
181 | ||||
182 | /// \brief Adds explicit data sharing attribute to the specified declaration. | |||
183 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, | |||
184 | DeclRefExpr *PrivateCopy = nullptr); | |||
185 | ||||
186 | /// \brief Returns data sharing attributes from top of the stack for the | |||
187 | /// specified declaration. | |||
188 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); | |||
189 | /// \brief Returns data-sharing attributes for the specified declaration. | |||
190 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); | |||
191 | /// \brief Checks if the specified variables has data-sharing attributes which | |||
192 | /// match specified \a CPred predicate in any directive which matches \a DPred | |||
193 | /// predicate. | |||
194 | DSAVarData hasDSA(ValueDecl *D, | |||
195 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, | |||
196 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, | |||
197 | bool FromParent); | |||
198 | /// \brief Checks if the specified variables has data-sharing attributes which | |||
199 | /// match specified \a CPred predicate in any innermost directive which | |||
200 | /// matches \a DPred predicate. | |||
201 | DSAVarData | |||
202 | hasInnermostDSA(ValueDecl *D, | |||
203 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, | |||
204 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, | |||
205 | bool FromParent); | |||
206 | /// \brief Checks if the specified variables has explicit data-sharing | |||
207 | /// attributes which match specified \a CPred predicate at the specified | |||
208 | /// OpenMP region. | |||
209 | bool hasExplicitDSA(ValueDecl *D, | |||
210 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, | |||
211 | unsigned Level, bool NotLastprivate = false); | |||
212 | ||||
213 | /// \brief Returns true if the directive at level \Level matches in the | |||
214 | /// specified \a DPred predicate. | |||
215 | bool hasExplicitDirective( | |||
216 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, | |||
217 | unsigned Level); | |||
218 | ||||
219 | /// \brief Finds a directive which matches specified \a DPred predicate. | |||
220 | bool hasDirective(const llvm::function_ref<bool(OpenMPDirectiveKind, | |||
221 | const DeclarationNameInfo &, | |||
222 | SourceLocation)> &DPred, | |||
223 | bool FromParent); | |||
224 | ||||
225 | /// \brief Returns currently analyzed directive. | |||
226 | OpenMPDirectiveKind getCurrentDirective() const { | |||
227 | return Stack.back().Directive; | |||
228 | } | |||
229 | /// \brief Returns parent directive. | |||
230 | OpenMPDirectiveKind getParentDirective() const { | |||
231 | if (Stack.size() > 2) | |||
232 | return Stack[Stack.size() - 2].Directive; | |||
233 | return OMPD_unknown; | |||
234 | } | |||
235 | ||||
236 | /// \brief Set default data sharing attribute to none. | |||
237 | void setDefaultDSANone(SourceLocation Loc) { | |||
238 | Stack.back().DefaultAttr = DSA_none; | |||
239 | Stack.back().DefaultAttrLoc = Loc; | |||
240 | } | |||
241 | /// \brief Set default data sharing attribute to shared. | |||
242 | void setDefaultDSAShared(SourceLocation Loc) { | |||
243 | Stack.back().DefaultAttr = DSA_shared; | |||
244 | Stack.back().DefaultAttrLoc = Loc; | |||
245 | } | |||
246 | ||||
247 | DefaultDataSharingAttributes getDefaultDSA() const { | |||
248 | return Stack.back().DefaultAttr; | |||
249 | } | |||
250 | SourceLocation getDefaultDSALocation() const { | |||
251 | return Stack.back().DefaultAttrLoc; | |||
252 | } | |||
253 | ||||
254 | /// \brief Checks if the specified variable is a threadprivate. | |||
255 | bool isThreadPrivate(VarDecl *D) { | |||
256 | DSAVarData DVar = getTopDSA(D, false); | |||
257 | return isOpenMPThreadPrivate(DVar.CKind); | |||
258 | } | |||
259 | ||||
260 | /// \brief Marks current region as ordered (it has an 'ordered' clause). | |||
261 | void setOrderedRegion(bool IsOrdered, Expr *Param) { | |||
262 | Stack.back().OrderedRegion.setInt(IsOrdered); | |||
263 | Stack.back().OrderedRegion.setPointer(Param); | |||
264 | } | |||
265 | /// \brief Returns true, if parent region is ordered (has associated | |||
266 | /// 'ordered' clause), false - otherwise. | |||
267 | bool isParentOrderedRegion() const { | |||
268 | if (Stack.size() > 2) | |||
269 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); | |||
270 | return false; | |||
271 | } | |||
272 | /// \brief Returns optional parameter for the ordered region. | |||
273 | Expr *getParentOrderedRegionParam() const { | |||
274 | if (Stack.size() > 2) | |||
275 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); | |||
276 | return nullptr; | |||
277 | } | |||
278 | /// \brief Marks current region as nowait (it has a 'nowait' clause). | |||
279 | void setNowaitRegion(bool IsNowait = true) { | |||
280 | Stack.back().NowaitRegion = IsNowait; | |||
281 | } | |||
282 | /// \brief Returns true, if parent region is nowait (has associated | |||
283 | /// 'nowait' clause), false - otherwise. | |||
284 | bool isParentNowaitRegion() const { | |||
285 | if (Stack.size() > 2) | |||
286 | return Stack[Stack.size() - 2].NowaitRegion; | |||
287 | return false; | |||
288 | } | |||
289 | /// \brief Marks parent region as cancel region. | |||
290 | void setParentCancelRegion(bool Cancel = true) { | |||
291 | if (Stack.size() > 2) | |||
292 | Stack[Stack.size() - 2].CancelRegion = | |||
293 | Stack[Stack.size() - 2].CancelRegion || Cancel; | |||
294 | } | |||
295 | /// \brief Return true if current region has inner cancel construct. | |||
296 | bool isCancelRegion() const { | |||
297 | return Stack.back().CancelRegion; | |||
298 | } | |||
299 | ||||
300 | /// \brief Set collapse value for the region. | |||
301 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } | |||
302 | /// \brief Return collapse value for region. | |||
303 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } | |||
304 | ||||
305 | /// \brief Marks current target region as one with closely nested teams | |||
306 | /// region. | |||
307 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { | |||
308 | if (Stack.size() > 2) | |||
309 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; | |||
310 | } | |||
311 | /// \brief Returns true, if current region has closely nested teams region. | |||
312 | bool hasInnerTeamsRegion() const { | |||
313 | return getInnerTeamsRegionLoc().isValid(); | |||
314 | } | |||
315 | /// \brief Returns location of the nested teams region (if any). | |||
316 | SourceLocation getInnerTeamsRegionLoc() const { | |||
317 | if (Stack.size() > 1) | |||
318 | return Stack.back().InnerTeamsRegionLoc; | |||
319 | return SourceLocation(); | |||
320 | } | |||
321 | ||||
322 | Scope *getCurScope() const { return Stack.back().CurScope; } | |||
323 | Scope *getCurScope() { return Stack.back().CurScope; } | |||
324 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } | |||
325 | ||||
326 | // Do the check specified in \a Check to all component lists and return true | |||
327 | // if any issue is found. | |||
328 | bool checkMappableExprComponentListsForDecl( | |||
329 | ValueDecl *VD, bool CurrentRegionOnly, | |||
330 | const llvm::function_ref<bool( | |||
331 | OMPClauseMappableExprCommon::MappableExprComponentListRef)> &Check) { | |||
332 | auto SI = Stack.rbegin(); | |||
333 | auto SE = Stack.rend(); | |||
334 | ||||
335 | if (SI == SE) | |||
336 | return false; | |||
337 | ||||
338 | if (CurrentRegionOnly) { | |||
339 | SE = std::next(SI); | |||
340 | } else { | |||
341 | ++SI; | |||
342 | } | |||
343 | ||||
344 | for (; SI != SE; ++SI) { | |||
345 | auto MI = SI->MappedExprComponents.find(VD); | |||
346 | if (MI != SI->MappedExprComponents.end()) | |||
347 | for (auto &L : MI->second) | |||
348 | if (Check(L)) | |||
349 | return true; | |||
350 | } | |||
351 | return false; | |||
352 | } | |||
353 | ||||
354 | // Create a new mappable expression component list associated with a given | |||
355 | // declaration and initialize it with the provided list of components. | |||
356 | void addMappableExpressionComponents( | |||
357 | ValueDecl *VD, | |||
358 | OMPClauseMappableExprCommon::MappableExprComponentListRef Components) { | |||
359 | assert(Stack.size() > 1 &&((Stack.size() > 1 && "Not expecting to retrieve components from a empty stack!" ) ? static_cast<void> (0) : __assert_fail ("Stack.size() > 1 && \"Not expecting to retrieve components from a empty stack!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 360, __PRETTY_FUNCTION__)) | |||
360 | "Not expecting to retrieve components from a empty stack!")((Stack.size() > 1 && "Not expecting to retrieve components from a empty stack!" ) ? static_cast<void> (0) : __assert_fail ("Stack.size() > 1 && \"Not expecting to retrieve components from a empty stack!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 360, __PRETTY_FUNCTION__)); | |||
361 | auto &MEC = Stack.back().MappedExprComponents[VD]; | |||
362 | // Create new entry and append the new components there. | |||
363 | MEC.resize(MEC.size() + 1); | |||
364 | MEC.back().append(Components.begin(), Components.end()); | |||
365 | } | |||
366 | ||||
367 | unsigned getNestingLevel() const { | |||
368 | assert(Stack.size() > 1)((Stack.size() > 1) ? static_cast<void> (0) : __assert_fail ("Stack.size() > 1", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 368, __PRETTY_FUNCTION__)); | |||
369 | return Stack.size() - 2; | |||
370 | } | |||
371 | void addDoacrossDependClause(OMPDependClause *C, OperatorOffsetTy &OpsOffs) { | |||
372 | assert(Stack.size() > 2)((Stack.size() > 2) ? static_cast<void> (0) : __assert_fail ("Stack.size() > 2", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 372, __PRETTY_FUNCTION__)); | |||
373 | assert(isOpenMPWorksharingDirective(Stack[Stack.size() - 2].Directive))((isOpenMPWorksharingDirective(Stack[Stack.size() - 2].Directive )) ? static_cast<void> (0) : __assert_fail ("isOpenMPWorksharingDirective(Stack[Stack.size() - 2].Directive)" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 373, __PRETTY_FUNCTION__)); | |||
374 | Stack[Stack.size() - 2].DoacrossDepends.insert({C, OpsOffs}); | |||
375 | } | |||
376 | llvm::iterator_range<DoacrossDependMapTy::const_iterator> | |||
377 | getDoacrossDependClauses() const { | |||
378 | assert(Stack.size() > 1)((Stack.size() > 1) ? static_cast<void> (0) : __assert_fail ("Stack.size() > 1", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 378, __PRETTY_FUNCTION__)); | |||
379 | if (isOpenMPWorksharingDirective(Stack[Stack.size() - 1].Directive)) { | |||
380 | auto &Ref = Stack[Stack.size() - 1].DoacrossDepends; | |||
381 | return llvm::make_range(Ref.begin(), Ref.end()); | |||
382 | } | |||
383 | return llvm::make_range(Stack[0].DoacrossDepends.end(), | |||
384 | Stack[0].DoacrossDepends.end()); | |||
385 | } | |||
386 | }; | |||
387 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { | |||
388 | return isOpenMPParallelDirective(DKind) || isOpenMPTaskingDirective(DKind) || | |||
389 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; | |||
390 | } | |||
391 | } // namespace | |||
392 | ||||
393 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { | |||
394 | auto *VD = dyn_cast<VarDecl>(D); | |||
395 | auto *FD = dyn_cast<FieldDecl>(D); | |||
396 | if (VD != nullptr) { | |||
397 | VD = VD->getCanonicalDecl(); | |||
398 | D = VD; | |||
399 | } else { | |||
400 | assert(FD)((FD) ? static_cast<void> (0) : __assert_fail ("FD", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 400, __PRETTY_FUNCTION__)); | |||
401 | FD = FD->getCanonicalDecl(); | |||
402 | D = FD; | |||
403 | } | |||
404 | return D; | |||
405 | } | |||
406 | ||||
407 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator& Iter, | |||
408 | ValueDecl *D) { | |||
409 | D = getCanonicalDecl(D); | |||
410 | auto *VD = dyn_cast<VarDecl>(D); | |||
411 | auto *FD = dyn_cast<FieldDecl>(D); | |||
412 | DSAVarData DVar; | |||
413 | if (Iter == std::prev(Stack.rend())) { | |||
414 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
415 | // in a region but not in construct] | |||
416 | // File-scope or namespace-scope variables referenced in called routines | |||
417 | // in the region are shared unless they appear in a threadprivate | |||
418 | // directive. | |||
419 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) | |||
420 | DVar.CKind = OMPC_shared; | |||
421 | ||||
422 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced | |||
423 | // in a region but not in construct] | |||
424 | // Variables with static storage duration that are declared in called | |||
425 | // routines in the region are shared. | |||
426 | if (VD && VD->hasGlobalStorage()) | |||
427 | DVar.CKind = OMPC_shared; | |||
428 | ||||
429 | // Non-static data members are shared by default. | |||
430 | if (FD) | |||
431 | DVar.CKind = OMPC_shared; | |||
432 | ||||
433 | return DVar; | |||
434 | } | |||
435 | ||||
436 | DVar.DKind = Iter->Directive; | |||
437 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
438 | // in a Construct, C/C++, predetermined, p.1] | |||
439 | // Variables with automatic storage duration that are declared in a scope | |||
440 | // inside the construct are private. | |||
441 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && | |||
442 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { | |||
443 | DVar.CKind = OMPC_private; | |||
444 | return DVar; | |||
445 | } | |||
446 | ||||
447 | // Explicitly specified attributes and local variables with predetermined | |||
448 | // attributes. | |||
449 | if (Iter->SharingMap.count(D)) { | |||
450 | DVar.RefExpr = Iter->SharingMap[D].RefExpr.getPointer(); | |||
451 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; | |||
452 | DVar.CKind = Iter->SharingMap[D].Attributes; | |||
453 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; | |||
454 | return DVar; | |||
455 | } | |||
456 | ||||
457 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
458 | // in a Construct, C/C++, implicitly determined, p.1] | |||
459 | // In a parallel or task construct, the data-sharing attributes of these | |||
460 | // variables are determined by the default clause, if present. | |||
461 | switch (Iter->DefaultAttr) { | |||
462 | case DSA_shared: | |||
463 | DVar.CKind = OMPC_shared; | |||
464 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; | |||
465 | return DVar; | |||
466 | case DSA_none: | |||
467 | return DVar; | |||
468 | case DSA_unspecified: | |||
469 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
470 | // in a Construct, implicitly determined, p.2] | |||
471 | // In a parallel construct, if no default clause is present, these | |||
472 | // variables are shared. | |||
473 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; | |||
474 | if (isOpenMPParallelDirective(DVar.DKind) || | |||
475 | isOpenMPTeamsDirective(DVar.DKind)) { | |||
476 | DVar.CKind = OMPC_shared; | |||
477 | return DVar; | |||
478 | } | |||
479 | ||||
480 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
481 | // in a Construct, implicitly determined, p.4] | |||
482 | // In a task construct, if no default clause is present, a variable that in | |||
483 | // the enclosing context is determined to be shared by all implicit tasks | |||
484 | // bound to the current team is shared. | |||
485 | if (isOpenMPTaskingDirective(DVar.DKind)) { | |||
486 | DSAVarData DVarTemp; | |||
487 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); | |||
488 | I != EE; ++I) { | |||
489 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables | |||
490 | // Referenced in a Construct, implicitly determined, p.6] | |||
491 | // In a task construct, if no default clause is present, a variable | |||
492 | // whose data-sharing attribute is not determined by the rules above is | |||
493 | // firstprivate. | |||
494 | DVarTemp = getDSA(I, D); | |||
495 | if (DVarTemp.CKind != OMPC_shared) { | |||
496 | DVar.RefExpr = nullptr; | |||
497 | DVar.CKind = OMPC_firstprivate; | |||
498 | return DVar; | |||
499 | } | |||
500 | if (isParallelOrTaskRegion(I->Directive)) | |||
501 | break; | |||
502 | } | |||
503 | DVar.CKind = | |||
504 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; | |||
505 | return DVar; | |||
506 | } | |||
507 | } | |||
508 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
509 | // in a Construct, implicitly determined, p.3] | |||
510 | // For constructs other than task, if no default clause is present, these | |||
511 | // variables inherit their data-sharing attributes from the enclosing | |||
512 | // context. | |||
513 | return getDSA(++Iter, D); | |||
514 | } | |||
515 | ||||
516 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { | |||
517 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty")((Stack.size() > 1 && "Data sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("Stack.size() > 1 && \"Data sharing attributes stack is empty\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 517, __PRETTY_FUNCTION__)); | |||
518 | D = getCanonicalDecl(D); | |||
519 | auto It = Stack.back().AlignedMap.find(D); | |||
520 | if (It == Stack.back().AlignedMap.end()) { | |||
521 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map")((NewDE && "Unexpected nullptr expr to be added into aligned map" ) ? static_cast<void> (0) : __assert_fail ("NewDE && \"Unexpected nullptr expr to be added into aligned map\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 521, __PRETTY_FUNCTION__)); | |||
522 | Stack.back().AlignedMap[D] = NewDE; | |||
523 | return nullptr; | |||
524 | } else { | |||
525 | assert(It->second && "Unexpected nullptr expr in the aligned map")((It->second && "Unexpected nullptr expr in the aligned map" ) ? static_cast<void> (0) : __assert_fail ("It->second && \"Unexpected nullptr expr in the aligned map\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 525, __PRETTY_FUNCTION__)); | |||
526 | return It->second; | |||
527 | } | |||
528 | return nullptr; | |||
529 | } | |||
530 | ||||
531 | void DSAStackTy::addLoopControlVariable(ValueDecl *D, VarDecl *Capture) { | |||
532 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty")((Stack.size() > 1 && "Data-sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("Stack.size() > 1 && \"Data-sharing attributes stack is empty\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 532, __PRETTY_FUNCTION__)); | |||
533 | D = getCanonicalDecl(D); | |||
534 | Stack.back().LCVMap.insert( | |||
535 | std::make_pair(D, LCDeclInfo(Stack.back().LCVMap.size() + 1, Capture))); | |||
536 | } | |||
537 | ||||
538 | DSAStackTy::LCDeclInfo DSAStackTy::isLoopControlVariable(ValueDecl *D) { | |||
539 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty")((Stack.size() > 1 && "Data-sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("Stack.size() > 1 && \"Data-sharing attributes stack is empty\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 539, __PRETTY_FUNCTION__)); | |||
540 | D = getCanonicalDecl(D); | |||
541 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] | |||
542 | : LCDeclInfo(0, nullptr); | |||
543 | } | |||
544 | ||||
545 | DSAStackTy::LCDeclInfo DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { | |||
546 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty")((Stack.size() > 2 && "Data-sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("Stack.size() > 2 && \"Data-sharing attributes stack is empty\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 546, __PRETTY_FUNCTION__)); | |||
547 | D = getCanonicalDecl(D); | |||
548 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 | |||
549 | ? Stack[Stack.size() - 2].LCVMap[D] | |||
550 | : LCDeclInfo(0, nullptr); | |||
551 | } | |||
552 | ||||
553 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { | |||
554 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty")((Stack.size() > 2 && "Data-sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("Stack.size() > 2 && \"Data-sharing attributes stack is empty\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 554, __PRETTY_FUNCTION__)); | |||
555 | if (Stack[Stack.size() - 2].LCVMap.size() < I) | |||
556 | return nullptr; | |||
557 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { | |||
558 | if (Pair.second.first == I) | |||
559 | return Pair.first; | |||
560 | } | |||
561 | return nullptr; | |||
562 | } | |||
563 | ||||
564 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, | |||
565 | DeclRefExpr *PrivateCopy) { | |||
566 | D = getCanonicalDecl(D); | |||
567 | if (A == OMPC_threadprivate) { | |||
568 | auto &Data = Stack[0].SharingMap[D]; | |||
569 | Data.Attributes = A; | |||
570 | Data.RefExpr.setPointer(E); | |||
571 | Data.PrivateCopy = nullptr; | |||
572 | } else { | |||
573 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty")((Stack.size() > 1 && "Data-sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("Stack.size() > 1 && \"Data-sharing attributes stack is empty\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 573, __PRETTY_FUNCTION__)); | |||
574 | auto &Data = Stack.back().SharingMap[D]; | |||
575 | assert(Data.Attributes == OMPC_unknown || (A == Data.Attributes) ||((Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate ) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate ) || (isLoopControlVariable(D).first && A == OMPC_private )) ? static_cast<void> (0) : __assert_fail ("Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || (isLoopControlVariable(D).first && A == OMPC_private)" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 578, __PRETTY_FUNCTION__)) | |||
576 | (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) ||((Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate ) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate ) || (isLoopControlVariable(D).first && A == OMPC_private )) ? static_cast<void> (0) : __assert_fail ("Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || (isLoopControlVariable(D).first && A == OMPC_private)" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 578, __PRETTY_FUNCTION__)) | |||
577 | (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) ||((Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate ) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate ) || (isLoopControlVariable(D).first && A == OMPC_private )) ? static_cast<void> (0) : __assert_fail ("Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || (isLoopControlVariable(D).first && A == OMPC_private)" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 578, __PRETTY_FUNCTION__)) | |||
578 | (isLoopControlVariable(D).first && A == OMPC_private))((Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate ) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate ) || (isLoopControlVariable(D).first && A == OMPC_private )) ? static_cast<void> (0) : __assert_fail ("Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || (isLoopControlVariable(D).first && A == OMPC_private)" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 578, __PRETTY_FUNCTION__)); | |||
579 | if (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) { | |||
580 | Data.RefExpr.setInt(/*IntVal=*/true); | |||
581 | return; | |||
582 | } | |||
583 | const bool IsLastprivate = | |||
584 | A == OMPC_lastprivate || Data.Attributes == OMPC_lastprivate; | |||
585 | Data.Attributes = A; | |||
586 | Data.RefExpr.setPointerAndInt(E, IsLastprivate); | |||
587 | Data.PrivateCopy = PrivateCopy; | |||
588 | if (PrivateCopy) { | |||
589 | auto &Data = Stack.back().SharingMap[PrivateCopy->getDecl()]; | |||
590 | Data.Attributes = A; | |||
591 | Data.RefExpr.setPointerAndInt(PrivateCopy, IsLastprivate); | |||
592 | Data.PrivateCopy = nullptr; | |||
593 | } | |||
594 | } | |||
595 | } | |||
596 | ||||
597 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { | |||
598 | D = D->getCanonicalDecl(); | |||
599 | if (Stack.size() > 2) { | |||
600 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); | |||
601 | Scope *TopScope = nullptr; | |||
602 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { | |||
603 | ++I; | |||
604 | } | |||
605 | if (I == E) | |||
606 | return false; | |||
607 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; | |||
608 | Scope *CurScope = getCurScope(); | |||
609 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { | |||
610 | CurScope = CurScope->getParent(); | |||
611 | } | |||
612 | return CurScope != TopScope; | |||
613 | } | |||
614 | return false; | |||
615 | } | |||
616 | ||||
617 | /// \brief Build a variable declaration for OpenMP loop iteration variable. | |||
618 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, | |||
619 | StringRef Name, const AttrVec *Attrs = nullptr) { | |||
620 | DeclContext *DC = SemaRef.CurContext; | |||
621 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); | |||
622 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); | |||
623 | VarDecl *Decl = | |||
624 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); | |||
625 | if (Attrs) { | |||
626 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); | |||
627 | I != E; ++I) | |||
628 | Decl->addAttr(*I); | |||
629 | } | |||
630 | Decl->setImplicit(); | |||
631 | return Decl; | |||
632 | } | |||
633 | ||||
634 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, | |||
635 | SourceLocation Loc, | |||
636 | bool RefersToCapture = false) { | |||
637 | D->setReferenced(); | |||
638 | D->markUsed(S.Context); | |||
639 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), | |||
640 | SourceLocation(), D, RefersToCapture, Loc, Ty, | |||
641 | VK_LValue); | |||
642 | } | |||
643 | ||||
644 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { | |||
645 | D = getCanonicalDecl(D); | |||
646 | DSAVarData DVar; | |||
647 | ||||
648 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
649 | // in a Construct, C/C++, predetermined, p.1] | |||
650 | // Variables appearing in threadprivate directives are threadprivate. | |||
651 | auto *VD = dyn_cast<VarDecl>(D); | |||
652 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && | |||
653 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && | |||
654 | SemaRef.getLangOpts().OpenMPUseTLS && | |||
655 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || | |||
656 | (VD && VD->getStorageClass() == SC_Register && | |||
657 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { | |||
658 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), | |||
659 | D->getLocation()), | |||
660 | OMPC_threadprivate); | |||
661 | } | |||
662 | if (Stack[0].SharingMap.count(D)) { | |||
663 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr.getPointer(); | |||
664 | DVar.CKind = OMPC_threadprivate; | |||
665 | return DVar; | |||
666 | } | |||
667 | ||||
668 | if (Stack.size() == 1) { | |||
669 | // Not in OpenMP execution region and top scope was already checked. | |||
670 | return DVar; | |||
671 | } | |||
672 | ||||
673 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
674 | // in a Construct, C/C++, predetermined, p.4] | |||
675 | // Static data members are shared. | |||
676 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
677 | // in a Construct, C/C++, predetermined, p.7] | |||
678 | // Variables with static storage duration that are declared in a scope | |||
679 | // inside the construct are shared. | |||
680 | auto &&MatchesAlways = [](OpenMPDirectiveKind) -> bool { return true; }; | |||
681 | if (VD && VD->isStaticDataMember()) { | |||
682 | DSAVarData DVarTemp = hasDSA(D, isOpenMPPrivate, MatchesAlways, FromParent); | |||
683 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) | |||
684 | return DVar; | |||
685 | ||||
686 | DVar.CKind = OMPC_shared; | |||
687 | return DVar; | |||
688 | } | |||
689 | ||||
690 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); | |||
691 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); | |||
692 | Type = SemaRef.getASTContext().getBaseElementType(Type); | |||
693 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
694 | // in a Construct, C/C++, predetermined, p.6] | |||
695 | // Variables with const qualified type having no mutable member are | |||
696 | // shared. | |||
697 | CXXRecordDecl *RD = | |||
698 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; | |||
699 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) | |||
700 | if (auto *CTD = CTSD->getSpecializedTemplate()) | |||
701 | RD = CTD->getTemplatedDecl(); | |||
702 | if (IsConstant && | |||
703 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && | |||
704 | RD->hasMutableFields())) { | |||
705 | // Variables with const-qualified type having no mutable member may be | |||
706 | // listed in a firstprivate clause, even if they are static data members. | |||
707 | DSAVarData DVarTemp = hasDSA( | |||
708 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_firstprivate; }, | |||
709 | MatchesAlways, FromParent); | |||
710 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) | |||
711 | return DVar; | |||
712 | ||||
713 | DVar.CKind = OMPC_shared; | |||
714 | return DVar; | |||
715 | } | |||
716 | ||||
717 | // Explicitly specified attributes and local variables with predetermined | |||
718 | // attributes. | |||
719 | auto StartI = std::next(Stack.rbegin()); | |||
720 | auto EndI = std::prev(Stack.rend()); | |||
721 | if (FromParent && StartI != EndI) { | |||
722 | StartI = std::next(StartI); | |||
723 | } | |||
724 | auto I = std::prev(StartI); | |||
725 | if (I->SharingMap.count(D)) { | |||
726 | DVar.RefExpr = I->SharingMap[D].RefExpr.getPointer(); | |||
727 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; | |||
728 | DVar.CKind = I->SharingMap[D].Attributes; | |||
729 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; | |||
730 | } | |||
731 | ||||
732 | return DVar; | |||
733 | } | |||
734 | ||||
735 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, | |||
736 | bool FromParent) { | |||
737 | D = getCanonicalDecl(D); | |||
738 | auto StartI = Stack.rbegin(); | |||
739 | auto EndI = std::prev(Stack.rend()); | |||
740 | if (FromParent && StartI != EndI) { | |||
741 | StartI = std::next(StartI); | |||
742 | } | |||
743 | return getDSA(StartI, D); | |||
744 | } | |||
745 | ||||
746 | DSAStackTy::DSAVarData | |||
747 | DSAStackTy::hasDSA(ValueDecl *D, | |||
748 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, | |||
749 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, | |||
750 | bool FromParent) { | |||
751 | D = getCanonicalDecl(D); | |||
752 | auto StartI = std::next(Stack.rbegin()); | |||
753 | auto EndI = Stack.rend(); | |||
754 | if (FromParent && StartI != EndI) { | |||
755 | StartI = std::next(StartI); | |||
756 | } | |||
757 | for (auto I = StartI, EE = EndI; I != EE; ++I) { | |||
758 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) | |||
759 | continue; | |||
760 | DSAVarData DVar = getDSA(I, D); | |||
761 | if (CPred(DVar.CKind)) | |||
762 | return DVar; | |||
763 | } | |||
764 | return DSAVarData(); | |||
765 | } | |||
766 | ||||
767 | DSAStackTy::DSAVarData DSAStackTy::hasInnermostDSA( | |||
768 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, | |||
769 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, | |||
770 | bool FromParent) { | |||
771 | D = getCanonicalDecl(D); | |||
772 | auto StartI = std::next(Stack.rbegin()); | |||
773 | auto EndI = Stack.rend(); | |||
774 | if (FromParent && StartI != EndI) { | |||
775 | StartI = std::next(StartI); | |||
776 | } | |||
777 | for (auto I = StartI, EE = EndI; I != EE; ++I) { | |||
778 | if (!DPred(I->Directive)) | |||
779 | break; | |||
780 | DSAVarData DVar = getDSA(I, D); | |||
781 | if (CPred(DVar.CKind)) | |||
782 | return DVar; | |||
783 | return DSAVarData(); | |||
784 | } | |||
785 | return DSAVarData(); | |||
786 | } | |||
787 | ||||
788 | bool DSAStackTy::hasExplicitDSA( | |||
789 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, | |||
790 | unsigned Level, bool NotLastprivate) { | |||
791 | if (CPred(ClauseKindMode)) | |||
792 | return true; | |||
793 | D = getCanonicalDecl(D); | |||
794 | auto StartI = std::next(Stack.begin()); | |||
795 | auto EndI = Stack.end(); | |||
796 | if (std::distance(StartI, EndI) <= (int)Level) | |||
797 | return false; | |||
798 | std::advance(StartI, Level); | |||
799 | return (StartI->SharingMap.count(D) > 0) && | |||
800 | StartI->SharingMap[D].RefExpr.getPointer() && | |||
801 | CPred(StartI->SharingMap[D].Attributes) && | |||
802 | (!NotLastprivate || !StartI->SharingMap[D].RefExpr.getInt()); | |||
803 | } | |||
804 | ||||
805 | bool DSAStackTy::hasExplicitDirective( | |||
806 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, | |||
807 | unsigned Level) { | |||
808 | auto StartI = std::next(Stack.begin()); | |||
809 | auto EndI = Stack.end(); | |||
810 | if (std::distance(StartI, EndI) <= (int)Level) | |||
811 | return false; | |||
812 | std::advance(StartI, Level); | |||
813 | return DPred(StartI->Directive); | |||
814 | } | |||
815 | ||||
816 | bool DSAStackTy::hasDirective( | |||
817 | const llvm::function_ref<bool(OpenMPDirectiveKind, | |||
818 | const DeclarationNameInfo &, SourceLocation)> | |||
819 | &DPred, | |||
820 | bool FromParent) { | |||
821 | auto StartI = std::next(Stack.rbegin()); | |||
822 | auto EndI = std::prev(Stack.rend()); | |||
823 | if (FromParent && StartI != EndI) { | |||
824 | StartI = std::next(StartI); | |||
825 | } | |||
826 | for (auto I = StartI, EE = EndI; I != EE; ++I) { | |||
827 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) | |||
828 | return true; | |||
829 | } | |||
830 | return false; | |||
831 | } | |||
832 | ||||
833 | void Sema::InitDataSharingAttributesStack() { | |||
834 | VarDataSharingAttributesStack = new DSAStackTy(*this); | |||
835 | } | |||
836 | ||||
837 | #define DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ) static_cast<DSAStackTy *>(VarDataSharingAttributesStack) | |||
838 | ||||
839 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, unsigned Level) { | |||
840 | assert(LangOpts.OpenMP && "OpenMP is not allowed")((LangOpts.OpenMP && "OpenMP is not allowed") ? static_cast <void> (0) : __assert_fail ("LangOpts.OpenMP && \"OpenMP is not allowed\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 840, __PRETTY_FUNCTION__)); | |||
841 | ||||
842 | auto &Ctx = getASTContext(); | |||
843 | bool IsByRef = true; | |||
844 | ||||
845 | // Find the directive that is associated with the provided scope. | |||
846 | auto Ty = D->getType(); | |||
847 | ||||
848 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level)) { | |||
849 | // This table summarizes how a given variable should be passed to the device | |||
850 | // given its type and the clauses where it appears. This table is based on | |||
851 | // the description in OpenMP 4.5 [2.10.4, target Construct] and | |||
852 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. | |||
853 | // | |||
854 | // ========================================================================= | |||
855 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | | |||
856 | // | |(tofrom:scalar)| | pvt | | | | | |||
857 | // ========================================================================= | |||
858 | // | scl | | | | - | | bycopy| | |||
859 | // | scl | | - | x | - | - | bycopy| | |||
860 | // | scl | | x | - | - | - | null | | |||
861 | // | scl | x | | | - | | byref | | |||
862 | // | scl | x | - | x | - | - | bycopy| | |||
863 | // | scl | x | x | - | - | - | null | | |||
864 | // | scl | | - | - | - | x | byref | | |||
865 | // | scl | x | - | - | - | x | byref | | |||
866 | // | |||
867 | // | agg | n.a. | | | - | | byref | | |||
868 | // | agg | n.a. | - | x | - | - | byref | | |||
869 | // | agg | n.a. | x | - | - | - | null | | |||
870 | // | agg | n.a. | - | - | - | x | byref | | |||
871 | // | agg | n.a. | - | - | - | x[] | byref | | |||
872 | // | |||
873 | // | ptr | n.a. | | | - | | bycopy| | |||
874 | // | ptr | n.a. | - | x | - | - | bycopy| | |||
875 | // | ptr | n.a. | x | - | - | - | null | | |||
876 | // | ptr | n.a. | - | - | - | x | byref | | |||
877 | // | ptr | n.a. | - | - | - | x[] | bycopy| | |||
878 | // | ptr | n.a. | - | - | x | | bycopy| | |||
879 | // | ptr | n.a. | - | - | x | x | bycopy| | |||
880 | // | ptr | n.a. | - | - | x | x[] | bycopy| | |||
881 | // ========================================================================= | |||
882 | // Legend: | |||
883 | // scl - scalar | |||
884 | // ptr - pointer | |||
885 | // agg - aggregate | |||
886 | // x - applies | |||
887 | // - - invalid in this combination | |||
888 | // [] - mapped with an array section | |||
889 | // byref - should be mapped by reference | |||
890 | // byval - should be mapped by value | |||
891 | // null - initialize a local variable to null on the device | |||
892 | // | |||
893 | // Observations: | |||
894 | // - All scalar declarations that show up in a map clause have to be passed | |||
895 | // by reference, because they may have been mapped in the enclosing data | |||
896 | // environment. | |||
897 | // - If the scalar value does not fit the size of uintptr, it has to be | |||
898 | // passed by reference, regardless the result in the table above. | |||
899 | // - For pointers mapped by value that have either an implicit map or an | |||
900 | // array section, the runtime library may pass the NULL value to the | |||
901 | // device instead of the value passed to it by the compiler. | |||
902 | ||||
903 | ||||
904 | if (Ty->isReferenceType()) | |||
905 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); | |||
906 | ||||
907 | // Locate map clauses and see if the variable being captured is referred to | |||
908 | // in any of those clauses. Here we only care about variables, not fields, | |||
909 | // because fields are part of aggregates. | |||
910 | bool IsVariableUsedInMapClause = false; | |||
911 | bool IsVariableAssociatedWithSection = false; | |||
912 | ||||
913 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->checkMappableExprComponentListsForDecl( | |||
914 | D, /*CurrentRegionOnly=*/true, | |||
915 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef | |||
916 | MapExprComponents) { | |||
917 | ||||
918 | auto EI = MapExprComponents.rbegin(); | |||
919 | auto EE = MapExprComponents.rend(); | |||
920 | ||||
921 | assert(EI != EE && "Invalid map expression!")((EI != EE && "Invalid map expression!") ? static_cast <void> (0) : __assert_fail ("EI != EE && \"Invalid map expression!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 921, __PRETTY_FUNCTION__)); | |||
922 | ||||
923 | if (isa<DeclRefExpr>(EI->getAssociatedExpression())) | |||
924 | IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D; | |||
925 | ||||
926 | ++EI; | |||
927 | if (EI == EE) | |||
928 | return false; | |||
929 | ||||
930 | if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || | |||
931 | isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || | |||
932 | isa<MemberExpr>(EI->getAssociatedExpression())) { | |||
933 | IsVariableAssociatedWithSection = true; | |||
934 | // There is nothing more we need to know about this variable. | |||
935 | return true; | |||
936 | } | |||
937 | ||||
938 | // Keep looking for more map info. | |||
939 | return false; | |||
940 | }); | |||
941 | ||||
942 | if (IsVariableUsedInMapClause) { | |||
943 | // If variable is identified in a map clause it is always captured by | |||
944 | // reference except if it is a pointer that is dereferenced somehow. | |||
945 | IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection); | |||
946 | } else { | |||
947 | // By default, all the data that has a scalar type is mapped by copy. | |||
948 | IsByRef = !Ty->isScalarType(); | |||
949 | } | |||
950 | } | |||
951 | ||||
952 | if (IsByRef && Ty.getNonReferenceType()->isScalarType()) { | |||
953 | IsByRef = !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDSA( | |||
954 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; }, | |||
955 | Level, /*NotLastprivate=*/true); | |||
956 | } | |||
957 | ||||
958 | // When passing data by copy, we need to make sure it fits the uintptr size | |||
959 | // and alignment, because the runtime library only deals with uintptr types. | |||
960 | // If it does not fit the uintptr size, we need to pass the data by reference | |||
961 | // instead. | |||
962 | if (!IsByRef && | |||
963 | (Ctx.getTypeSizeInChars(Ty) > | |||
964 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || | |||
965 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) { | |||
966 | IsByRef = true; | |||
967 | } | |||
968 | ||||
969 | return IsByRef; | |||
970 | } | |||
971 | ||||
972 | unsigned Sema::getOpenMPNestingLevel() const { | |||
973 | assert(getLangOpts().OpenMP)((getLangOpts().OpenMP) ? static_cast<void> (0) : __assert_fail ("getLangOpts().OpenMP", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 973, __PRETTY_FUNCTION__)); | |||
974 | return DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getNestingLevel(); | |||
975 | } | |||
976 | ||||
977 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { | |||
978 | assert(LangOpts.OpenMP && "OpenMP is not allowed")((LangOpts.OpenMP && "OpenMP is not allowed") ? static_cast <void> (0) : __assert_fail ("LangOpts.OpenMP && \"OpenMP is not allowed\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 978, __PRETTY_FUNCTION__)); | |||
979 | D = getCanonicalDecl(D); | |||
980 | ||||
981 | // If we are attempting to capture a global variable in a directive with | |||
982 | // 'target' we return true so that this global is also mapped to the device. | |||
983 | // | |||
984 | // FIXME: If the declaration is enclosed in a 'declare target' directive, | |||
985 | // then it should not be captured. Therefore, an extra check has to be | |||
986 | // inserted here once support for 'declare target' is added. | |||
987 | // | |||
988 | auto *VD = dyn_cast<VarDecl>(D); | |||
989 | if (VD && !VD->hasLocalStorage()) { | |||
990 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective() == OMPD_target && | |||
991 | !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isClauseParsingMode()) | |||
992 | return VD; | |||
993 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurScope() && | |||
994 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasDirective( | |||
995 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &, | |||
996 | SourceLocation) -> bool { | |||
997 | return isOpenMPTargetExecutionDirective(K); | |||
998 | }, | |||
999 | false)) | |||
1000 | return VD; | |||
1001 | } | |||
1002 | ||||
1003 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective() != OMPD_unknown && | |||
1004 | (!DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isClauseParsingMode() || | |||
1005 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getParentDirective() != OMPD_unknown)) { | |||
1006 | auto &&Info = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isLoopControlVariable(D); | |||
1007 | if (Info.first || | |||
1008 | (VD && VD->hasLocalStorage() && | |||
1009 | isParallelOrTaskRegion(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) || | |||
1010 | (VD && DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isForceVarCapturing())) | |||
1011 | return VD ? VD : Info.second; | |||
1012 | auto DVarPrivate = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isClauseParsingMode()); | |||
1013 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) | |||
1014 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); | |||
| ||||
1015 | DVarPrivate = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasDSA( | |||
1016 | D, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, | |||
1017 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isClauseParsingMode()); | |||
1018 | if (DVarPrivate.CKind != OMPC_unknown) | |||
1019 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); | |||
1020 | } | |||
1021 | return nullptr; | |||
1022 | } | |||
1023 | ||||
1024 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { | |||
1025 | assert(LangOpts.OpenMP && "OpenMP is not allowed")((LangOpts.OpenMP && "OpenMP is not allowed") ? static_cast <void> (0) : __assert_fail ("LangOpts.OpenMP && \"OpenMP is not allowed\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 1025, __PRETTY_FUNCTION__)); | |||
1026 | return DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDSA( | |||
1027 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); | |||
1028 | } | |||
1029 | ||||
1030 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { | |||
1031 | assert(LangOpts.OpenMP && "OpenMP is not allowed")((LangOpts.OpenMP && "OpenMP is not allowed") ? static_cast <void> (0) : __assert_fail ("LangOpts.OpenMP && \"OpenMP is not allowed\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 1031, __PRETTY_FUNCTION__)); | |||
1032 | // Return true if the current level is no longer enclosed in a target region. | |||
1033 | ||||
1034 | auto *VD = dyn_cast<VarDecl>(D); | |||
1035 | return VD && !VD->hasLocalStorage() && | |||
1036 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDirective(isOpenMPTargetExecutionDirective, | |||
1037 | Level); | |||
1038 | } | |||
1039 | ||||
1040 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ); } | |||
1041 | ||||
1042 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, | |||
1043 | const DeclarationNameInfo &DirName, | |||
1044 | Scope *CurScope, SourceLocation Loc) { | |||
1045 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->push(DKind, DirName, CurScope, Loc); | |||
1046 | PushExpressionEvaluationContext(PotentiallyEvaluated); | |||
1047 | } | |||
1048 | ||||
1049 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { | |||
1050 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setClauseParsingMode(K); | |||
1051 | } | |||
1052 | ||||
1053 | void Sema::EndOpenMPClause() { | |||
1054 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setClauseParsingMode(/*K=*/OMPC_unknown); | |||
1055 | } | |||
1056 | ||||
1057 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { | |||
1058 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] | |||
1059 | // A variable of class type (or array thereof) that appears in a lastprivate | |||
1060 | // clause requires an accessible, unambiguous default constructor for the | |||
1061 | // class type, unless the list item is also specified in a firstprivate | |||
1062 | // clause. | |||
1063 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { | |||
1064 | for (auto *C : D->clauses()) { | |||
1065 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { | |||
1066 | SmallVector<Expr *, 8> PrivateCopies; | |||
1067 | for (auto *DE : Clause->varlists()) { | |||
1068 | if (DE->isValueDependent() || DE->isTypeDependent()) { | |||
1069 | PrivateCopies.push_back(nullptr); | |||
1070 | continue; | |||
1071 | } | |||
1072 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); | |||
1073 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); | |||
1074 | QualType Type = VD->getType().getNonReferenceType(); | |||
1075 | auto DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(VD, false); | |||
1076 | if (DVar.CKind == OMPC_lastprivate) { | |||
1077 | // Generate helper private variable and initialize it with the | |||
1078 | // default value. The address of the original variable is replaced | |||
1079 | // by the address of the new private variable in CodeGen. This new | |||
1080 | // variable is not added to IdResolver, so the code in the OpenMP | |||
1081 | // region uses original variable for proper diagnostics. | |||
1082 | auto *VDPrivate = buildVarDecl( | |||
1083 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), | |||
1084 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); | |||
1085 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); | |||
1086 | if (VDPrivate->isInvalidDecl()) | |||
1087 | continue; | |||
1088 | PrivateCopies.push_back(buildDeclRefExpr( | |||
1089 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); | |||
1090 | } else { | |||
1091 | // The variable is also a firstprivate, so initialization sequence | |||
1092 | // for private copy is generated already. | |||
1093 | PrivateCopies.push_back(nullptr); | |||
1094 | } | |||
1095 | } | |||
1096 | // Set initializers to private copies if no errors were found. | |||
1097 | if (PrivateCopies.size() == Clause->varlist_size()) | |||
1098 | Clause->setPrivateCopies(PrivateCopies); | |||
1099 | } | |||
1100 | } | |||
1101 | } | |||
1102 | ||||
1103 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->pop(); | |||
1104 | DiscardCleanupsInEvaluationContext(); | |||
1105 | PopExpressionEvaluationContext(); | |||
1106 | } | |||
1107 | ||||
1108 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, | |||
1109 | Expr *NumIterations, Sema &SemaRef, | |||
1110 | Scope *S, DSAStackTy *Stack); | |||
1111 | ||||
1112 | namespace { | |||
1113 | ||||
1114 | class VarDeclFilterCCC : public CorrectionCandidateCallback { | |||
1115 | private: | |||
1116 | Sema &SemaRef; | |||
1117 | ||||
1118 | public: | |||
1119 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} | |||
1120 | bool ValidateCandidate(const TypoCorrection &Candidate) override { | |||
1121 | NamedDecl *ND = Candidate.getCorrectionDecl(); | |||
1122 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { | |||
1123 | return VD->hasGlobalStorage() && | |||
1124 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), | |||
1125 | SemaRef.getCurScope()); | |||
1126 | } | |||
1127 | return false; | |||
1128 | } | |||
1129 | }; | |||
1130 | ||||
1131 | class VarOrFuncDeclFilterCCC : public CorrectionCandidateCallback { | |||
1132 | private: | |||
1133 | Sema &SemaRef; | |||
1134 | ||||
1135 | public: | |||
1136 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} | |||
1137 | bool ValidateCandidate(const TypoCorrection &Candidate) override { | |||
1138 | NamedDecl *ND = Candidate.getCorrectionDecl(); | |||
1139 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { | |||
1140 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), | |||
1141 | SemaRef.getCurScope()); | |||
1142 | } | |||
1143 | return false; | |||
1144 | } | |||
1145 | }; | |||
1146 | ||||
1147 | } // namespace | |||
1148 | ||||
1149 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, | |||
1150 | CXXScopeSpec &ScopeSpec, | |||
1151 | const DeclarationNameInfo &Id) { | |||
1152 | LookupResult Lookup(*this, Id, LookupOrdinaryName); | |||
1153 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); | |||
1154 | ||||
1155 | if (Lookup.isAmbiguous()) | |||
1156 | return ExprError(); | |||
1157 | ||||
1158 | VarDecl *VD; | |||
1159 | if (!Lookup.isSingleResult()) { | |||
1160 | if (TypoCorrection Corrected = CorrectTypo( | |||
1161 | Id, LookupOrdinaryName, CurScope, nullptr, | |||
1162 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { | |||
1163 | diagnoseTypo(Corrected, | |||
1164 | PDiag(Lookup.empty() | |||
1165 | ? diag::err_undeclared_var_use_suggest | |||
1166 | : diag::err_omp_expected_var_arg_suggest) | |||
1167 | << Id.getName()); | |||
1168 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); | |||
1169 | } else { | |||
1170 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use | |||
1171 | : diag::err_omp_expected_var_arg) | |||
1172 | << Id.getName(); | |||
1173 | return ExprError(); | |||
1174 | } | |||
1175 | } else { | |||
1176 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { | |||
1177 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); | |||
1178 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); | |||
1179 | return ExprError(); | |||
1180 | } | |||
1181 | } | |||
1182 | Lookup.suppressDiagnostics(); | |||
1183 | ||||
1184 | // OpenMP [2.9.2, Syntax, C/C++] | |||
1185 | // Variables must be file-scope, namespace-scope, or static block-scope. | |||
1186 | if (!VD->hasGlobalStorage()) { | |||
1187 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) | |||
1188 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); | |||
1189 | bool IsDecl = | |||
1190 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
1191 | Diag(VD->getLocation(), | |||
1192 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
1193 | << VD; | |||
1194 | return ExprError(); | |||
1195 | } | |||
1196 | ||||
1197 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); | |||
1198 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); | |||
1199 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] | |||
1200 | // A threadprivate directive for file-scope variables must appear outside | |||
1201 | // any definition or declaration. | |||
1202 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && | |||
1203 | !getCurLexicalContext()->isTranslationUnit()) { | |||
1204 | Diag(Id.getLoc(), diag::err_omp_var_scope) | |||
1205 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; | |||
1206 | bool IsDecl = | |||
1207 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
1208 | Diag(VD->getLocation(), | |||
1209 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
1210 | << VD; | |||
1211 | return ExprError(); | |||
1212 | } | |||
1213 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] | |||
1214 | // A threadprivate directive for static class member variables must appear | |||
1215 | // in the class definition, in the same scope in which the member | |||
1216 | // variables are declared. | |||
1217 | if (CanonicalVD->isStaticDataMember() && | |||
1218 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { | |||
1219 | Diag(Id.getLoc(), diag::err_omp_var_scope) | |||
1220 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; | |||
1221 | bool IsDecl = | |||
1222 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
1223 | Diag(VD->getLocation(), | |||
1224 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
1225 | << VD; | |||
1226 | return ExprError(); | |||
1227 | } | |||
1228 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] | |||
1229 | // A threadprivate directive for namespace-scope variables must appear | |||
1230 | // outside any definition or declaration other than the namespace | |||
1231 | // definition itself. | |||
1232 | if (CanonicalVD->getDeclContext()->isNamespace() && | |||
1233 | (!getCurLexicalContext()->isFileContext() || | |||
1234 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { | |||
1235 | Diag(Id.getLoc(), diag::err_omp_var_scope) | |||
1236 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; | |||
1237 | bool IsDecl = | |||
1238 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
1239 | Diag(VD->getLocation(), | |||
1240 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
1241 | << VD; | |||
1242 | return ExprError(); | |||
1243 | } | |||
1244 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] | |||
1245 | // A threadprivate directive for static block-scope variables must appear | |||
1246 | // in the scope of the variable and not in a nested scope. | |||
1247 | if (CanonicalVD->isStaticLocal() && CurScope && | |||
1248 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { | |||
1249 | Diag(Id.getLoc(), diag::err_omp_var_scope) | |||
1250 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; | |||
1251 | bool IsDecl = | |||
1252 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
1253 | Diag(VD->getLocation(), | |||
1254 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
1255 | << VD; | |||
1256 | return ExprError(); | |||
1257 | } | |||
1258 | ||||
1259 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] | |||
1260 | // A threadprivate directive must lexically precede all references to any | |||
1261 | // of the variables in its list. | |||
1262 | if (VD->isUsed() && !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isThreadPrivate(VD)) { | |||
1263 | Diag(Id.getLoc(), diag::err_omp_var_used) | |||
1264 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; | |||
1265 | return ExprError(); | |||
1266 | } | |||
1267 | ||||
1268 | QualType ExprType = VD->getType().getNonReferenceType(); | |||
1269 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), | |||
1270 | SourceLocation(), VD, | |||
1271 | /*RefersToEnclosingVariableOrCapture=*/false, | |||
1272 | Id.getLoc(), ExprType, VK_LValue); | |||
1273 | } | |||
1274 | ||||
1275 | Sema::DeclGroupPtrTy | |||
1276 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, | |||
1277 | ArrayRef<Expr *> VarList) { | |||
1278 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { | |||
1279 | CurContext->addDecl(D); | |||
1280 | return DeclGroupPtrTy::make(DeclGroupRef(D)); | |||
1281 | } | |||
1282 | return nullptr; | |||
1283 | } | |||
1284 | ||||
1285 | namespace { | |||
1286 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { | |||
1287 | Sema &SemaRef; | |||
1288 | ||||
1289 | public: | |||
1290 | bool VisitDeclRefExpr(const DeclRefExpr *E) { | |||
1291 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { | |||
1292 | if (VD->hasLocalStorage()) { | |||
1293 | SemaRef.Diag(E->getLocStart(), | |||
1294 | diag::err_omp_local_var_in_threadprivate_init) | |||
1295 | << E->getSourceRange(); | |||
1296 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) | |||
1297 | << VD << VD->getSourceRange(); | |||
1298 | return true; | |||
1299 | } | |||
1300 | } | |||
1301 | return false; | |||
1302 | } | |||
1303 | bool VisitStmt(const Stmt *S) { | |||
1304 | for (auto Child : S->children()) { | |||
1305 | if (Child && Visit(Child)) | |||
1306 | return true; | |||
1307 | } | |||
1308 | return false; | |||
1309 | } | |||
1310 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} | |||
1311 | }; | |||
1312 | } // namespace | |||
1313 | ||||
1314 | OMPThreadPrivateDecl * | |||
1315 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { | |||
1316 | SmallVector<Expr *, 8> Vars; | |||
1317 | for (auto &RefExpr : VarList) { | |||
1318 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); | |||
1319 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); | |||
1320 | SourceLocation ILoc = DE->getExprLoc(); | |||
1321 | ||||
1322 | // Mark variable as used. | |||
1323 | VD->setReferenced(); | |||
1324 | VD->markUsed(Context); | |||
1325 | ||||
1326 | QualType QType = VD->getType(); | |||
1327 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { | |||
1328 | // It will be analyzed later. | |||
1329 | Vars.push_back(DE); | |||
1330 | continue; | |||
1331 | } | |||
1332 | ||||
1333 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] | |||
1334 | // A threadprivate variable must not have an incomplete type. | |||
1335 | if (RequireCompleteType(ILoc, VD->getType(), | |||
1336 | diag::err_omp_threadprivate_incomplete_type)) { | |||
1337 | continue; | |||
1338 | } | |||
1339 | ||||
1340 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] | |||
1341 | // A threadprivate variable must not have a reference type. | |||
1342 | if (VD->getType()->isReferenceType()) { | |||
1343 | Diag(ILoc, diag::err_omp_ref_type_arg) | |||
1344 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); | |||
1345 | bool IsDecl = | |||
1346 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
1347 | Diag(VD->getLocation(), | |||
1348 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
1349 | << VD; | |||
1350 | continue; | |||
1351 | } | |||
1352 | ||||
1353 | // Check if this is a TLS variable. If TLS is not being supported, produce | |||
1354 | // the corresponding diagnostic. | |||
1355 | if ((VD->getTLSKind() != VarDecl::TLS_None && | |||
1356 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && | |||
1357 | getLangOpts().OpenMPUseTLS && | |||
1358 | getASTContext().getTargetInfo().isTLSSupported())) || | |||
1359 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && | |||
1360 | !VD->isLocalVarDecl())) { | |||
1361 | Diag(ILoc, diag::err_omp_var_thread_local) | |||
1362 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); | |||
1363 | bool IsDecl = | |||
1364 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
1365 | Diag(VD->getLocation(), | |||
1366 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
1367 | << VD; | |||
1368 | continue; | |||
1369 | } | |||
1370 | ||||
1371 | // Check if initial value of threadprivate variable reference variable with | |||
1372 | // local storage (it is not supported by runtime). | |||
1373 | if (auto Init = VD->getAnyInitializer()) { | |||
1374 | LocalVarRefChecker Checker(*this); | |||
1375 | if (Checker.Visit(Init)) | |||
1376 | continue; | |||
1377 | } | |||
1378 | ||||
1379 | Vars.push_back(RefExpr); | |||
1380 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addDSA(VD, DE, OMPC_threadprivate); | |||
1381 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( | |||
1382 | Context, SourceRange(Loc, Loc))); | |||
1383 | if (auto *ML = Context.getASTMutationListener()) | |||
1384 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); | |||
1385 | } | |||
1386 | OMPThreadPrivateDecl *D = nullptr; | |||
1387 | if (!Vars.empty()) { | |||
1388 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, | |||
1389 | Vars); | |||
1390 | D->setAccess(AS_public); | |||
1391 | } | |||
1392 | return D; | |||
1393 | } | |||
1394 | ||||
1395 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, | |||
1396 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, | |||
1397 | bool IsLoopIterVar = false) { | |||
1398 | if (DVar.RefExpr) { | |||
1399 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) | |||
1400 | << getOpenMPClauseName(DVar.CKind); | |||
1401 | return; | |||
1402 | } | |||
1403 | enum { | |||
1404 | PDSA_StaticMemberShared, | |||
1405 | PDSA_StaticLocalVarShared, | |||
1406 | PDSA_LoopIterVarPrivate, | |||
1407 | PDSA_LoopIterVarLinear, | |||
1408 | PDSA_LoopIterVarLastprivate, | |||
1409 | PDSA_ConstVarShared, | |||
1410 | PDSA_GlobalVarShared, | |||
1411 | PDSA_TaskVarFirstprivate, | |||
1412 | PDSA_LocalVarPrivate, | |||
1413 | PDSA_Implicit | |||
1414 | } Reason = PDSA_Implicit; | |||
1415 | bool ReportHint = false; | |||
1416 | auto ReportLoc = D->getLocation(); | |||
1417 | auto *VD = dyn_cast<VarDecl>(D); | |||
1418 | if (IsLoopIterVar) { | |||
1419 | if (DVar.CKind == OMPC_private) | |||
1420 | Reason = PDSA_LoopIterVarPrivate; | |||
1421 | else if (DVar.CKind == OMPC_lastprivate) | |||
1422 | Reason = PDSA_LoopIterVarLastprivate; | |||
1423 | else | |||
1424 | Reason = PDSA_LoopIterVarLinear; | |||
1425 | } else if (isOpenMPTaskingDirective(DVar.DKind) && | |||
1426 | DVar.CKind == OMPC_firstprivate) { | |||
1427 | Reason = PDSA_TaskVarFirstprivate; | |||
1428 | ReportLoc = DVar.ImplicitDSALoc; | |||
1429 | } else if (VD && VD->isStaticLocal()) | |||
1430 | Reason = PDSA_StaticLocalVarShared; | |||
1431 | else if (VD && VD->isStaticDataMember()) | |||
1432 | Reason = PDSA_StaticMemberShared; | |||
1433 | else if (VD && VD->isFileVarDecl()) | |||
1434 | Reason = PDSA_GlobalVarShared; | |||
1435 | else if (D->getType().isConstant(SemaRef.getASTContext())) | |||
1436 | Reason = PDSA_ConstVarShared; | |||
1437 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { | |||
1438 | ReportHint = true; | |||
1439 | Reason = PDSA_LocalVarPrivate; | |||
1440 | } | |||
1441 | if (Reason != PDSA_Implicit) { | |||
1442 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) | |||
1443 | << Reason << ReportHint | |||
1444 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); | |||
1445 | } else if (DVar.ImplicitDSALoc.isValid()) { | |||
1446 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) | |||
1447 | << getOpenMPClauseName(DVar.CKind); | |||
1448 | } | |||
1449 | } | |||
1450 | ||||
1451 | namespace { | |||
1452 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { | |||
1453 | DSAStackTy *Stack; | |||
1454 | Sema &SemaRef; | |||
1455 | bool ErrorFound; | |||
1456 | CapturedStmt *CS; | |||
1457 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; | |||
1458 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; | |||
1459 | ||||
1460 | public: | |||
1461 | void VisitDeclRefExpr(DeclRefExpr *E) { | |||
1462 | if (E->isTypeDependent() || E->isValueDependent() || | |||
1463 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) | |||
1464 | return; | |||
1465 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { | |||
1466 | // Skip internally declared variables. | |||
1467 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) | |||
1468 | return; | |||
1469 | ||||
1470 | auto DVar = Stack->getTopDSA(VD, false); | |||
1471 | // Check if the variable has explicit DSA set and stop analysis if it so. | |||
1472 | if (DVar.RefExpr) return; | |||
1473 | ||||
1474 | auto ELoc = E->getExprLoc(); | |||
1475 | auto DKind = Stack->getCurrentDirective(); | |||
1476 | // The default(none) clause requires that each variable that is referenced | |||
1477 | // in the construct, and does not have a predetermined data-sharing | |||
1478 | // attribute, must have its data-sharing attribute explicitly determined | |||
1479 | // by being listed in a data-sharing attribute clause. | |||
1480 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && | |||
1481 | isParallelOrTaskRegion(DKind) && | |||
1482 | VarsWithInheritedDSA.count(VD) == 0) { | |||
1483 | VarsWithInheritedDSA[VD] = E; | |||
1484 | return; | |||
1485 | } | |||
1486 | ||||
1487 | // OpenMP [2.9.3.6, Restrictions, p.2] | |||
1488 | // A list item that appears in a reduction clause of the innermost | |||
1489 | // enclosing worksharing or parallel construct may not be accessed in an | |||
1490 | // explicit task. | |||
1491 | DVar = Stack->hasInnermostDSA( | |||
1492 | VD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, | |||
1493 | [](OpenMPDirectiveKind K) -> bool { | |||
1494 | return isOpenMPParallelDirective(K) || | |||
1495 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); | |||
1496 | }, | |||
1497 | false); | |||
1498 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { | |||
1499 | ErrorFound = true; | |||
1500 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); | |||
1501 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); | |||
1502 | return; | |||
1503 | } | |||
1504 | ||||
1505 | // Define implicit data-sharing attributes for task. | |||
1506 | DVar = Stack->getImplicitDSA(VD, false); | |||
1507 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && | |||
1508 | !Stack->isLoopControlVariable(VD).first) | |||
1509 | ImplicitFirstprivate.push_back(E); | |||
1510 | } | |||
1511 | } | |||
1512 | void VisitMemberExpr(MemberExpr *E) { | |||
1513 | if (E->isTypeDependent() || E->isValueDependent() || | |||
1514 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) | |||
1515 | return; | |||
1516 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { | |||
1517 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { | |||
1518 | auto DVar = Stack->getTopDSA(FD, false); | |||
1519 | // Check if the variable has explicit DSA set and stop analysis if it | |||
1520 | // so. | |||
1521 | if (DVar.RefExpr) | |||
1522 | return; | |||
1523 | ||||
1524 | auto ELoc = E->getExprLoc(); | |||
1525 | auto DKind = Stack->getCurrentDirective(); | |||
1526 | // OpenMP [2.9.3.6, Restrictions, p.2] | |||
1527 | // A list item that appears in a reduction clause of the innermost | |||
1528 | // enclosing worksharing or parallel construct may not be accessed in | |||
1529 | // an explicit task. | |||
1530 | DVar = Stack->hasInnermostDSA( | |||
1531 | FD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, | |||
1532 | [](OpenMPDirectiveKind K) -> bool { | |||
1533 | return isOpenMPParallelDirective(K) || | |||
1534 | isOpenMPWorksharingDirective(K) || | |||
1535 | isOpenMPTeamsDirective(K); | |||
1536 | }, | |||
1537 | false); | |||
1538 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { | |||
1539 | ErrorFound = true; | |||
1540 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); | |||
1541 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); | |||
1542 | return; | |||
1543 | } | |||
1544 | ||||
1545 | // Define implicit data-sharing attributes for task. | |||
1546 | DVar = Stack->getImplicitDSA(FD, false); | |||
1547 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && | |||
1548 | !Stack->isLoopControlVariable(FD).first) | |||
1549 | ImplicitFirstprivate.push_back(E); | |||
1550 | } | |||
1551 | } | |||
1552 | } | |||
1553 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { | |||
1554 | for (auto *C : S->clauses()) { | |||
1555 | // Skip analysis of arguments of implicitly defined firstprivate clause | |||
1556 | // for task directives. | |||
1557 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) | |||
1558 | for (auto *CC : C->children()) { | |||
1559 | if (CC) | |||
1560 | Visit(CC); | |||
1561 | } | |||
1562 | } | |||
1563 | } | |||
1564 | void VisitStmt(Stmt *S) { | |||
1565 | for (auto *C : S->children()) { | |||
1566 | if (C && !isa<OMPExecutableDirective>(C)) | |||
1567 | Visit(C); | |||
1568 | } | |||
1569 | } | |||
1570 | ||||
1571 | bool isErrorFound() { return ErrorFound; } | |||
1572 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } | |||
1573 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { | |||
1574 | return VarsWithInheritedDSA; | |||
1575 | } | |||
1576 | ||||
1577 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) | |||
1578 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} | |||
1579 | }; | |||
1580 | } // namespace | |||
1581 | ||||
1582 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { | |||
1583 | switch (DKind) { | |||
1584 | case OMPD_parallel: { | |||
1585 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); | |||
1586 | QualType KmpInt32PtrTy = | |||
1587 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); | |||
1588 | Sema::CapturedParamNameType Params[] = { | |||
1589 | std::make_pair(".global_tid.", KmpInt32PtrTy), | |||
1590 | std::make_pair(".bound_tid.", KmpInt32PtrTy), | |||
1591 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1592 | }; | |||
1593 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1594 | Params); | |||
1595 | break; | |||
1596 | } | |||
1597 | case OMPD_simd: { | |||
1598 | Sema::CapturedParamNameType Params[] = { | |||
1599 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1600 | }; | |||
1601 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1602 | Params); | |||
1603 | break; | |||
1604 | } | |||
1605 | case OMPD_for: { | |||
1606 | Sema::CapturedParamNameType Params[] = { | |||
1607 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1608 | }; | |||
1609 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1610 | Params); | |||
1611 | break; | |||
1612 | } | |||
1613 | case OMPD_for_simd: { | |||
1614 | Sema::CapturedParamNameType Params[] = { | |||
1615 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1616 | }; | |||
1617 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1618 | Params); | |||
1619 | break; | |||
1620 | } | |||
1621 | case OMPD_sections: { | |||
1622 | Sema::CapturedParamNameType Params[] = { | |||
1623 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1624 | }; | |||
1625 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1626 | Params); | |||
1627 | break; | |||
1628 | } | |||
1629 | case OMPD_section: { | |||
1630 | Sema::CapturedParamNameType Params[] = { | |||
1631 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1632 | }; | |||
1633 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1634 | Params); | |||
1635 | break; | |||
1636 | } | |||
1637 | case OMPD_single: { | |||
1638 | Sema::CapturedParamNameType Params[] = { | |||
1639 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1640 | }; | |||
1641 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1642 | Params); | |||
1643 | break; | |||
1644 | } | |||
1645 | case OMPD_master: { | |||
1646 | Sema::CapturedParamNameType Params[] = { | |||
1647 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1648 | }; | |||
1649 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1650 | Params); | |||
1651 | break; | |||
1652 | } | |||
1653 | case OMPD_critical: { | |||
1654 | Sema::CapturedParamNameType Params[] = { | |||
1655 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1656 | }; | |||
1657 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1658 | Params); | |||
1659 | break; | |||
1660 | } | |||
1661 | case OMPD_parallel_for: { | |||
1662 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); | |||
1663 | QualType KmpInt32PtrTy = | |||
1664 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); | |||
1665 | Sema::CapturedParamNameType Params[] = { | |||
1666 | std::make_pair(".global_tid.", KmpInt32PtrTy), | |||
1667 | std::make_pair(".bound_tid.", KmpInt32PtrTy), | |||
1668 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1669 | }; | |||
1670 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1671 | Params); | |||
1672 | break; | |||
1673 | } | |||
1674 | case OMPD_parallel_for_simd: { | |||
1675 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); | |||
1676 | QualType KmpInt32PtrTy = | |||
1677 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); | |||
1678 | Sema::CapturedParamNameType Params[] = { | |||
1679 | std::make_pair(".global_tid.", KmpInt32PtrTy), | |||
1680 | std::make_pair(".bound_tid.", KmpInt32PtrTy), | |||
1681 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1682 | }; | |||
1683 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1684 | Params); | |||
1685 | break; | |||
1686 | } | |||
1687 | case OMPD_parallel_sections: { | |||
1688 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); | |||
1689 | QualType KmpInt32PtrTy = | |||
1690 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); | |||
1691 | Sema::CapturedParamNameType Params[] = { | |||
1692 | std::make_pair(".global_tid.", KmpInt32PtrTy), | |||
1693 | std::make_pair(".bound_tid.", KmpInt32PtrTy), | |||
1694 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1695 | }; | |||
1696 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1697 | Params); | |||
1698 | break; | |||
1699 | } | |||
1700 | case OMPD_task: { | |||
1701 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); | |||
1702 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; | |||
1703 | FunctionProtoType::ExtProtoInfo EPI; | |||
1704 | EPI.Variadic = true; | |||
1705 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); | |||
1706 | Sema::CapturedParamNameType Params[] = { | |||
1707 | std::make_pair(".global_tid.", KmpInt32Ty), | |||
1708 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), | |||
1709 | std::make_pair(".privates.", Context.VoidPtrTy.withConst()), | |||
1710 | std::make_pair(".copy_fn.", | |||
1711 | Context.getPointerType(CopyFnType).withConst()), | |||
1712 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), | |||
1713 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1714 | }; | |||
1715 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1716 | Params); | |||
1717 | // Mark this captured region as inlined, because we don't use outlined | |||
1718 | // function directly. | |||
1719 | getCurCapturedRegion()->TheCapturedDecl->addAttr( | |||
1720 | AlwaysInlineAttr::CreateImplicit( | |||
1721 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); | |||
1722 | break; | |||
1723 | } | |||
1724 | case OMPD_ordered: { | |||
1725 | Sema::CapturedParamNameType Params[] = { | |||
1726 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1727 | }; | |||
1728 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1729 | Params); | |||
1730 | break; | |||
1731 | } | |||
1732 | case OMPD_atomic: { | |||
1733 | Sema::CapturedParamNameType Params[] = { | |||
1734 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1735 | }; | |||
1736 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1737 | Params); | |||
1738 | break; | |||
1739 | } | |||
1740 | case OMPD_target_data: | |||
1741 | case OMPD_target: | |||
1742 | case OMPD_target_parallel: | |||
1743 | case OMPD_target_parallel_for: { | |||
1744 | Sema::CapturedParamNameType Params[] = { | |||
1745 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1746 | }; | |||
1747 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1748 | Params); | |||
1749 | break; | |||
1750 | } | |||
1751 | case OMPD_teams: { | |||
1752 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); | |||
1753 | QualType KmpInt32PtrTy = | |||
1754 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); | |||
1755 | Sema::CapturedParamNameType Params[] = { | |||
1756 | std::make_pair(".global_tid.", KmpInt32PtrTy), | |||
1757 | std::make_pair(".bound_tid.", KmpInt32PtrTy), | |||
1758 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1759 | }; | |||
1760 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1761 | Params); | |||
1762 | break; | |||
1763 | } | |||
1764 | case OMPD_taskgroup: { | |||
1765 | Sema::CapturedParamNameType Params[] = { | |||
1766 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1767 | }; | |||
1768 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1769 | Params); | |||
1770 | break; | |||
1771 | } | |||
1772 | case OMPD_taskloop: | |||
1773 | case OMPD_taskloop_simd: { | |||
1774 | QualType KmpInt32Ty = | |||
1775 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1); | |||
1776 | QualType KmpUInt64Ty = | |||
1777 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); | |||
1778 | QualType KmpInt64Ty = | |||
1779 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); | |||
1780 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; | |||
1781 | FunctionProtoType::ExtProtoInfo EPI; | |||
1782 | EPI.Variadic = true; | |||
1783 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); | |||
1784 | Sema::CapturedParamNameType Params[] = { | |||
1785 | std::make_pair(".global_tid.", KmpInt32Ty), | |||
1786 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), | |||
1787 | std::make_pair(".privates.", | |||
1788 | Context.VoidPtrTy.withConst().withRestrict()), | |||
1789 | std::make_pair( | |||
1790 | ".copy_fn.", | |||
1791 | Context.getPointerType(CopyFnType).withConst().withRestrict()), | |||
1792 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), | |||
1793 | std::make_pair(".lb.", KmpUInt64Ty), | |||
1794 | std::make_pair(".ub.", KmpUInt64Ty), std::make_pair(".st.", KmpInt64Ty), | |||
1795 | std::make_pair(".liter.", KmpInt32Ty), | |||
1796 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1797 | }; | |||
1798 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1799 | Params); | |||
1800 | // Mark this captured region as inlined, because we don't use outlined | |||
1801 | // function directly. | |||
1802 | getCurCapturedRegion()->TheCapturedDecl->addAttr( | |||
1803 | AlwaysInlineAttr::CreateImplicit( | |||
1804 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); | |||
1805 | break; | |||
1806 | } | |||
1807 | case OMPD_distribute: { | |||
1808 | Sema::CapturedParamNameType Params[] = { | |||
1809 | std::make_pair(StringRef(), QualType()) // __context with shared vars | |||
1810 | }; | |||
1811 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, | |||
1812 | Params); | |||
1813 | break; | |||
1814 | } | |||
1815 | case OMPD_threadprivate: | |||
1816 | case OMPD_taskyield: | |||
1817 | case OMPD_barrier: | |||
1818 | case OMPD_taskwait: | |||
1819 | case OMPD_cancellation_point: | |||
1820 | case OMPD_cancel: | |||
1821 | case OMPD_flush: | |||
1822 | case OMPD_target_enter_data: | |||
1823 | case OMPD_target_exit_data: | |||
1824 | case OMPD_declare_reduction: | |||
1825 | case OMPD_declare_simd: | |||
1826 | case OMPD_declare_target: | |||
1827 | case OMPD_end_declare_target: | |||
1828 | case OMPD_target_update: | |||
1829 | llvm_unreachable("OpenMP Directive is not allowed")::llvm::llvm_unreachable_internal("OpenMP Directive is not allowed" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 1829); | |||
1830 | case OMPD_unknown: | |||
1831 | llvm_unreachable("Unknown OpenMP directive")::llvm::llvm_unreachable_internal("Unknown OpenMP directive", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 1831); | |||
1832 | } | |||
1833 | } | |||
1834 | ||||
1835 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, | |||
1836 | Expr *CaptureExpr, bool WithInit, | |||
1837 | bool AsExpression) { | |||
1838 | assert(CaptureExpr)((CaptureExpr) ? static_cast<void> (0) : __assert_fail ( "CaptureExpr", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 1838, __PRETTY_FUNCTION__)); | |||
1839 | ASTContext &C = S.getASTContext(); | |||
1840 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); | |||
1841 | QualType Ty = Init->getType(); | |||
1842 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { | |||
1843 | if (S.getLangOpts().CPlusPlus) | |||
1844 | Ty = C.getLValueReferenceType(Ty); | |||
1845 | else { | |||
1846 | Ty = C.getPointerType(Ty); | |||
1847 | ExprResult Res = | |||
1848 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); | |||
1849 | if (!Res.isUsable()) | |||
1850 | return nullptr; | |||
1851 | Init = Res.get(); | |||
1852 | } | |||
1853 | WithInit = true; | |||
1854 | } | |||
1855 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty); | |||
1856 | if (!WithInit) | |||
1857 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); | |||
1858 | S.CurContext->addHiddenDecl(CED); | |||
1859 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false, | |||
1860 | /*TypeMayContainAuto=*/true); | |||
1861 | return CED; | |||
1862 | } | |||
1863 | ||||
1864 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, | |||
1865 | bool WithInit) { | |||
1866 | OMPCapturedExprDecl *CD; | |||
1867 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) | |||
1868 | CD = cast<OMPCapturedExprDecl>(VD); | |||
1869 | else | |||
1870 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, | |||
1871 | /*AsExpression=*/false); | |||
1872 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), | |||
1873 | CaptureExpr->getExprLoc()); | |||
1874 | } | |||
1875 | ||||
1876 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { | |||
1877 | if (!Ref) { | |||
1878 | auto *CD = | |||
1879 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), | |||
1880 | CaptureExpr, /*WithInit=*/true, /*AsExpression=*/true); | |||
1881 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), | |||
1882 | CaptureExpr->getExprLoc()); | |||
1883 | } | |||
1884 | ExprResult Res = Ref; | |||
1885 | if (!S.getLangOpts().CPlusPlus && | |||
1886 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && | |||
1887 | Ref->getType()->isPointerType()) | |||
1888 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); | |||
1889 | if (!Res.isUsable()) | |||
1890 | return ExprError(); | |||
1891 | return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get()); | |||
1892 | } | |||
1893 | ||||
1894 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, | |||
1895 | ArrayRef<OMPClause *> Clauses) { | |||
1896 | if (!S.isUsable()) { | |||
1897 | ActOnCapturedRegionError(); | |||
1898 | return StmtError(); | |||
1899 | } | |||
1900 | ||||
1901 | OMPOrderedClause *OC = nullptr; | |||
1902 | OMPScheduleClause *SC = nullptr; | |||
1903 | SmallVector<OMPLinearClause *, 4> LCs; | |||
1904 | // This is required for proper codegen. | |||
1905 | for (auto *Clause : Clauses) { | |||
1906 | if (isOpenMPPrivate(Clause->getClauseKind()) || | |||
1907 | Clause->getClauseKind() == OMPC_copyprivate || | |||
1908 | (getLangOpts().OpenMPUseTLS && | |||
1909 | getASTContext().getTargetInfo().isTLSSupported() && | |||
1910 | Clause->getClauseKind() == OMPC_copyin)) { | |||
1911 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); | |||
1912 | // Mark all variables in private list clauses as used in inner region. | |||
1913 | for (auto *VarRef : Clause->children()) { | |||
1914 | if (auto *E = cast_or_null<Expr>(VarRef)) { | |||
1915 | MarkDeclarationsReferencedInExpr(E); | |||
1916 | } | |||
1917 | } | |||
1918 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setForceVarCapturing(/*V=*/false); | |||
1919 | } else if (isParallelOrTaskRegion(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) { | |||
1920 | // Mark all variables in private list clauses as used in inner region. | |||
1921 | // Required for proper codegen of combined directives. | |||
1922 | // TODO: add processing for other clauses. | |||
1923 | if (auto *C = OMPClauseWithPreInit::get(Clause)) { | |||
1924 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { | |||
1925 | for (auto *D : DS->decls()) | |||
1926 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); | |||
1927 | } | |||
1928 | } | |||
1929 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { | |||
1930 | if (auto *E = C->getPostUpdateExpr()) | |||
1931 | MarkDeclarationsReferencedInExpr(E); | |||
1932 | } | |||
1933 | } | |||
1934 | if (Clause->getClauseKind() == OMPC_schedule) | |||
1935 | SC = cast<OMPScheduleClause>(Clause); | |||
1936 | else if (Clause->getClauseKind() == OMPC_ordered) | |||
1937 | OC = cast<OMPOrderedClause>(Clause); | |||
1938 | else if (Clause->getClauseKind() == OMPC_linear) | |||
1939 | LCs.push_back(cast<OMPLinearClause>(Clause)); | |||
1940 | } | |||
1941 | bool ErrorFound = false; | |||
1942 | // OpenMP, 2.7.1 Loop Construct, Restrictions | |||
1943 | // The nonmonotonic modifier cannot be specified if an ordered clause is | |||
1944 | // specified. | |||
1945 | if (SC && | |||
1946 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || | |||
1947 | SC->getSecondScheduleModifier() == | |||
1948 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && | |||
1949 | OC) { | |||
1950 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic | |||
1951 | ? SC->getFirstScheduleModifierLoc() | |||
1952 | : SC->getSecondScheduleModifierLoc(), | |||
1953 | diag::err_omp_schedule_nonmonotonic_ordered) | |||
1954 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); | |||
1955 | ErrorFound = true; | |||
1956 | } | |||
1957 | if (!LCs.empty() && OC && OC->getNumForLoops()) { | |||
1958 | for (auto *C : LCs) { | |||
1959 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) | |||
1960 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); | |||
1961 | } | |||
1962 | ErrorFound = true; | |||
1963 | } | |||
1964 | if (isOpenMPWorksharingDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()) && | |||
1965 | isOpenMPSimdDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()) && OC && | |||
1966 | OC->getNumForLoops()) { | |||
1967 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) | |||
1968 | << getOpenMPDirectiveName(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()); | |||
1969 | ErrorFound = true; | |||
1970 | } | |||
1971 | if (ErrorFound) { | |||
1972 | ActOnCapturedRegionError(); | |||
1973 | return StmtError(); | |||
1974 | } | |||
1975 | return ActOnCapturedRegionEnd(S.get()); | |||
1976 | } | |||
1977 | ||||
1978 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, | |||
1979 | OpenMPDirectiveKind CurrentRegion, | |||
1980 | const DeclarationNameInfo &CurrentName, | |||
1981 | OpenMPDirectiveKind CancelRegion, | |||
1982 | SourceLocation StartLoc) { | |||
1983 | // Allowed nesting of constructs | |||
1984 | // +------------------+-----------------+------------------------------------+ | |||
1985 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| | |||
1986 | // +------------------+-----------------+------------------------------------+ | |||
1987 | // | parallel | parallel | * | | |||
1988 | // | parallel | for | * | | |||
1989 | // | parallel | for simd | * | | |||
1990 | // | parallel | master | * | | |||
1991 | // | parallel | critical | * | | |||
1992 | // | parallel | simd | * | | |||
1993 | // | parallel | sections | * | | |||
1994 | // | parallel | section | + | | |||
1995 | // | parallel | single | * | | |||
1996 | // | parallel | parallel for | * | | |||
1997 | // | parallel |parallel for simd| * | | |||
1998 | // | parallel |parallel sections| * | | |||
1999 | // | parallel | task | * | | |||
2000 | // | parallel | taskyield | * | | |||
2001 | // | parallel | barrier | * | | |||
2002 | // | parallel | taskwait | * | | |||
2003 | // | parallel | taskgroup | * | | |||
2004 | // | parallel | flush | * | | |||
2005 | // | parallel | ordered | + | | |||
2006 | // | parallel | atomic | * | | |||
2007 | // | parallel | target | * | | |||
2008 | // | parallel | target parallel | * | | |||
2009 | // | parallel | target parallel | * | | |||
2010 | // | | for | | | |||
2011 | // | parallel | target enter | * | | |||
2012 | // | | data | | | |||
2013 | // | parallel | target exit | * | | |||
2014 | // | | data | | | |||
2015 | // | parallel | teams | + | | |||
2016 | // | parallel | cancellation | | | |||
2017 | // | | point | ! | | |||
2018 | // | parallel | cancel | ! | | |||
2019 | // | parallel | taskloop | * | | |||
2020 | // | parallel | taskloop simd | * | | |||
2021 | // | parallel | distribute | | | |||
2022 | // +------------------+-----------------+------------------------------------+ | |||
2023 | // | for | parallel | * | | |||
2024 | // | for | for | + | | |||
2025 | // | for | for simd | + | | |||
2026 | // | for | master | + | | |||
2027 | // | for | critical | * | | |||
2028 | // | for | simd | * | | |||
2029 | // | for | sections | + | | |||
2030 | // | for | section | + | | |||
2031 | // | for | single | + | | |||
2032 | // | for | parallel for | * | | |||
2033 | // | for |parallel for simd| * | | |||
2034 | // | for |parallel sections| * | | |||
2035 | // | for | task | * | | |||
2036 | // | for | taskyield | * | | |||
2037 | // | for | barrier | + | | |||
2038 | // | for | taskwait | * | | |||
2039 | // | for | taskgroup | * | | |||
2040 | // | for | flush | * | | |||
2041 | // | for | ordered | * (if construct is ordered) | | |||
2042 | // | for | atomic | * | | |||
2043 | // | for | target | * | | |||
2044 | // | for | target parallel | * | | |||
2045 | // | for | target parallel | * | | |||
2046 | // | | for | | | |||
2047 | // | for | target enter | * | | |||
2048 | // | | data | | | |||
2049 | // | for | target exit | * | | |||
2050 | // | | data | | | |||
2051 | // | for | teams | + | | |||
2052 | // | for | cancellation | | | |||
2053 | // | | point | ! | | |||
2054 | // | for | cancel | ! | | |||
2055 | // | for | taskloop | * | | |||
2056 | // | for | taskloop simd | * | | |||
2057 | // | for | distribute | | | |||
2058 | // +------------------+-----------------+------------------------------------+ | |||
2059 | // | master | parallel | * | | |||
2060 | // | master | for | + | | |||
2061 | // | master | for simd | + | | |||
2062 | // | master | master | * | | |||
2063 | // | master | critical | * | | |||
2064 | // | master | simd | * | | |||
2065 | // | master | sections | + | | |||
2066 | // | master | section | + | | |||
2067 | // | master | single | + | | |||
2068 | // | master | parallel for | * | | |||
2069 | // | master |parallel for simd| * | | |||
2070 | // | master |parallel sections| * | | |||
2071 | // | master | task | * | | |||
2072 | // | master | taskyield | * | | |||
2073 | // | master | barrier | + | | |||
2074 | // | master | taskwait | * | | |||
2075 | // | master | taskgroup | * | | |||
2076 | // | master | flush | * | | |||
2077 | // | master | ordered | + | | |||
2078 | // | master | atomic | * | | |||
2079 | // | master | target | * | | |||
2080 | // | master | target parallel | * | | |||
2081 | // | master | target parallel | * | | |||
2082 | // | | for | | | |||
2083 | // | master | target enter | * | | |||
2084 | // | | data | | | |||
2085 | // | master | target exit | * | | |||
2086 | // | | data | | | |||
2087 | // | master | teams | + | | |||
2088 | // | master | cancellation | | | |||
2089 | // | | point | | | |||
2090 | // | master | cancel | | | |||
2091 | // | master | taskloop | * | | |||
2092 | // | master | taskloop simd | * | | |||
2093 | // | master | distribute | | | |||
2094 | // +------------------+-----------------+------------------------------------+ | |||
2095 | // | critical | parallel | * | | |||
2096 | // | critical | for | + | | |||
2097 | // | critical | for simd | + | | |||
2098 | // | critical | master | * | | |||
2099 | // | critical | critical | * (should have different names) | | |||
2100 | // | critical | simd | * | | |||
2101 | // | critical | sections | + | | |||
2102 | // | critical | section | + | | |||
2103 | // | critical | single | + | | |||
2104 | // | critical | parallel for | * | | |||
2105 | // | critical |parallel for simd| * | | |||
2106 | // | critical |parallel sections| * | | |||
2107 | // | critical | task | * | | |||
2108 | // | critical | taskyield | * | | |||
2109 | // | critical | barrier | + | | |||
2110 | // | critical | taskwait | * | | |||
2111 | // | critical | taskgroup | * | | |||
2112 | // | critical | ordered | + | | |||
2113 | // | critical | atomic | * | | |||
2114 | // | critical | target | * | | |||
2115 | // | critical | target parallel | * | | |||
2116 | // | critical | target parallel | * | | |||
2117 | // | | for | | | |||
2118 | // | critical | target enter | * | | |||
2119 | // | | data | | | |||
2120 | // | critical | target exit | * | | |||
2121 | // | | data | | | |||
2122 | // | critical | teams | + | | |||
2123 | // | critical | cancellation | | | |||
2124 | // | | point | | | |||
2125 | // | critical | cancel | | | |||
2126 | // | critical | taskloop | * | | |||
2127 | // | critical | taskloop simd | * | | |||
2128 | // | critical | distribute | | | |||
2129 | // +------------------+-----------------+------------------------------------+ | |||
2130 | // | simd | parallel | | | |||
2131 | // | simd | for | | | |||
2132 | // | simd | for simd | | | |||
2133 | // | simd | master | | | |||
2134 | // | simd | critical | | | |||
2135 | // | simd | simd | * | | |||
2136 | // | simd | sections | | | |||
2137 | // | simd | section | | | |||
2138 | // | simd | single | | | |||
2139 | // | simd | parallel for | | | |||
2140 | // | simd |parallel for simd| | | |||
2141 | // | simd |parallel sections| | | |||
2142 | // | simd | task | | | |||
2143 | // | simd | taskyield | | | |||
2144 | // | simd | barrier | | | |||
2145 | // | simd | taskwait | | | |||
2146 | // | simd | taskgroup | | | |||
2147 | // | simd | flush | | | |||
2148 | // | simd | ordered | + (with simd clause) | | |||
2149 | // | simd | atomic | | | |||
2150 | // | simd | target | | | |||
2151 | // | simd | target parallel | | | |||
2152 | // | simd | target parallel | | | |||
2153 | // | | for | | | |||
2154 | // | simd | target enter | | | |||
2155 | // | | data | | | |||
2156 | // | simd | target exit | | | |||
2157 | // | | data | | | |||
2158 | // | simd | teams | | | |||
2159 | // | simd | cancellation | | | |||
2160 | // | | point | | | |||
2161 | // | simd | cancel | | | |||
2162 | // | simd | taskloop | | | |||
2163 | // | simd | taskloop simd | | | |||
2164 | // | simd | distribute | | | |||
2165 | // +------------------+-----------------+------------------------------------+ | |||
2166 | // | for simd | parallel | | | |||
2167 | // | for simd | for | | | |||
2168 | // | for simd | for simd | | | |||
2169 | // | for simd | master | | | |||
2170 | // | for simd | critical | | | |||
2171 | // | for simd | simd | * | | |||
2172 | // | for simd | sections | | | |||
2173 | // | for simd | section | | | |||
2174 | // | for simd | single | | | |||
2175 | // | for simd | parallel for | | | |||
2176 | // | for simd |parallel for simd| | | |||
2177 | // | for simd |parallel sections| | | |||
2178 | // | for simd | task | | | |||
2179 | // | for simd | taskyield | | | |||
2180 | // | for simd | barrier | | | |||
2181 | // | for simd | taskwait | | | |||
2182 | // | for simd | taskgroup | | | |||
2183 | // | for simd | flush | | | |||
2184 | // | for simd | ordered | + (with simd clause) | | |||
2185 | // | for simd | atomic | | | |||
2186 | // | for simd | target | | | |||
2187 | // | for simd | target parallel | | | |||
2188 | // | for simd | target parallel | | | |||
2189 | // | | for | | | |||
2190 | // | for simd | target enter | | | |||
2191 | // | | data | | | |||
2192 | // | for simd | target exit | | | |||
2193 | // | | data | | | |||
2194 | // | for simd | teams | | | |||
2195 | // | for simd | cancellation | | | |||
2196 | // | | point | | | |||
2197 | // | for simd | cancel | | | |||
2198 | // | for simd | taskloop | | | |||
2199 | // | for simd | taskloop simd | | | |||
2200 | // | for simd | distribute | | | |||
2201 | // +------------------+-----------------+------------------------------------+ | |||
2202 | // | parallel for simd| parallel | | | |||
2203 | // | parallel for simd| for | | | |||
2204 | // | parallel for simd| for simd | | | |||
2205 | // | parallel for simd| master | | | |||
2206 | // | parallel for simd| critical | | | |||
2207 | // | parallel for simd| simd | * | | |||
2208 | // | parallel for simd| sections | | | |||
2209 | // | parallel for simd| section | | | |||
2210 | // | parallel for simd| single | | | |||
2211 | // | parallel for simd| parallel for | | | |||
2212 | // | parallel for simd|parallel for simd| | | |||
2213 | // | parallel for simd|parallel sections| | | |||
2214 | // | parallel for simd| task | | | |||
2215 | // | parallel for simd| taskyield | | | |||
2216 | // | parallel for simd| barrier | | | |||
2217 | // | parallel for simd| taskwait | | | |||
2218 | // | parallel for simd| taskgroup | | | |||
2219 | // | parallel for simd| flush | | | |||
2220 | // | parallel for simd| ordered | + (with simd clause) | | |||
2221 | // | parallel for simd| atomic | | | |||
2222 | // | parallel for simd| target | | | |||
2223 | // | parallel for simd| target parallel | | | |||
2224 | // | parallel for simd| target parallel | | | |||
2225 | // | | for | | | |||
2226 | // | parallel for simd| target enter | | | |||
2227 | // | | data | | | |||
2228 | // | parallel for simd| target exit | | | |||
2229 | // | | data | | | |||
2230 | // | parallel for simd| teams | | | |||
2231 | // | parallel for simd| cancellation | | | |||
2232 | // | | point | | | |||
2233 | // | parallel for simd| cancel | | | |||
2234 | // | parallel for simd| taskloop | | | |||
2235 | // | parallel for simd| taskloop simd | | | |||
2236 | // | parallel for simd| distribute | | | |||
2237 | // +------------------+-----------------+------------------------------------+ | |||
2238 | // | sections | parallel | * | | |||
2239 | // | sections | for | + | | |||
2240 | // | sections | for simd | + | | |||
2241 | // | sections | master | + | | |||
2242 | // | sections | critical | * | | |||
2243 | // | sections | simd | * | | |||
2244 | // | sections | sections | + | | |||
2245 | // | sections | section | * | | |||
2246 | // | sections | single | + | | |||
2247 | // | sections | parallel for | * | | |||
2248 | // | sections |parallel for simd| * | | |||
2249 | // | sections |parallel sections| * | | |||
2250 | // | sections | task | * | | |||
2251 | // | sections | taskyield | * | | |||
2252 | // | sections | barrier | + | | |||
2253 | // | sections | taskwait | * | | |||
2254 | // | sections | taskgroup | * | | |||
2255 | // | sections | flush | * | | |||
2256 | // | sections | ordered | + | | |||
2257 | // | sections | atomic | * | | |||
2258 | // | sections | target | * | | |||
2259 | // | sections | target parallel | * | | |||
2260 | // | sections | target parallel | * | | |||
2261 | // | | for | | | |||
2262 | // | sections | target enter | * | | |||
2263 | // | | data | | | |||
2264 | // | sections | target exit | * | | |||
2265 | // | | data | | | |||
2266 | // | sections | teams | + | | |||
2267 | // | sections | cancellation | | | |||
2268 | // | | point | ! | | |||
2269 | // | sections | cancel | ! | | |||
2270 | // | sections | taskloop | * | | |||
2271 | // | sections | taskloop simd | * | | |||
2272 | // | sections | distribute | | | |||
2273 | // +------------------+-----------------+------------------------------------+ | |||
2274 | // | section | parallel | * | | |||
2275 | // | section | for | + | | |||
2276 | // | section | for simd | + | | |||
2277 | // | section | master | + | | |||
2278 | // | section | critical | * | | |||
2279 | // | section | simd | * | | |||
2280 | // | section | sections | + | | |||
2281 | // | section | section | + | | |||
2282 | // | section | single | + | | |||
2283 | // | section | parallel for | * | | |||
2284 | // | section |parallel for simd| * | | |||
2285 | // | section |parallel sections| * | | |||
2286 | // | section | task | * | | |||
2287 | // | section | taskyield | * | | |||
2288 | // | section | barrier | + | | |||
2289 | // | section | taskwait | * | | |||
2290 | // | section | taskgroup | * | | |||
2291 | // | section | flush | * | | |||
2292 | // | section | ordered | + | | |||
2293 | // | section | atomic | * | | |||
2294 | // | section | target | * | | |||
2295 | // | section | target parallel | * | | |||
2296 | // | section | target parallel | * | | |||
2297 | // | | for | | | |||
2298 | // | section | target enter | * | | |||
2299 | // | | data | | | |||
2300 | // | section | target exit | * | | |||
2301 | // | | data | | | |||
2302 | // | section | teams | + | | |||
2303 | // | section | cancellation | | | |||
2304 | // | | point | ! | | |||
2305 | // | section | cancel | ! | | |||
2306 | // | section | taskloop | * | | |||
2307 | // | section | taskloop simd | * | | |||
2308 | // | section | distribute | | | |||
2309 | // +------------------+-----------------+------------------------------------+ | |||
2310 | // | single | parallel | * | | |||
2311 | // | single | for | + | | |||
2312 | // | single | for simd | + | | |||
2313 | // | single | master | + | | |||
2314 | // | single | critical | * | | |||
2315 | // | single | simd | * | | |||
2316 | // | single | sections | + | | |||
2317 | // | single | section | + | | |||
2318 | // | single | single | + | | |||
2319 | // | single | parallel for | * | | |||
2320 | // | single |parallel for simd| * | | |||
2321 | // | single |parallel sections| * | | |||
2322 | // | single | task | * | | |||
2323 | // | single | taskyield | * | | |||
2324 | // | single | barrier | + | | |||
2325 | // | single | taskwait | * | | |||
2326 | // | single | taskgroup | * | | |||
2327 | // | single | flush | * | | |||
2328 | // | single | ordered | + | | |||
2329 | // | single | atomic | * | | |||
2330 | // | single | target | * | | |||
2331 | // | single | target parallel | * | | |||
2332 | // | single | target parallel | * | | |||
2333 | // | | for | | | |||
2334 | // | single | target enter | * | | |||
2335 | // | | data | | | |||
2336 | // | single | target exit | * | | |||
2337 | // | | data | | | |||
2338 | // | single | teams | + | | |||
2339 | // | single | cancellation | | | |||
2340 | // | | point | | | |||
2341 | // | single | cancel | | | |||
2342 | // | single | taskloop | * | | |||
2343 | // | single | taskloop simd | * | | |||
2344 | // | single | distribute | | | |||
2345 | // +------------------+-----------------+------------------------------------+ | |||
2346 | // | parallel for | parallel | * | | |||
2347 | // | parallel for | for | + | | |||
2348 | // | parallel for | for simd | + | | |||
2349 | // | parallel for | master | + | | |||
2350 | // | parallel for | critical | * | | |||
2351 | // | parallel for | simd | * | | |||
2352 | // | parallel for | sections | + | | |||
2353 | // | parallel for | section | + | | |||
2354 | // | parallel for | single | + | | |||
2355 | // | parallel for | parallel for | * | | |||
2356 | // | parallel for |parallel for simd| * | | |||
2357 | // | parallel for |parallel sections| * | | |||
2358 | // | parallel for | task | * | | |||
2359 | // | parallel for | taskyield | * | | |||
2360 | // | parallel for | barrier | + | | |||
2361 | // | parallel for | taskwait | * | | |||
2362 | // | parallel for | taskgroup | * | | |||
2363 | // | parallel for | flush | * | | |||
2364 | // | parallel for | ordered | * (if construct is ordered) | | |||
2365 | // | parallel for | atomic | * | | |||
2366 | // | parallel for | target | * | | |||
2367 | // | parallel for | target parallel | * | | |||
2368 | // | parallel for | target parallel | * | | |||
2369 | // | | for | | | |||
2370 | // | parallel for | target enter | * | | |||
2371 | // | | data | | | |||
2372 | // | parallel for | target exit | * | | |||
2373 | // | | data | | | |||
2374 | // | parallel for | teams | + | | |||
2375 | // | parallel for | cancellation | | | |||
2376 | // | | point | ! | | |||
2377 | // | parallel for | cancel | ! | | |||
2378 | // | parallel for | taskloop | * | | |||
2379 | // | parallel for | taskloop simd | * | | |||
2380 | // | parallel for | distribute | | | |||
2381 | // +------------------+-----------------+------------------------------------+ | |||
2382 | // | parallel sections| parallel | * | | |||
2383 | // | parallel sections| for | + | | |||
2384 | // | parallel sections| for simd | + | | |||
2385 | // | parallel sections| master | + | | |||
2386 | // | parallel sections| critical | + | | |||
2387 | // | parallel sections| simd | * | | |||
2388 | // | parallel sections| sections | + | | |||
2389 | // | parallel sections| section | * | | |||
2390 | // | parallel sections| single | + | | |||
2391 | // | parallel sections| parallel for | * | | |||
2392 | // | parallel sections|parallel for simd| * | | |||
2393 | // | parallel sections|parallel sections| * | | |||
2394 | // | parallel sections| task | * | | |||
2395 | // | parallel sections| taskyield | * | | |||
2396 | // | parallel sections| barrier | + | | |||
2397 | // | parallel sections| taskwait | * | | |||
2398 | // | parallel sections| taskgroup | * | | |||
2399 | // | parallel sections| flush | * | | |||
2400 | // | parallel sections| ordered | + | | |||
2401 | // | parallel sections| atomic | * | | |||
2402 | // | parallel sections| target | * | | |||
2403 | // | parallel sections| target parallel | * | | |||
2404 | // | parallel sections| target parallel | * | | |||
2405 | // | | for | | | |||
2406 | // | parallel sections| target enter | * | | |||
2407 | // | | data | | | |||
2408 | // | parallel sections| target exit | * | | |||
2409 | // | | data | | | |||
2410 | // | parallel sections| teams | + | | |||
2411 | // | parallel sections| cancellation | | | |||
2412 | // | | point | ! | | |||
2413 | // | parallel sections| cancel | ! | | |||
2414 | // | parallel sections| taskloop | * | | |||
2415 | // | parallel sections| taskloop simd | * | | |||
2416 | // | parallel sections| distribute | | | |||
2417 | // +------------------+-----------------+------------------------------------+ | |||
2418 | // | task | parallel | * | | |||
2419 | // | task | for | + | | |||
2420 | // | task | for simd | + | | |||
2421 | // | task | master | + | | |||
2422 | // | task | critical | * | | |||
2423 | // | task | simd | * | | |||
2424 | // | task | sections | + | | |||
2425 | // | task | section | + | | |||
2426 | // | task | single | + | | |||
2427 | // | task | parallel for | * | | |||
2428 | // | task |parallel for simd| * | | |||
2429 | // | task |parallel sections| * | | |||
2430 | // | task | task | * | | |||
2431 | // | task | taskyield | * | | |||
2432 | // | task | barrier | + | | |||
2433 | // | task | taskwait | * | | |||
2434 | // | task | taskgroup | * | | |||
2435 | // | task | flush | * | | |||
2436 | // | task | ordered | + | | |||
2437 | // | task | atomic | * | | |||
2438 | // | task | target | * | | |||
2439 | // | task | target parallel | * | | |||
2440 | // | task | target parallel | * | | |||
2441 | // | | for | | | |||
2442 | // | task | target enter | * | | |||
2443 | // | | data | | | |||
2444 | // | task | target exit | * | | |||
2445 | // | | data | | | |||
2446 | // | task | teams | + | | |||
2447 | // | task | cancellation | | | |||
2448 | // | | point | ! | | |||
2449 | // | task | cancel | ! | | |||
2450 | // | task | taskloop | * | | |||
2451 | // | task | taskloop simd | * | | |||
2452 | // | task | distribute | | | |||
2453 | // +------------------+-----------------+------------------------------------+ | |||
2454 | // | ordered | parallel | * | | |||
2455 | // | ordered | for | + | | |||
2456 | // | ordered | for simd | + | | |||
2457 | // | ordered | master | * | | |||
2458 | // | ordered | critical | * | | |||
2459 | // | ordered | simd | * | | |||
2460 | // | ordered | sections | + | | |||
2461 | // | ordered | section | + | | |||
2462 | // | ordered | single | + | | |||
2463 | // | ordered | parallel for | * | | |||
2464 | // | ordered |parallel for simd| * | | |||
2465 | // | ordered |parallel sections| * | | |||
2466 | // | ordered | task | * | | |||
2467 | // | ordered | taskyield | * | | |||
2468 | // | ordered | barrier | + | | |||
2469 | // | ordered | taskwait | * | | |||
2470 | // | ordered | taskgroup | * | | |||
2471 | // | ordered | flush | * | | |||
2472 | // | ordered | ordered | + | | |||
2473 | // | ordered | atomic | * | | |||
2474 | // | ordered | target | * | | |||
2475 | // | ordered | target parallel | * | | |||
2476 | // | ordered | target parallel | * | | |||
2477 | // | | for | | | |||
2478 | // | ordered | target enter | * | | |||
2479 | // | | data | | | |||
2480 | // | ordered | target exit | * | | |||
2481 | // | | data | | | |||
2482 | // | ordered | teams | + | | |||
2483 | // | ordered | cancellation | | | |||
2484 | // | | point | | | |||
2485 | // | ordered | cancel | | | |||
2486 | // | ordered | taskloop | * | | |||
2487 | // | ordered | taskloop simd | * | | |||
2488 | // | ordered | distribute | | | |||
2489 | // +------------------+-----------------+------------------------------------+ | |||
2490 | // | atomic | parallel | | | |||
2491 | // | atomic | for | | | |||
2492 | // | atomic | for simd | | | |||
2493 | // | atomic | master | | | |||
2494 | // | atomic | critical | | | |||
2495 | // | atomic | simd | | | |||
2496 | // | atomic | sections | | | |||
2497 | // | atomic | section | | | |||
2498 | // | atomic | single | | | |||
2499 | // | atomic | parallel for | | | |||
2500 | // | atomic |parallel for simd| | | |||
2501 | // | atomic |parallel sections| | | |||
2502 | // | atomic | task | | | |||
2503 | // | atomic | taskyield | | | |||
2504 | // | atomic | barrier | | | |||
2505 | // | atomic | taskwait | | | |||
2506 | // | atomic | taskgroup | | | |||
2507 | // | atomic | flush | | | |||
2508 | // | atomic | ordered | | | |||
2509 | // | atomic | atomic | | | |||
2510 | // | atomic | target | | | |||
2511 | // | atomic | target parallel | | | |||
2512 | // | atomic | target parallel | | | |||
2513 | // | | for | | | |||
2514 | // | atomic | target enter | | | |||
2515 | // | | data | | | |||
2516 | // | atomic | target exit | | | |||
2517 | // | | data | | | |||
2518 | // | atomic | teams | | | |||
2519 | // | atomic | cancellation | | | |||
2520 | // | | point | | | |||
2521 | // | atomic | cancel | | | |||
2522 | // | atomic | taskloop | | | |||
2523 | // | atomic | taskloop simd | | | |||
2524 | // | atomic | distribute | | | |||
2525 | // +------------------+-----------------+------------------------------------+ | |||
2526 | // | target | parallel | * | | |||
2527 | // | target | for | * | | |||
2528 | // | target | for simd | * | | |||
2529 | // | target | master | * | | |||
2530 | // | target | critical | * | | |||
2531 | // | target | simd | * | | |||
2532 | // | target | sections | * | | |||
2533 | // | target | section | * | | |||
2534 | // | target | single | * | | |||
2535 | // | target | parallel for | * | | |||
2536 | // | target |parallel for simd| * | | |||
2537 | // | target |parallel sections| * | | |||
2538 | // | target | task | * | | |||
2539 | // | target | taskyield | * | | |||
2540 | // | target | barrier | * | | |||
2541 | // | target | taskwait | * | | |||
2542 | // | target | taskgroup | * | | |||
2543 | // | target | flush | * | | |||
2544 | // | target | ordered | * | | |||
2545 | // | target | atomic | * | | |||
2546 | // | target | target | | | |||
2547 | // | target | target parallel | | | |||
2548 | // | target | target parallel | | | |||
2549 | // | | for | | | |||
2550 | // | target | target enter | | | |||
2551 | // | | data | | | |||
2552 | // | target | target exit | | | |||
2553 | // | | data | | | |||
2554 | // | target | teams | * | | |||
2555 | // | target | cancellation | | | |||
2556 | // | | point | | | |||
2557 | // | target | cancel | | | |||
2558 | // | target | taskloop | * | | |||
2559 | // | target | taskloop simd | * | | |||
2560 | // | target | distribute | | | |||
2561 | // +------------------+-----------------+------------------------------------+ | |||
2562 | // | target parallel | parallel | * | | |||
2563 | // | target parallel | for | * | | |||
2564 | // | target parallel | for simd | * | | |||
2565 | // | target parallel | master | * | | |||
2566 | // | target parallel | critical | * | | |||
2567 | // | target parallel | simd | * | | |||
2568 | // | target parallel | sections | * | | |||
2569 | // | target parallel | section | * | | |||
2570 | // | target parallel | single | * | | |||
2571 | // | target parallel | parallel for | * | | |||
2572 | // | target parallel |parallel for simd| * | | |||
2573 | // | target parallel |parallel sections| * | | |||
2574 | // | target parallel | task | * | | |||
2575 | // | target parallel | taskyield | * | | |||
2576 | // | target parallel | barrier | * | | |||
2577 | // | target parallel | taskwait | * | | |||
2578 | // | target parallel | taskgroup | * | | |||
2579 | // | target parallel | flush | * | | |||
2580 | // | target parallel | ordered | * | | |||
2581 | // | target parallel | atomic | * | | |||
2582 | // | target parallel | target | | | |||
2583 | // | target parallel | target parallel | | | |||
2584 | // | target parallel | target parallel | | | |||
2585 | // | | for | | | |||
2586 | // | target parallel | target enter | | | |||
2587 | // | | data | | | |||
2588 | // | target parallel | target exit | | | |||
2589 | // | | data | | | |||
2590 | // | target parallel | teams | | | |||
2591 | // | target parallel | cancellation | | | |||
2592 | // | | point | ! | | |||
2593 | // | target parallel | cancel | ! | | |||
2594 | // | target parallel | taskloop | * | | |||
2595 | // | target parallel | taskloop simd | * | | |||
2596 | // | target parallel | distribute | | | |||
2597 | // +------------------+-----------------+------------------------------------+ | |||
2598 | // | target parallel | parallel | * | | |||
2599 | // | for | | | | |||
2600 | // | target parallel | for | * | | |||
2601 | // | for | | | | |||
2602 | // | target parallel | for simd | * | | |||
2603 | // | for | | | | |||
2604 | // | target parallel | master | * | | |||
2605 | // | for | | | | |||
2606 | // | target parallel | critical | * | | |||
2607 | // | for | | | | |||
2608 | // | target parallel | simd | * | | |||
2609 | // | for | | | | |||
2610 | // | target parallel | sections | * | | |||
2611 | // | for | | | | |||
2612 | // | target parallel | section | * | | |||
2613 | // | for | | | | |||
2614 | // | target parallel | single | * | | |||
2615 | // | for | | | | |||
2616 | // | target parallel | parallel for | * | | |||
2617 | // | for | | | | |||
2618 | // | target parallel |parallel for simd| * | | |||
2619 | // | for | | | | |||
2620 | // | target parallel |parallel sections| * | | |||
2621 | // | for | | | | |||
2622 | // | target parallel | task | * | | |||
2623 | // | for | | | | |||
2624 | // | target parallel | taskyield | * | | |||
2625 | // | for | | | | |||
2626 | // | target parallel | barrier | * | | |||
2627 | // | for | | | | |||
2628 | // | target parallel | taskwait | * | | |||
2629 | // | for | | | | |||
2630 | // | target parallel | taskgroup | * | | |||
2631 | // | for | | | | |||
2632 | // | target parallel | flush | * | | |||
2633 | // | for | | | | |||
2634 | // | target parallel | ordered | * | | |||
2635 | // | for | | | | |||
2636 | // | target parallel | atomic | * | | |||
2637 | // | for | | | | |||
2638 | // | target parallel | target | | | |||
2639 | // | for | | | | |||
2640 | // | target parallel | target parallel | | | |||
2641 | // | for | | | | |||
2642 | // | target parallel | target parallel | | | |||
2643 | // | for | for | | | |||
2644 | // | target parallel | target enter | | | |||
2645 | // | for | data | | | |||
2646 | // | target parallel | target exit | | | |||
2647 | // | for | data | | | |||
2648 | // | target parallel | teams | | | |||
2649 | // | for | | | | |||
2650 | // | target parallel | cancellation | | | |||
2651 | // | for | point | ! | | |||
2652 | // | target parallel | cancel | ! | | |||
2653 | // | for | | | | |||
2654 | // | target parallel | taskloop | * | | |||
2655 | // | for | | | | |||
2656 | // | target parallel | taskloop simd | * | | |||
2657 | // | for | | | | |||
2658 | // | target parallel | distribute | | | |||
2659 | // | for | | | | |||
2660 | // +------------------+-----------------+------------------------------------+ | |||
2661 | // | teams | parallel | * | | |||
2662 | // | teams | for | + | | |||
2663 | // | teams | for simd | + | | |||
2664 | // | teams | master | + | | |||
2665 | // | teams | critical | + | | |||
2666 | // | teams | simd | + | | |||
2667 | // | teams | sections | + | | |||
2668 | // | teams | section | + | | |||
2669 | // | teams | single | + | | |||
2670 | // | teams | parallel for | * | | |||
2671 | // | teams |parallel for simd| * | | |||
2672 | // | teams |parallel sections| * | | |||
2673 | // | teams | task | + | | |||
2674 | // | teams | taskyield | + | | |||
2675 | // | teams | barrier | + | | |||
2676 | // | teams | taskwait | + | | |||
2677 | // | teams | taskgroup | + | | |||
2678 | // | teams | flush | + | | |||
2679 | // | teams | ordered | + | | |||
2680 | // | teams | atomic | + | | |||
2681 | // | teams | target | + | | |||
2682 | // | teams | target parallel | + | | |||
2683 | // | teams | target parallel | + | | |||
2684 | // | | for | | | |||
2685 | // | teams | target enter | + | | |||
2686 | // | | data | | | |||
2687 | // | teams | target exit | + | | |||
2688 | // | | data | | | |||
2689 | // | teams | teams | + | | |||
2690 | // | teams | cancellation | | | |||
2691 | // | | point | | | |||
2692 | // | teams | cancel | | | |||
2693 | // | teams | taskloop | + | | |||
2694 | // | teams | taskloop simd | + | | |||
2695 | // | teams | distribute | ! | | |||
2696 | // +------------------+-----------------+------------------------------------+ | |||
2697 | // | taskloop | parallel | * | | |||
2698 | // | taskloop | for | + | | |||
2699 | // | taskloop | for simd | + | | |||
2700 | // | taskloop | master | + | | |||
2701 | // | taskloop | critical | * | | |||
2702 | // | taskloop | simd | * | | |||
2703 | // | taskloop | sections | + | | |||
2704 | // | taskloop | section | + | | |||
2705 | // | taskloop | single | + | | |||
2706 | // | taskloop | parallel for | * | | |||
2707 | // | taskloop |parallel for simd| * | | |||
2708 | // | taskloop |parallel sections| * | | |||
2709 | // | taskloop | task | * | | |||
2710 | // | taskloop | taskyield | * | | |||
2711 | // | taskloop | barrier | + | | |||
2712 | // | taskloop | taskwait | * | | |||
2713 | // | taskloop | taskgroup | * | | |||
2714 | // | taskloop | flush | * | | |||
2715 | // | taskloop | ordered | + | | |||
2716 | // | taskloop | atomic | * | | |||
2717 | // | taskloop | target | * | | |||
2718 | // | taskloop | target parallel | * | | |||
2719 | // | taskloop | target parallel | * | | |||
2720 | // | | for | | | |||
2721 | // | taskloop | target enter | * | | |||
2722 | // | | data | | | |||
2723 | // | taskloop | target exit | * | | |||
2724 | // | | data | | | |||
2725 | // | taskloop | teams | + | | |||
2726 | // | taskloop | cancellation | | | |||
2727 | // | | point | | | |||
2728 | // | taskloop | cancel | | | |||
2729 | // | taskloop | taskloop | * | | |||
2730 | // | taskloop | distribute | | | |||
2731 | // +------------------+-----------------+------------------------------------+ | |||
2732 | // | taskloop simd | parallel | | | |||
2733 | // | taskloop simd | for | | | |||
2734 | // | taskloop simd | for simd | | | |||
2735 | // | taskloop simd | master | | | |||
2736 | // | taskloop simd | critical | | | |||
2737 | // | taskloop simd | simd | * | | |||
2738 | // | taskloop simd | sections | | | |||
2739 | // | taskloop simd | section | | | |||
2740 | // | taskloop simd | single | | | |||
2741 | // | taskloop simd | parallel for | | | |||
2742 | // | taskloop simd |parallel for simd| | | |||
2743 | // | taskloop simd |parallel sections| | | |||
2744 | // | taskloop simd | task | | | |||
2745 | // | taskloop simd | taskyield | | | |||
2746 | // | taskloop simd | barrier | | | |||
2747 | // | taskloop simd | taskwait | | | |||
2748 | // | taskloop simd | taskgroup | | | |||
2749 | // | taskloop simd | flush | | | |||
2750 | // | taskloop simd | ordered | + (with simd clause) | | |||
2751 | // | taskloop simd | atomic | | | |||
2752 | // | taskloop simd | target | | | |||
2753 | // | taskloop simd | target parallel | | | |||
2754 | // | taskloop simd | target parallel | | | |||
2755 | // | | for | | | |||
2756 | // | taskloop simd | target enter | | | |||
2757 | // | | data | | | |||
2758 | // | taskloop simd | target exit | | | |||
2759 | // | | data | | | |||
2760 | // | taskloop simd | teams | | | |||
2761 | // | taskloop simd | cancellation | | | |||
2762 | // | | point | | | |||
2763 | // | taskloop simd | cancel | | | |||
2764 | // | taskloop simd | taskloop | | | |||
2765 | // | taskloop simd | taskloop simd | | | |||
2766 | // | taskloop simd | distribute | | | |||
2767 | // +------------------+-----------------+------------------------------------+ | |||
2768 | // | distribute | parallel | * | | |||
2769 | // | distribute | for | * | | |||
2770 | // | distribute | for simd | * | | |||
2771 | // | distribute | master | * | | |||
2772 | // | distribute | critical | * | | |||
2773 | // | distribute | simd | * | | |||
2774 | // | distribute | sections | * | | |||
2775 | // | distribute | section | * | | |||
2776 | // | distribute | single | * | | |||
2777 | // | distribute | parallel for | * | | |||
2778 | // | distribute |parallel for simd| * | | |||
2779 | // | distribute |parallel sections| * | | |||
2780 | // | distribute | task | * | | |||
2781 | // | distribute | taskyield | * | | |||
2782 | // | distribute | barrier | * | | |||
2783 | // | distribute | taskwait | * | | |||
2784 | // | distribute | taskgroup | * | | |||
2785 | // | distribute | flush | * | | |||
2786 | // | distribute | ordered | + | | |||
2787 | // | distribute | atomic | * | | |||
2788 | // | distribute | target | | | |||
2789 | // | distribute | target parallel | | | |||
2790 | // | distribute | target parallel | | | |||
2791 | // | | for | | | |||
2792 | // | distribute | target enter | | | |||
2793 | // | | data | | | |||
2794 | // | distribute | target exit | | | |||
2795 | // | | data | | | |||
2796 | // | distribute | teams | | | |||
2797 | // | distribute | cancellation | + | | |||
2798 | // | | point | | | |||
2799 | // | distribute | cancel | + | | |||
2800 | // | distribute | taskloop | * | | |||
2801 | // | distribute | taskloop simd | * | | |||
2802 | // | distribute | distribute | | | |||
2803 | // +------------------+-----------------+------------------------------------+ | |||
2804 | if (Stack->getCurScope()) { | |||
2805 | auto ParentRegion = Stack->getParentDirective(); | |||
2806 | auto OffendingRegion = ParentRegion; | |||
2807 | bool NestingProhibited = false; | |||
2808 | bool CloseNesting = true; | |||
2809 | enum { | |||
2810 | NoRecommend, | |||
2811 | ShouldBeInParallelRegion, | |||
2812 | ShouldBeInOrderedRegion, | |||
2813 | ShouldBeInTargetRegion, | |||
2814 | ShouldBeInTeamsRegion | |||
2815 | } Recommend = NoRecommend; | |||
2816 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered && | |||
2817 | CurrentRegion != OMPD_simd) { | |||
2818 | // OpenMP [2.16, Nesting of Regions] | |||
2819 | // OpenMP constructs may not be nested inside a simd region. | |||
2820 | // OpenMP [2.8.1,simd Construct, Restrictions] | |||
2821 | // An ordered construct with the simd clause is the only OpenMP construct | |||
2822 | // that can appear in the simd region. | |||
2823 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); | |||
2824 | return true; | |||
2825 | } | |||
2826 | if (ParentRegion == OMPD_atomic) { | |||
2827 | // OpenMP [2.16, Nesting of Regions] | |||
2828 | // OpenMP constructs may not be nested inside an atomic region. | |||
2829 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); | |||
2830 | return true; | |||
2831 | } | |||
2832 | if (CurrentRegion == OMPD_section) { | |||
2833 | // OpenMP [2.7.2, sections Construct, Restrictions] | |||
2834 | // Orphaned section directives are prohibited. That is, the section | |||
2835 | // directives must appear within the sections construct and must not be | |||
2836 | // encountered elsewhere in the sections region. | |||
2837 | if (ParentRegion != OMPD_sections && | |||
2838 | ParentRegion != OMPD_parallel_sections) { | |||
2839 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) | |||
2840 | << (ParentRegion != OMPD_unknown) | |||
2841 | << getOpenMPDirectiveName(ParentRegion); | |||
2842 | return true; | |||
2843 | } | |||
2844 | return false; | |||
2845 | } | |||
2846 | // Allow some constructs to be orphaned (they could be used in functions, | |||
2847 | // called from OpenMP regions with the required preconditions). | |||
2848 | if (ParentRegion == OMPD_unknown) | |||
2849 | return false; | |||
2850 | if (CurrentRegion == OMPD_cancellation_point || | |||
2851 | CurrentRegion == OMPD_cancel) { | |||
2852 | // OpenMP [2.16, Nesting of Regions] | |||
2853 | // A cancellation point construct for which construct-type-clause is | |||
2854 | // taskgroup must be nested inside a task construct. A cancellation | |||
2855 | // point construct for which construct-type-clause is not taskgroup must | |||
2856 | // be closely nested inside an OpenMP construct that matches the type | |||
2857 | // specified in construct-type-clause. | |||
2858 | // A cancel construct for which construct-type-clause is taskgroup must be | |||
2859 | // nested inside a task construct. A cancel construct for which | |||
2860 | // construct-type-clause is not taskgroup must be closely nested inside an | |||
2861 | // OpenMP construct that matches the type specified in | |||
2862 | // construct-type-clause. | |||
2863 | NestingProhibited = | |||
2864 | !((CancelRegion == OMPD_parallel && | |||
2865 | (ParentRegion == OMPD_parallel || | |||
2866 | ParentRegion == OMPD_target_parallel)) || | |||
2867 | (CancelRegion == OMPD_for && | |||
2868 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || | |||
2869 | ParentRegion == OMPD_target_parallel_for)) || | |||
2870 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || | |||
2871 | (CancelRegion == OMPD_sections && | |||
2872 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || | |||
2873 | ParentRegion == OMPD_parallel_sections))); | |||
2874 | } else if (CurrentRegion == OMPD_master) { | |||
2875 | // OpenMP [2.16, Nesting of Regions] | |||
2876 | // A master region may not be closely nested inside a worksharing, | |||
2877 | // atomic, or explicit task region. | |||
2878 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || | |||
2879 | isOpenMPTaskingDirective(ParentRegion); | |||
2880 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { | |||
2881 | // OpenMP [2.16, Nesting of Regions] | |||
2882 | // A critical region may not be nested (closely or otherwise) inside a | |||
2883 | // critical region with the same name. Note that this restriction is not | |||
2884 | // sufficient to prevent deadlock. | |||
2885 | SourceLocation PreviousCriticalLoc; | |||
2886 | bool DeadLock = | |||
2887 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( | |||
2888 | OpenMPDirectiveKind K, | |||
2889 | const DeclarationNameInfo &DNI, | |||
2890 | SourceLocation Loc) | |||
2891 | ->bool { | |||
2892 | if (K == OMPD_critical && | |||
2893 | DNI.getName() == CurrentName.getName()) { | |||
2894 | PreviousCriticalLoc = Loc; | |||
2895 | return true; | |||
2896 | } else | |||
2897 | return false; | |||
2898 | }, | |||
2899 | false /* skip top directive */); | |||
2900 | if (DeadLock) { | |||
2901 | SemaRef.Diag(StartLoc, | |||
2902 | diag::err_omp_prohibited_region_critical_same_name) | |||
2903 | << CurrentName.getName(); | |||
2904 | if (PreviousCriticalLoc.isValid()) | |||
2905 | SemaRef.Diag(PreviousCriticalLoc, | |||
2906 | diag::note_omp_previous_critical_region); | |||
2907 | return true; | |||
2908 | } | |||
2909 | } else if (CurrentRegion == OMPD_barrier) { | |||
2910 | // OpenMP [2.16, Nesting of Regions] | |||
2911 | // A barrier region may not be closely nested inside a worksharing, | |||
2912 | // explicit task, critical, ordered, atomic, or master region. | |||
2913 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || | |||
2914 | isOpenMPTaskingDirective(ParentRegion) || | |||
2915 | ParentRegion == OMPD_master || | |||
2916 | ParentRegion == OMPD_critical || | |||
2917 | ParentRegion == OMPD_ordered; | |||
2918 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && | |||
2919 | !isOpenMPParallelDirective(CurrentRegion)) { | |||
2920 | // OpenMP [2.16, Nesting of Regions] | |||
2921 | // A worksharing region may not be closely nested inside a worksharing, | |||
2922 | // explicit task, critical, ordered, atomic, or master region. | |||
2923 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || | |||
2924 | isOpenMPTaskingDirective(ParentRegion) || | |||
2925 | ParentRegion == OMPD_master || | |||
2926 | ParentRegion == OMPD_critical || | |||
2927 | ParentRegion == OMPD_ordered; | |||
2928 | Recommend = ShouldBeInParallelRegion; | |||
2929 | } else if (CurrentRegion == OMPD_ordered) { | |||
2930 | // OpenMP [2.16, Nesting of Regions] | |||
2931 | // An ordered region may not be closely nested inside a critical, | |||
2932 | // atomic, or explicit task region. | |||
2933 | // An ordered region must be closely nested inside a loop region (or | |||
2934 | // parallel loop region) with an ordered clause. | |||
2935 | // OpenMP [2.8.1,simd Construct, Restrictions] | |||
2936 | // An ordered construct with the simd clause is the only OpenMP construct | |||
2937 | // that can appear in the simd region. | |||
2938 | NestingProhibited = ParentRegion == OMPD_critical || | |||
2939 | isOpenMPTaskingDirective(ParentRegion) || | |||
2940 | !(isOpenMPSimdDirective(ParentRegion) || | |||
2941 | Stack->isParentOrderedRegion()); | |||
2942 | Recommend = ShouldBeInOrderedRegion; | |||
2943 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { | |||
2944 | // OpenMP [2.16, Nesting of Regions] | |||
2945 | // If specified, a teams construct must be contained within a target | |||
2946 | // construct. | |||
2947 | NestingProhibited = ParentRegion != OMPD_target; | |||
2948 | Recommend = ShouldBeInTargetRegion; | |||
2949 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); | |||
2950 | } | |||
2951 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { | |||
2952 | // OpenMP [2.16, Nesting of Regions] | |||
2953 | // distribute, parallel, parallel sections, parallel workshare, and the | |||
2954 | // parallel loop and parallel loop SIMD constructs are the only OpenMP | |||
2955 | // constructs that can be closely nested in the teams region. | |||
2956 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && | |||
2957 | !isOpenMPDistributeDirective(CurrentRegion); | |||
2958 | Recommend = ShouldBeInParallelRegion; | |||
2959 | } | |||
2960 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { | |||
2961 | // OpenMP 4.5 [2.17 Nesting of Regions] | |||
2962 | // The region associated with the distribute construct must be strictly | |||
2963 | // nested inside a teams region | |||
2964 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); | |||
2965 | Recommend = ShouldBeInTeamsRegion; | |||
2966 | } | |||
2967 | if (!NestingProhibited && | |||
2968 | (isOpenMPTargetExecutionDirective(CurrentRegion) || | |||
2969 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { | |||
2970 | // OpenMP 4.5 [2.17 Nesting of Regions] | |||
2971 | // If a target, target update, target data, target enter data, or | |||
2972 | // target exit data construct is encountered during execution of a | |||
2973 | // target region, the behavior is unspecified. | |||
2974 | NestingProhibited = Stack->hasDirective( | |||
2975 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, | |||
2976 | SourceLocation) -> bool { | |||
2977 | if (isOpenMPTargetExecutionDirective(K)) { | |||
2978 | OffendingRegion = K; | |||
2979 | return true; | |||
2980 | } else | |||
2981 | return false; | |||
2982 | }, | |||
2983 | false /* don't skip top directive */); | |||
2984 | CloseNesting = false; | |||
2985 | } | |||
2986 | if (NestingProhibited) { | |||
2987 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) | |||
2988 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) | |||
2989 | << Recommend << getOpenMPDirectiveName(CurrentRegion); | |||
2990 | return true; | |||
2991 | } | |||
2992 | } | |||
2993 | return false; | |||
2994 | } | |||
2995 | ||||
2996 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, | |||
2997 | ArrayRef<OMPClause *> Clauses, | |||
2998 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { | |||
2999 | bool ErrorFound = false; | |||
3000 | unsigned NamedModifiersNumber = 0; | |||
3001 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( | |||
3002 | OMPD_unknown + 1); | |||
3003 | SmallVector<SourceLocation, 4> NameModifierLoc; | |||
3004 | for (const auto *C : Clauses) { | |||
3005 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { | |||
3006 | // At most one if clause without a directive-name-modifier can appear on | |||
3007 | // the directive. | |||
3008 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); | |||
3009 | if (FoundNameModifiers[CurNM]) { | |||
3010 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) | |||
3011 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) | |||
3012 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); | |||
3013 | ErrorFound = true; | |||
3014 | } else if (CurNM != OMPD_unknown) { | |||
3015 | NameModifierLoc.push_back(IC->getNameModifierLoc()); | |||
3016 | ++NamedModifiersNumber; | |||
3017 | } | |||
3018 | FoundNameModifiers[CurNM] = IC; | |||
3019 | if (CurNM == OMPD_unknown) | |||
3020 | continue; | |||
3021 | // Check if the specified name modifier is allowed for the current | |||
3022 | // directive. | |||
3023 | // At most one if clause with the particular directive-name-modifier can | |||
3024 | // appear on the directive. | |||
3025 | bool MatchFound = false; | |||
3026 | for (auto NM : AllowedNameModifiers) { | |||
3027 | if (CurNM == NM) { | |||
3028 | MatchFound = true; | |||
3029 | break; | |||
3030 | } | |||
3031 | } | |||
3032 | if (!MatchFound) { | |||
3033 | S.Diag(IC->getNameModifierLoc(), | |||
3034 | diag::err_omp_wrong_if_directive_name_modifier) | |||
3035 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); | |||
3036 | ErrorFound = true; | |||
3037 | } | |||
3038 | } | |||
3039 | } | |||
3040 | // If any if clause on the directive includes a directive-name-modifier then | |||
3041 | // all if clauses on the directive must include a directive-name-modifier. | |||
3042 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { | |||
3043 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { | |||
3044 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), | |||
3045 | diag::err_omp_no_more_if_clause); | |||
3046 | } else { | |||
3047 | std::string Values; | |||
3048 | std::string Sep(", "); | |||
3049 | unsigned AllowedCnt = 0; | |||
3050 | unsigned TotalAllowedNum = | |||
3051 | AllowedNameModifiers.size() - NamedModifiersNumber; | |||
3052 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; | |||
3053 | ++Cnt) { | |||
3054 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; | |||
3055 | if (!FoundNameModifiers[NM]) { | |||
3056 | Values += "'"; | |||
3057 | Values += getOpenMPDirectiveName(NM); | |||
3058 | Values += "'"; | |||
3059 | if (AllowedCnt + 2 == TotalAllowedNum) | |||
3060 | Values += " or "; | |||
3061 | else if (AllowedCnt + 1 != TotalAllowedNum) | |||
3062 | Values += Sep; | |||
3063 | ++AllowedCnt; | |||
3064 | } | |||
3065 | } | |||
3066 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), | |||
3067 | diag::err_omp_unnamed_if_clause) | |||
3068 | << (TotalAllowedNum > 1) << Values; | |||
3069 | } | |||
3070 | for (auto Loc : NameModifierLoc) { | |||
3071 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); | |||
3072 | } | |||
3073 | ErrorFound = true; | |||
3074 | } | |||
3075 | return ErrorFound; | |||
3076 | } | |||
3077 | ||||
3078 | StmtResult Sema::ActOnOpenMPExecutableDirective( | |||
3079 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, | |||
3080 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, | |||
3081 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { | |||
3082 | StmtResult Res = StmtError(); | |||
3083 | if (CheckNestingOfRegions(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), Kind, DirName, CancelRegion, | |||
3084 | StartLoc)) | |||
3085 | return StmtError(); | |||
3086 | ||||
3087 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; | |||
3088 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; | |||
3089 | bool ErrorFound = false; | |||
3090 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); | |||
3091 | if (AStmt) { | |||
3092 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3092, __PRETTY_FUNCTION__)); | |||
3093 | ||||
3094 | // Check default data sharing attributes for referenced variables. | |||
3095 | DSAAttrChecker DSAChecker(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), *this, cast<CapturedStmt>(AStmt)); | |||
3096 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); | |||
3097 | if (DSAChecker.isErrorFound()) | |||
3098 | return StmtError(); | |||
3099 | // Generate list of implicitly defined firstprivate variables. | |||
3100 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); | |||
3101 | ||||
3102 | if (!DSAChecker.getImplicitFirstprivate().empty()) { | |||
3103 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( | |||
3104 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), | |||
3105 | SourceLocation(), SourceLocation())) { | |||
3106 | ClausesWithImplicit.push_back(Implicit); | |||
3107 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != | |||
3108 | DSAChecker.getImplicitFirstprivate().size(); | |||
3109 | } else | |||
3110 | ErrorFound = true; | |||
3111 | } | |||
3112 | } | |||
3113 | ||||
3114 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; | |||
3115 | switch (Kind) { | |||
3116 | case OMPD_parallel: | |||
3117 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, | |||
3118 | EndLoc); | |||
3119 | AllowedNameModifiers.push_back(OMPD_parallel); | |||
3120 | break; | |||
3121 | case OMPD_simd: | |||
3122 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, | |||
3123 | VarsWithInheritedDSA); | |||
3124 | break; | |||
3125 | case OMPD_for: | |||
3126 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, | |||
3127 | VarsWithInheritedDSA); | |||
3128 | break; | |||
3129 | case OMPD_for_simd: | |||
3130 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, | |||
3131 | EndLoc, VarsWithInheritedDSA); | |||
3132 | break; | |||
3133 | case OMPD_sections: | |||
3134 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, | |||
3135 | EndLoc); | |||
3136 | break; | |||
3137 | case OMPD_section: | |||
3138 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp section' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp section' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3139, __PRETTY_FUNCTION__)) | |||
3139 | "No clauses are allowed for 'omp section' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp section' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp section' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3139, __PRETTY_FUNCTION__)); | |||
3140 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); | |||
3141 | break; | |||
3142 | case OMPD_single: | |||
3143 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, | |||
3144 | EndLoc); | |||
3145 | break; | |||
3146 | case OMPD_master: | |||
3147 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp master' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp master' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3148, __PRETTY_FUNCTION__)) | |||
3148 | "No clauses are allowed for 'omp master' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp master' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp master' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3148, __PRETTY_FUNCTION__)); | |||
3149 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); | |||
3150 | break; | |||
3151 | case OMPD_critical: | |||
3152 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, | |||
3153 | StartLoc, EndLoc); | |||
3154 | break; | |||
3155 | case OMPD_parallel_for: | |||
3156 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, | |||
3157 | EndLoc, VarsWithInheritedDSA); | |||
3158 | AllowedNameModifiers.push_back(OMPD_parallel); | |||
3159 | break; | |||
3160 | case OMPD_parallel_for_simd: | |||
3161 | Res = ActOnOpenMPParallelForSimdDirective( | |||
3162 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); | |||
3163 | AllowedNameModifiers.push_back(OMPD_parallel); | |||
3164 | break; | |||
3165 | case OMPD_parallel_sections: | |||
3166 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, | |||
3167 | StartLoc, EndLoc); | |||
3168 | AllowedNameModifiers.push_back(OMPD_parallel); | |||
3169 | break; | |||
3170 | case OMPD_task: | |||
3171 | Res = | |||
3172 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); | |||
3173 | AllowedNameModifiers.push_back(OMPD_task); | |||
3174 | break; | |||
3175 | case OMPD_taskyield: | |||
3176 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp taskyield' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp taskyield' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3177, __PRETTY_FUNCTION__)) | |||
3177 | "No clauses are allowed for 'omp taskyield' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp taskyield' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp taskyield' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3177, __PRETTY_FUNCTION__)); | |||
3178 | assert(AStmt == nullptr &&((AStmt == nullptr && "No associated statement allowed for 'omp taskyield' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp taskyield' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3179, __PRETTY_FUNCTION__)) | |||
3179 | "No associated statement allowed for 'omp taskyield' directive")((AStmt == nullptr && "No associated statement allowed for 'omp taskyield' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp taskyield' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3179, __PRETTY_FUNCTION__)); | |||
3180 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); | |||
3181 | break; | |||
3182 | case OMPD_barrier: | |||
3183 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp barrier' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp barrier' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3184, __PRETTY_FUNCTION__)) | |||
3184 | "No clauses are allowed for 'omp barrier' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp barrier' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp barrier' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3184, __PRETTY_FUNCTION__)); | |||
3185 | assert(AStmt == nullptr &&((AStmt == nullptr && "No associated statement allowed for 'omp barrier' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp barrier' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3186, __PRETTY_FUNCTION__)) | |||
3186 | "No associated statement allowed for 'omp barrier' directive")((AStmt == nullptr && "No associated statement allowed for 'omp barrier' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp barrier' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3186, __PRETTY_FUNCTION__)); | |||
3187 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); | |||
3188 | break; | |||
3189 | case OMPD_taskwait: | |||
3190 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp taskwait' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp taskwait' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3191, __PRETTY_FUNCTION__)) | |||
3191 | "No clauses are allowed for 'omp taskwait' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp taskwait' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp taskwait' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3191, __PRETTY_FUNCTION__)); | |||
3192 | assert(AStmt == nullptr &&((AStmt == nullptr && "No associated statement allowed for 'omp taskwait' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp taskwait' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3193, __PRETTY_FUNCTION__)) | |||
3193 | "No associated statement allowed for 'omp taskwait' directive")((AStmt == nullptr && "No associated statement allowed for 'omp taskwait' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp taskwait' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3193, __PRETTY_FUNCTION__)); | |||
3194 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); | |||
3195 | break; | |||
3196 | case OMPD_taskgroup: | |||
3197 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp taskgroup' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp taskgroup' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3198, __PRETTY_FUNCTION__)) | |||
3198 | "No clauses are allowed for 'omp taskgroup' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp taskgroup' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp taskgroup' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3198, __PRETTY_FUNCTION__)); | |||
3199 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); | |||
3200 | break; | |||
3201 | case OMPD_flush: | |||
3202 | assert(AStmt == nullptr &&((AStmt == nullptr && "No associated statement allowed for 'omp flush' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp flush' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3203, __PRETTY_FUNCTION__)) | |||
3203 | "No associated statement allowed for 'omp flush' directive")((AStmt == nullptr && "No associated statement allowed for 'omp flush' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp flush' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3203, __PRETTY_FUNCTION__)); | |||
3204 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); | |||
3205 | break; | |||
3206 | case OMPD_ordered: | |||
3207 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, | |||
3208 | EndLoc); | |||
3209 | break; | |||
3210 | case OMPD_atomic: | |||
3211 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, | |||
3212 | EndLoc); | |||
3213 | break; | |||
3214 | case OMPD_teams: | |||
3215 | Res = | |||
3216 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); | |||
3217 | break; | |||
3218 | case OMPD_target: | |||
3219 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, | |||
3220 | EndLoc); | |||
3221 | AllowedNameModifiers.push_back(OMPD_target); | |||
3222 | break; | |||
3223 | case OMPD_target_parallel: | |||
3224 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, | |||
3225 | StartLoc, EndLoc); | |||
3226 | AllowedNameModifiers.push_back(OMPD_target); | |||
3227 | AllowedNameModifiers.push_back(OMPD_parallel); | |||
3228 | break; | |||
3229 | case OMPD_target_parallel_for: | |||
3230 | Res = ActOnOpenMPTargetParallelForDirective( | |||
3231 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); | |||
3232 | AllowedNameModifiers.push_back(OMPD_target); | |||
3233 | AllowedNameModifiers.push_back(OMPD_parallel); | |||
3234 | break; | |||
3235 | case OMPD_cancellation_point: | |||
3236 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp cancellation point' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp cancellation point' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3237, __PRETTY_FUNCTION__)) | |||
3237 | "No clauses are allowed for 'omp cancellation point' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp cancellation point' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp cancellation point' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3237, __PRETTY_FUNCTION__)); | |||
3238 | assert(AStmt == nullptr && "No associated statement allowed for 'omp "((AStmt == nullptr && "No associated statement allowed for 'omp " "cancellation point' directive") ? static_cast<void> ( 0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp \" \"cancellation point' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3239, __PRETTY_FUNCTION__)) | |||
3239 | "cancellation point' directive")((AStmt == nullptr && "No associated statement allowed for 'omp " "cancellation point' directive") ? static_cast<void> ( 0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp \" \"cancellation point' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3239, __PRETTY_FUNCTION__)); | |||
3240 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); | |||
3241 | break; | |||
3242 | case OMPD_cancel: | |||
3243 | assert(AStmt == nullptr &&((AStmt == nullptr && "No associated statement allowed for 'omp cancel' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp cancel' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3244, __PRETTY_FUNCTION__)) | |||
3244 | "No associated statement allowed for 'omp cancel' directive")((AStmt == nullptr && "No associated statement allowed for 'omp cancel' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp cancel' directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3244, __PRETTY_FUNCTION__)); | |||
3245 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, | |||
3246 | CancelRegion); | |||
3247 | AllowedNameModifiers.push_back(OMPD_cancel); | |||
3248 | break; | |||
3249 | case OMPD_target_data: | |||
3250 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, | |||
3251 | EndLoc); | |||
3252 | AllowedNameModifiers.push_back(OMPD_target_data); | |||
3253 | break; | |||
3254 | case OMPD_target_enter_data: | |||
3255 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, | |||
3256 | EndLoc); | |||
3257 | AllowedNameModifiers.push_back(OMPD_target_enter_data); | |||
3258 | break; | |||
3259 | case OMPD_target_exit_data: | |||
3260 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, | |||
3261 | EndLoc); | |||
3262 | AllowedNameModifiers.push_back(OMPD_target_exit_data); | |||
3263 | break; | |||
3264 | case OMPD_taskloop: | |||
3265 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, | |||
3266 | EndLoc, VarsWithInheritedDSA); | |||
3267 | AllowedNameModifiers.push_back(OMPD_taskloop); | |||
3268 | break; | |||
3269 | case OMPD_taskloop_simd: | |||
3270 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, | |||
3271 | EndLoc, VarsWithInheritedDSA); | |||
3272 | AllowedNameModifiers.push_back(OMPD_taskloop); | |||
3273 | break; | |||
3274 | case OMPD_distribute: | |||
3275 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, | |||
3276 | EndLoc, VarsWithInheritedDSA); | |||
3277 | break; | |||
3278 | case OMPD_target_update: | |||
3279 | assert(!AStmt && "Statement is not allowed for target update")((!AStmt && "Statement is not allowed for target update" ) ? static_cast<void> (0) : __assert_fail ("!AStmt && \"Statement is not allowed for target update\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3279, __PRETTY_FUNCTION__)); | |||
3280 | Res = | |||
3281 | ActOnOpenMPTargetUpdateDirective(ClausesWithImplicit, StartLoc, EndLoc); | |||
3282 | AllowedNameModifiers.push_back(OMPD_target_update); | |||
3283 | break; | |||
3284 | case OMPD_declare_target: | |||
3285 | case OMPD_end_declare_target: | |||
3286 | case OMPD_threadprivate: | |||
3287 | case OMPD_declare_reduction: | |||
3288 | case OMPD_declare_simd: | |||
3289 | llvm_unreachable("OpenMP Directive is not allowed")::llvm::llvm_unreachable_internal("OpenMP Directive is not allowed" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3289); | |||
3290 | case OMPD_unknown: | |||
3291 | llvm_unreachable("Unknown OpenMP directive")::llvm::llvm_unreachable_internal("Unknown OpenMP directive", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3291); | |||
3292 | } | |||
3293 | ||||
3294 | for (auto P : VarsWithInheritedDSA) { | |||
3295 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) | |||
3296 | << P.first << P.second->getSourceRange(); | |||
3297 | } | |||
3298 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; | |||
3299 | ||||
3300 | if (!AllowedNameModifiers.empty()) | |||
3301 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || | |||
3302 | ErrorFound; | |||
3303 | ||||
3304 | if (ErrorFound) | |||
3305 | return StmtError(); | |||
3306 | return Res; | |||
3307 | } | |||
3308 | ||||
3309 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( | |||
3310 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, | |||
3311 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, | |||
3312 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, | |||
3313 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { | |||
3314 | assert(Aligneds.size() == Alignments.size())((Aligneds.size() == Alignments.size()) ? static_cast<void > (0) : __assert_fail ("Aligneds.size() == Alignments.size()" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3314, __PRETTY_FUNCTION__)); | |||
3315 | assert(Linears.size() == LinModifiers.size())((Linears.size() == LinModifiers.size()) ? static_cast<void > (0) : __assert_fail ("Linears.size() == LinModifiers.size()" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3315, __PRETTY_FUNCTION__)); | |||
3316 | assert(Linears.size() == Steps.size())((Linears.size() == Steps.size()) ? static_cast<void> ( 0) : __assert_fail ("Linears.size() == Steps.size()", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3316, __PRETTY_FUNCTION__)); | |||
3317 | if (!DG || DG.get().isNull()) | |||
3318 | return DeclGroupPtrTy(); | |||
3319 | ||||
3320 | if (!DG.get().isSingleDecl()) { | |||
3321 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd); | |||
3322 | return DG; | |||
3323 | } | |||
3324 | auto *ADecl = DG.get().getSingleDecl(); | |||
3325 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) | |||
3326 | ADecl = FTD->getTemplatedDecl(); | |||
3327 | ||||
3328 | auto *FD = dyn_cast<FunctionDecl>(ADecl); | |||
3329 | if (!FD) { | |||
3330 | Diag(ADecl->getLocation(), diag::err_omp_function_expected); | |||
3331 | return DeclGroupPtrTy(); | |||
3332 | } | |||
3333 | ||||
3334 | // OpenMP [2.8.2, declare simd construct, Description] | |||
3335 | // The parameter of the simdlen clause must be a constant positive integer | |||
3336 | // expression. | |||
3337 | ExprResult SL; | |||
3338 | if (Simdlen) | |||
3339 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); | |||
3340 | // OpenMP [2.8.2, declare simd construct, Description] | |||
3341 | // The special this pointer can be used as if was one of the arguments to the | |||
3342 | // function in any of the linear, aligned, or uniform clauses. | |||
3343 | // The uniform clause declares one or more arguments to have an invariant | |||
3344 | // value for all concurrent invocations of the function in the execution of a | |||
3345 | // single SIMD loop. | |||
3346 | llvm::DenseMap<Decl *, Expr *> UniformedArgs; | |||
3347 | Expr *UniformedLinearThis = nullptr; | |||
3348 | for (auto *E : Uniforms) { | |||
3349 | E = E->IgnoreParenImpCasts(); | |||
3350 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) | |||
3351 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) | |||
3352 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && | |||
3353 | FD->getParamDecl(PVD->getFunctionScopeIndex()) | |||
3354 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { | |||
3355 | UniformedArgs.insert(std::make_pair(PVD->getCanonicalDecl(), E)); | |||
3356 | continue; | |||
3357 | } | |||
3358 | if (isa<CXXThisExpr>(E)) { | |||
3359 | UniformedLinearThis = E; | |||
3360 | continue; | |||
3361 | } | |||
3362 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) | |||
3363 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); | |||
3364 | } | |||
3365 | // OpenMP [2.8.2, declare simd construct, Description] | |||
3366 | // The aligned clause declares that the object to which each list item points | |||
3367 | // is aligned to the number of bytes expressed in the optional parameter of | |||
3368 | // the aligned clause. | |||
3369 | // The special this pointer can be used as if was one of the arguments to the | |||
3370 | // function in any of the linear, aligned, or uniform clauses. | |||
3371 | // The type of list items appearing in the aligned clause must be array, | |||
3372 | // pointer, reference to array, or reference to pointer. | |||
3373 | llvm::DenseMap<Decl *, Expr *> AlignedArgs; | |||
3374 | Expr *AlignedThis = nullptr; | |||
3375 | for (auto *E : Aligneds) { | |||
3376 | E = E->IgnoreParenImpCasts(); | |||
3377 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) | |||
3378 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { | |||
3379 | auto *CanonPVD = PVD->getCanonicalDecl(); | |||
3380 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && | |||
3381 | FD->getParamDecl(PVD->getFunctionScopeIndex()) | |||
3382 | ->getCanonicalDecl() == CanonPVD) { | |||
3383 | // OpenMP [2.8.1, simd construct, Restrictions] | |||
3384 | // A list-item cannot appear in more than one aligned clause. | |||
3385 | if (AlignedArgs.count(CanonPVD) > 0) { | |||
3386 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) | |||
3387 | << 1 << E->getSourceRange(); | |||
3388 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), | |||
3389 | diag::note_omp_explicit_dsa) | |||
3390 | << getOpenMPClauseName(OMPC_aligned); | |||
3391 | continue; | |||
3392 | } | |||
3393 | AlignedArgs[CanonPVD] = E; | |||
3394 | QualType QTy = PVD->getType() | |||
3395 | .getNonReferenceType() | |||
3396 | .getUnqualifiedType() | |||
3397 | .getCanonicalType(); | |||
3398 | const Type *Ty = QTy.getTypePtrOrNull(); | |||
3399 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { | |||
3400 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) | |||
3401 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); | |||
3402 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; | |||
3403 | } | |||
3404 | continue; | |||
3405 | } | |||
3406 | } | |||
3407 | if (isa<CXXThisExpr>(E)) { | |||
3408 | if (AlignedThis) { | |||
3409 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) | |||
3410 | << 2 << E->getSourceRange(); | |||
3411 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) | |||
3412 | << getOpenMPClauseName(OMPC_aligned); | |||
3413 | } | |||
3414 | AlignedThis = E; | |||
3415 | continue; | |||
3416 | } | |||
3417 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) | |||
3418 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); | |||
3419 | } | |||
3420 | // The optional parameter of the aligned clause, alignment, must be a constant | |||
3421 | // positive integer expression. If no optional parameter is specified, | |||
3422 | // implementation-defined default alignments for SIMD instructions on the | |||
3423 | // target platforms are assumed. | |||
3424 | SmallVector<Expr *, 4> NewAligns; | |||
3425 | for (auto *E : Alignments) { | |||
3426 | ExprResult Align; | |||
3427 | if (E) | |||
3428 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); | |||
3429 | NewAligns.push_back(Align.get()); | |||
3430 | } | |||
3431 | // OpenMP [2.8.2, declare simd construct, Description] | |||
3432 | // The linear clause declares one or more list items to be private to a SIMD | |||
3433 | // lane and to have a linear relationship with respect to the iteration space | |||
3434 | // of a loop. | |||
3435 | // The special this pointer can be used as if was one of the arguments to the | |||
3436 | // function in any of the linear, aligned, or uniform clauses. | |||
3437 | // When a linear-step expression is specified in a linear clause it must be | |||
3438 | // either a constant integer expression or an integer-typed parameter that is | |||
3439 | // specified in a uniform clause on the directive. | |||
3440 | llvm::DenseMap<Decl *, Expr *> LinearArgs; | |||
3441 | const bool IsUniformedThis = UniformedLinearThis != nullptr; | |||
3442 | auto MI = LinModifiers.begin(); | |||
3443 | for (auto *E : Linears) { | |||
3444 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); | |||
3445 | ++MI; | |||
3446 | E = E->IgnoreParenImpCasts(); | |||
3447 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) | |||
3448 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { | |||
3449 | auto *CanonPVD = PVD->getCanonicalDecl(); | |||
3450 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && | |||
3451 | FD->getParamDecl(PVD->getFunctionScopeIndex()) | |||
3452 | ->getCanonicalDecl() == CanonPVD) { | |||
3453 | // OpenMP [2.15.3.7, linear Clause, Restrictions] | |||
3454 | // A list-item cannot appear in more than one linear clause. | |||
3455 | if (LinearArgs.count(CanonPVD) > 0) { | |||
3456 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) | |||
3457 | << getOpenMPClauseName(OMPC_linear) | |||
3458 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); | |||
3459 | Diag(LinearArgs[CanonPVD]->getExprLoc(), | |||
3460 | diag::note_omp_explicit_dsa) | |||
3461 | << getOpenMPClauseName(OMPC_linear); | |||
3462 | continue; | |||
3463 | } | |||
3464 | // Each argument can appear in at most one uniform or linear clause. | |||
3465 | if (UniformedArgs.count(CanonPVD) > 0) { | |||
3466 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) | |||
3467 | << getOpenMPClauseName(OMPC_linear) | |||
3468 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); | |||
3469 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), | |||
3470 | diag::note_omp_explicit_dsa) | |||
3471 | << getOpenMPClauseName(OMPC_uniform); | |||
3472 | continue; | |||
3473 | } | |||
3474 | LinearArgs[CanonPVD] = E; | |||
3475 | if (E->isValueDependent() || E->isTypeDependent() || | |||
3476 | E->isInstantiationDependent() || | |||
3477 | E->containsUnexpandedParameterPack()) | |||
3478 | continue; | |||
3479 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, | |||
3480 | PVD->getOriginalType()); | |||
3481 | continue; | |||
3482 | } | |||
3483 | } | |||
3484 | if (isa<CXXThisExpr>(E)) { | |||
3485 | if (UniformedLinearThis) { | |||
3486 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) | |||
3487 | << getOpenMPClauseName(OMPC_linear) | |||
3488 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) | |||
3489 | << E->getSourceRange(); | |||
3490 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) | |||
3491 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform | |||
3492 | : OMPC_linear); | |||
3493 | continue; | |||
3494 | } | |||
3495 | UniformedLinearThis = E; | |||
3496 | if (E->isValueDependent() || E->isTypeDependent() || | |||
3497 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) | |||
3498 | continue; | |||
3499 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, | |||
3500 | E->getType()); | |||
3501 | continue; | |||
3502 | } | |||
3503 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) | |||
3504 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); | |||
3505 | } | |||
3506 | Expr *Step = nullptr; | |||
3507 | Expr *NewStep = nullptr; | |||
3508 | SmallVector<Expr *, 4> NewSteps; | |||
3509 | for (auto *E : Steps) { | |||
3510 | // Skip the same step expression, it was checked already. | |||
3511 | if (Step == E || !E) { | |||
3512 | NewSteps.push_back(E ? NewStep : nullptr); | |||
3513 | continue; | |||
3514 | } | |||
3515 | Step = E; | |||
3516 | if (auto *DRE = dyn_cast<DeclRefExpr>(Step)) | |||
3517 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { | |||
3518 | auto *CanonPVD = PVD->getCanonicalDecl(); | |||
3519 | if (UniformedArgs.count(CanonPVD) == 0) { | |||
3520 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) | |||
3521 | << Step->getSourceRange(); | |||
3522 | } else if (E->isValueDependent() || E->isTypeDependent() || | |||
3523 | E->isInstantiationDependent() || | |||
3524 | E->containsUnexpandedParameterPack() || | |||
3525 | CanonPVD->getType()->hasIntegerRepresentation()) | |||
3526 | NewSteps.push_back(Step); | |||
3527 | else { | |||
3528 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) | |||
3529 | << Step->getSourceRange(); | |||
3530 | } | |||
3531 | continue; | |||
3532 | } | |||
3533 | NewStep = Step; | |||
3534 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && | |||
3535 | !Step->isInstantiationDependent() && | |||
3536 | !Step->containsUnexpandedParameterPack()) { | |||
3537 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) | |||
3538 | .get(); | |||
3539 | if (NewStep) | |||
3540 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); | |||
3541 | } | |||
3542 | NewSteps.push_back(NewStep); | |||
3543 | } | |||
3544 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( | |||
3545 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), | |||
3546 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), | |||
3547 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), | |||
3548 | const_cast<Expr **>(Linears.data()), Linears.size(), | |||
3549 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), | |||
3550 | NewSteps.data(), NewSteps.size(), SR); | |||
3551 | ADecl->addAttr(NewAttr); | |||
3552 | return ConvertDeclToDeclGroup(ADecl); | |||
3553 | } | |||
3554 | ||||
3555 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, | |||
3556 | Stmt *AStmt, | |||
3557 | SourceLocation StartLoc, | |||
3558 | SourceLocation EndLoc) { | |||
3559 | if (!AStmt) | |||
3560 | return StmtError(); | |||
3561 | ||||
3562 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); | |||
3563 | // 1.2.2 OpenMP Language Terminology | |||
3564 | // Structured block - An executable statement with a single entry at the | |||
3565 | // top and a single exit at the bottom. | |||
3566 | // The point of exit cannot be a branch out of the structured block. | |||
3567 | // longjmp() and throw() must not violate the entry/exit criteria. | |||
3568 | CS->getCapturedDecl()->setNothrow(); | |||
3569 | ||||
3570 | getCurFunction()->setHasBranchProtectedScope(); | |||
3571 | ||||
3572 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, | |||
3573 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isCancelRegion()); | |||
3574 | } | |||
3575 | ||||
3576 | namespace { | |||
3577 | /// \brief Helper class for checking canonical form of the OpenMP loops and | |||
3578 | /// extracting iteration space of each loop in the loop nest, that will be used | |||
3579 | /// for IR generation. | |||
3580 | class OpenMPIterationSpaceChecker { | |||
3581 | /// \brief Reference to Sema. | |||
3582 | Sema &SemaRef; | |||
3583 | /// \brief A location for diagnostics (when there is no some better location). | |||
3584 | SourceLocation DefaultLoc; | |||
3585 | /// \brief A location for diagnostics (when increment is not compatible). | |||
3586 | SourceLocation ConditionLoc; | |||
3587 | /// \brief A source location for referring to loop init later. | |||
3588 | SourceRange InitSrcRange; | |||
3589 | /// \brief A source location for referring to condition later. | |||
3590 | SourceRange ConditionSrcRange; | |||
3591 | /// \brief A source location for referring to increment later. | |||
3592 | SourceRange IncrementSrcRange; | |||
3593 | /// \brief Loop variable. | |||
3594 | ValueDecl *LCDecl = nullptr; | |||
3595 | /// \brief Reference to loop variable. | |||
3596 | Expr *LCRef = nullptr; | |||
3597 | /// \brief Lower bound (initializer for the var). | |||
3598 | Expr *LB = nullptr; | |||
3599 | /// \brief Upper bound. | |||
3600 | Expr *UB = nullptr; | |||
3601 | /// \brief Loop step (increment). | |||
3602 | Expr *Step = nullptr; | |||
3603 | /// \brief This flag is true when condition is one of: | |||
3604 | /// Var < UB | |||
3605 | /// Var <= UB | |||
3606 | /// UB > Var | |||
3607 | /// UB >= Var | |||
3608 | bool TestIsLessOp = false; | |||
3609 | /// \brief This flag is true when condition is strict ( < or > ). | |||
3610 | bool TestIsStrictOp = false; | |||
3611 | /// \brief This flag is true when step is subtracted on each iteration. | |||
3612 | bool SubtractStep = false; | |||
3613 | ||||
3614 | public: | |||
3615 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) | |||
3616 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} | |||
3617 | /// \brief Check init-expr for canonical loop form and save loop counter | |||
3618 | /// variable - #Var and its initialization value - #LB. | |||
3619 | bool CheckInit(Stmt *S, bool EmitDiags = true); | |||
3620 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags | |||
3621 | /// for less/greater and for strict/non-strict comparison. | |||
3622 | bool CheckCond(Expr *S); | |||
3623 | /// \brief Check incr-expr for canonical loop form and return true if it | |||
3624 | /// does not conform, otherwise save loop step (#Step). | |||
3625 | bool CheckInc(Expr *S); | |||
3626 | /// \brief Return the loop counter variable. | |||
3627 | ValueDecl *GetLoopDecl() const { return LCDecl; } | |||
3628 | /// \brief Return the reference expression to loop counter variable. | |||
3629 | Expr *GetLoopDeclRefExpr() const { return LCRef; } | |||
3630 | /// \brief Source range of the loop init. | |||
3631 | SourceRange GetInitSrcRange() const { return InitSrcRange; } | |||
3632 | /// \brief Source range of the loop condition. | |||
3633 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } | |||
3634 | /// \brief Source range of the loop increment. | |||
3635 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } | |||
3636 | /// \brief True if the step should be subtracted. | |||
3637 | bool ShouldSubtractStep() const { return SubtractStep; } | |||
3638 | /// \brief Build the expression to calculate the number of iterations. | |||
3639 | Expr * | |||
3640 | BuildNumIterations(Scope *S, const bool LimitedType, | |||
3641 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; | |||
3642 | /// \brief Build the precondition expression for the loops. | |||
3643 | Expr *BuildPreCond(Scope *S, Expr *Cond, | |||
3644 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; | |||
3645 | /// \brief Build reference expression to the counter be used for codegen. | |||
3646 | DeclRefExpr *BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures, | |||
3647 | DSAStackTy &DSA) const; | |||
3648 | /// \brief Build reference expression to the private counter be used for | |||
3649 | /// codegen. | |||
3650 | Expr *BuildPrivateCounterVar() const; | |||
3651 | /// \brief Build initization of the counter be used for codegen. | |||
3652 | Expr *BuildCounterInit() const; | |||
3653 | /// \brief Build step of the counter be used for codegen. | |||
3654 | Expr *BuildCounterStep() const; | |||
3655 | /// \brief Return true if any expression is dependent. | |||
3656 | bool Dependent() const; | |||
3657 | ||||
3658 | private: | |||
3659 | /// \brief Check the right-hand side of an assignment in the increment | |||
3660 | /// expression. | |||
3661 | bool CheckIncRHS(Expr *RHS); | |||
3662 | /// \brief Helper to set loop counter variable and its initializer. | |||
3663 | bool SetLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); | |||
3664 | /// \brief Helper to set upper bound. | |||
3665 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, | |||
3666 | SourceLocation SL); | |||
3667 | /// \brief Helper to set loop increment. | |||
3668 | bool SetStep(Expr *NewStep, bool Subtract); | |||
3669 | }; | |||
3670 | ||||
3671 | bool OpenMPIterationSpaceChecker::Dependent() const { | |||
3672 | if (!LCDecl) { | |||
3673 | assert(!LB && !UB && !Step)((!LB && !UB && !Step) ? static_cast<void> (0) : __assert_fail ("!LB && !UB && !Step", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3673, __PRETTY_FUNCTION__)); | |||
3674 | return false; | |||
3675 | } | |||
3676 | return LCDecl->getType()->isDependentType() || | |||
3677 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || | |||
3678 | (Step && Step->isValueDependent()); | |||
3679 | } | |||
3680 | ||||
3681 | static Expr *getExprAsWritten(Expr *E) { | |||
3682 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) | |||
3683 | E = ExprTemp->getSubExpr(); | |||
3684 | ||||
3685 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) | |||
3686 | E = MTE->GetTemporaryExpr(); | |||
3687 | ||||
3688 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) | |||
3689 | E = Binder->getSubExpr(); | |||
3690 | ||||
3691 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) | |||
3692 | E = ICE->getSubExprAsWritten(); | |||
3693 | return E->IgnoreParens(); | |||
3694 | } | |||
3695 | ||||
3696 | bool OpenMPIterationSpaceChecker::SetLCDeclAndLB(ValueDecl *NewLCDecl, | |||
3697 | Expr *NewLCRefExpr, | |||
3698 | Expr *NewLB) { | |||
3699 | // State consistency checking to ensure correct usage. | |||
3700 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr &&((LCDecl == nullptr && LB == nullptr && LCRef == nullptr && UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp) ? static_cast <void> (0) : __assert_fail ("LCDecl == nullptr && LB == nullptr && LCRef == nullptr && UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3701, __PRETTY_FUNCTION__)) | |||
3701 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp)((LCDecl == nullptr && LB == nullptr && LCRef == nullptr && UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp) ? static_cast <void> (0) : __assert_fail ("LCDecl == nullptr && LB == nullptr && LCRef == nullptr && UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3701, __PRETTY_FUNCTION__)); | |||
3702 | if (!NewLCDecl || !NewLB) | |||
3703 | return true; | |||
3704 | LCDecl = getCanonicalDecl(NewLCDecl); | |||
3705 | LCRef = NewLCRefExpr; | |||
3706 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) | |||
3707 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) | |||
3708 | if ((Ctor->isCopyOrMoveConstructor() || | |||
3709 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && | |||
3710 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) | |||
3711 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); | |||
3712 | LB = NewLB; | |||
3713 | return false; | |||
3714 | } | |||
3715 | ||||
3716 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, | |||
3717 | SourceRange SR, SourceLocation SL) { | |||
3718 | // State consistency checking to ensure correct usage. | |||
3719 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr &&((LCDecl != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp) ? static_cast<void> (0) : __assert_fail ("LCDecl != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3720, __PRETTY_FUNCTION__)) | |||
3720 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp)((LCDecl != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp) ? static_cast<void> (0) : __assert_fail ("LCDecl != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3720, __PRETTY_FUNCTION__)); | |||
3721 | if (!NewUB) | |||
3722 | return true; | |||
3723 | UB = NewUB; | |||
3724 | TestIsLessOp = LessOp; | |||
3725 | TestIsStrictOp = StrictOp; | |||
3726 | ConditionSrcRange = SR; | |||
3727 | ConditionLoc = SL; | |||
3728 | return false; | |||
3729 | } | |||
3730 | ||||
3731 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { | |||
3732 | // State consistency checking to ensure correct usage. | |||
3733 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr)((LCDecl != nullptr && LB != nullptr && Step == nullptr) ? static_cast<void> (0) : __assert_fail ("LCDecl != nullptr && LB != nullptr && Step == nullptr" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 3733, __PRETTY_FUNCTION__)); | |||
3734 | if (!NewStep) | |||
3735 | return true; | |||
3736 | if (!NewStep->isValueDependent()) { | |||
3737 | // Check that the step is integer expression. | |||
3738 | SourceLocation StepLoc = NewStep->getLocStart(); | |||
3739 | ExprResult Val = | |||
3740 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); | |||
3741 | if (Val.isInvalid()) | |||
3742 | return true; | |||
3743 | NewStep = Val.get(); | |||
3744 | ||||
3745 | // OpenMP [2.6, Canonical Loop Form, Restrictions] | |||
3746 | // If test-expr is of form var relational-op b and relational-op is < or | |||
3747 | // <= then incr-expr must cause var to increase on each iteration of the | |||
3748 | // loop. If test-expr is of form var relational-op b and relational-op is | |||
3749 | // > or >= then incr-expr must cause var to decrease on each iteration of | |||
3750 | // the loop. | |||
3751 | // If test-expr is of form b relational-op var and relational-op is < or | |||
3752 | // <= then incr-expr must cause var to decrease on each iteration of the | |||
3753 | // loop. If test-expr is of form b relational-op var and relational-op is | |||
3754 | // > or >= then incr-expr must cause var to increase on each iteration of | |||
3755 | // the loop. | |||
3756 | llvm::APSInt Result; | |||
3757 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); | |||
3758 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); | |||
3759 | bool IsConstNeg = | |||
3760 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); | |||
3761 | bool IsConstPos = | |||
3762 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); | |||
3763 | bool IsConstZero = IsConstant && !Result.getBoolValue(); | |||
3764 | if (UB && (IsConstZero || | |||
3765 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) | |||
3766 | : (IsConstPos || (IsUnsigned && !Subtract))))) { | |||
3767 | SemaRef.Diag(NewStep->getExprLoc(), | |||
3768 | diag::err_omp_loop_incr_not_compatible) | |||
3769 | << LCDecl << TestIsLessOp << NewStep->getSourceRange(); | |||
3770 | SemaRef.Diag(ConditionLoc, | |||
3771 | diag::note_omp_loop_cond_requres_compatible_incr) | |||
3772 | << TestIsLessOp << ConditionSrcRange; | |||
3773 | return true; | |||
3774 | } | |||
3775 | if (TestIsLessOp == Subtract) { | |||
3776 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, | |||
3777 | NewStep).get(); | |||
3778 | Subtract = !Subtract; | |||
3779 | } | |||
3780 | } | |||
3781 | ||||
3782 | Step = NewStep; | |||
3783 | SubtractStep = Subtract; | |||
3784 | return false; | |||
3785 | } | |||
3786 | ||||
3787 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { | |||
3788 | // Check init-expr for canonical loop form and save loop counter | |||
3789 | // variable - #Var and its initialization value - #LB. | |||
3790 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: | |||
3791 | // var = lb | |||
3792 | // integer-type var = lb | |||
3793 | // random-access-iterator-type var = lb | |||
3794 | // pointer-type var = lb | |||
3795 | // | |||
3796 | if (!S) { | |||
3797 | if (EmitDiags) { | |||
3798 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); | |||
3799 | } | |||
3800 | return true; | |||
3801 | } | |||
3802 | InitSrcRange = S->getSourceRange(); | |||
3803 | if (Expr *E = dyn_cast<Expr>(S)) | |||
3804 | S = E->IgnoreParens(); | |||
3805 | if (auto BO = dyn_cast<BinaryOperator>(S)) { | |||
3806 | if (BO->getOpcode() == BO_Assign) { | |||
3807 | auto *LHS = BO->getLHS()->IgnoreParens(); | |||
3808 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { | |||
3809 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) | |||
3810 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) | |||
3811 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); | |||
3812 | return SetLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); | |||
3813 | } | |||
3814 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { | |||
3815 | if (ME->isArrow() && | |||
3816 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) | |||
3817 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); | |||
3818 | } | |||
3819 | } | |||
3820 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { | |||
3821 | if (DS->isSingleDecl()) { | |||
3822 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { | |||
3823 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { | |||
3824 | // Accept non-canonical init form here but emit ext. warning. | |||
3825 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) | |||
3826 | SemaRef.Diag(S->getLocStart(), | |||
3827 | diag::ext_omp_loop_not_canonical_init) | |||
3828 | << S->getSourceRange(); | |||
3829 | return SetLCDeclAndLB(Var, nullptr, Var->getInit()); | |||
3830 | } | |||
3831 | } | |||
3832 | } | |||
3833 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { | |||
3834 | if (CE->getOperator() == OO_Equal) { | |||
3835 | auto *LHS = CE->getArg(0); | |||
3836 | if (auto DRE = dyn_cast<DeclRefExpr>(LHS)) { | |||
3837 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) | |||
3838 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) | |||
3839 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); | |||
3840 | return SetLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); | |||
3841 | } | |||
3842 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { | |||
3843 | if (ME->isArrow() && | |||
3844 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) | |||
3845 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); | |||
3846 | } | |||
3847 | } | |||
3848 | } | |||
3849 | ||||
3850 | if (Dependent() || SemaRef.CurContext->isDependentContext()) | |||
3851 | return false; | |||
3852 | if (EmitDiags) { | |||
3853 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) | |||
3854 | << S->getSourceRange(); | |||
3855 | } | |||
3856 | return true; | |||
3857 | } | |||
3858 | ||||
3859 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the | |||
3860 | /// variable (which may be the loop variable) if possible. | |||
3861 | static const ValueDecl *GetInitLCDecl(Expr *E) { | |||
3862 | if (!E) | |||
3863 | return nullptr; | |||
3864 | E = getExprAsWritten(E); | |||
3865 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) | |||
3866 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) | |||
3867 | if ((Ctor->isCopyOrMoveConstructor() || | |||
3868 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && | |||
3869 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) | |||
3870 | E = CE->getArg(0)->IgnoreParenImpCasts(); | |||
3871 | if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { | |||
3872 | if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) { | |||
3873 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD)) | |||
3874 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) | |||
3875 | return getCanonicalDecl(ME->getMemberDecl()); | |||
3876 | return getCanonicalDecl(VD); | |||
3877 | } | |||
3878 | } | |||
3879 | if (auto *ME = dyn_cast_or_null<MemberExpr>(E)) | |||
3880 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) | |||
3881 | return getCanonicalDecl(ME->getMemberDecl()); | |||
3882 | return nullptr; | |||
3883 | } | |||
3884 | ||||
3885 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { | |||
3886 | // Check test-expr for canonical form, save upper-bound UB, flags for | |||
3887 | // less/greater and for strict/non-strict comparison. | |||
3888 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: | |||
3889 | // var relational-op b | |||
3890 | // b relational-op var | |||
3891 | // | |||
3892 | if (!S) { | |||
3893 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; | |||
3894 | return true; | |||
3895 | } | |||
3896 | S = getExprAsWritten(S); | |||
3897 | SourceLocation CondLoc = S->getLocStart(); | |||
3898 | if (auto BO = dyn_cast<BinaryOperator>(S)) { | |||
3899 | if (BO->isRelationalOp()) { | |||
3900 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) | |||
3901 | return SetUB(BO->getRHS(), | |||
3902 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), | |||
3903 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), | |||
3904 | BO->getSourceRange(), BO->getOperatorLoc()); | |||
3905 | if (GetInitLCDecl(BO->getRHS()) == LCDecl) | |||
3906 | return SetUB(BO->getLHS(), | |||
3907 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), | |||
3908 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), | |||
3909 | BO->getSourceRange(), BO->getOperatorLoc()); | |||
3910 | } | |||
3911 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { | |||
3912 | if (CE->getNumArgs() == 2) { | |||
3913 | auto Op = CE->getOperator(); | |||
3914 | switch (Op) { | |||
3915 | case OO_Greater: | |||
3916 | case OO_GreaterEqual: | |||
3917 | case OO_Less: | |||
3918 | case OO_LessEqual: | |||
3919 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) | |||
3920 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, | |||
3921 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), | |||
3922 | CE->getOperatorLoc()); | |||
3923 | if (GetInitLCDecl(CE->getArg(1)) == LCDecl) | |||
3924 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, | |||
3925 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), | |||
3926 | CE->getOperatorLoc()); | |||
3927 | break; | |||
3928 | default: | |||
3929 | break; | |||
3930 | } | |||
3931 | } | |||
3932 | } | |||
3933 | if (Dependent() || SemaRef.CurContext->isDependentContext()) | |||
3934 | return false; | |||
3935 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) | |||
3936 | << S->getSourceRange() << LCDecl; | |||
3937 | return true; | |||
3938 | } | |||
3939 | ||||
3940 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { | |||
3941 | // RHS of canonical loop form increment can be: | |||
3942 | // var + incr | |||
3943 | // incr + var | |||
3944 | // var - incr | |||
3945 | // | |||
3946 | RHS = RHS->IgnoreParenImpCasts(); | |||
3947 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { | |||
3948 | if (BO->isAdditiveOp()) { | |||
3949 | bool IsAdd = BO->getOpcode() == BO_Add; | |||
3950 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) | |||
3951 | return SetStep(BO->getRHS(), !IsAdd); | |||
3952 | if (IsAdd && GetInitLCDecl(BO->getRHS()) == LCDecl) | |||
3953 | return SetStep(BO->getLHS(), false); | |||
3954 | } | |||
3955 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { | |||
3956 | bool IsAdd = CE->getOperator() == OO_Plus; | |||
3957 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { | |||
3958 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) | |||
3959 | return SetStep(CE->getArg(1), !IsAdd); | |||
3960 | if (IsAdd && GetInitLCDecl(CE->getArg(1)) == LCDecl) | |||
3961 | return SetStep(CE->getArg(0), false); | |||
3962 | } | |||
3963 | } | |||
3964 | if (Dependent() || SemaRef.CurContext->isDependentContext()) | |||
3965 | return false; | |||
3966 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) | |||
3967 | << RHS->getSourceRange() << LCDecl; | |||
3968 | return true; | |||
3969 | } | |||
3970 | ||||
3971 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { | |||
3972 | // Check incr-expr for canonical loop form and return true if it | |||
3973 | // does not conform. | |||
3974 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: | |||
3975 | // ++var | |||
3976 | // var++ | |||
3977 | // --var | |||
3978 | // var-- | |||
3979 | // var += incr | |||
3980 | // var -= incr | |||
3981 | // var = var + incr | |||
3982 | // var = incr + var | |||
3983 | // var = var - incr | |||
3984 | // | |||
3985 | if (!S) { | |||
3986 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; | |||
3987 | return true; | |||
3988 | } | |||
3989 | IncrementSrcRange = S->getSourceRange(); | |||
3990 | S = S->IgnoreParens(); | |||
3991 | if (auto UO = dyn_cast<UnaryOperator>(S)) { | |||
3992 | if (UO->isIncrementDecrementOp() && | |||
3993 | GetInitLCDecl(UO->getSubExpr()) == LCDecl) | |||
3994 | return SetStep( | |||
3995 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), | |||
3996 | (UO->isDecrementOp() ? -1 : 1)).get(), | |||
3997 | false); | |||
3998 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { | |||
3999 | switch (BO->getOpcode()) { | |||
4000 | case BO_AddAssign: | |||
4001 | case BO_SubAssign: | |||
4002 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) | |||
4003 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); | |||
4004 | break; | |||
4005 | case BO_Assign: | |||
4006 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) | |||
4007 | return CheckIncRHS(BO->getRHS()); | |||
4008 | break; | |||
4009 | default: | |||
4010 | break; | |||
4011 | } | |||
4012 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { | |||
4013 | switch (CE->getOperator()) { | |||
4014 | case OO_PlusPlus: | |||
4015 | case OO_MinusMinus: | |||
4016 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) | |||
4017 | return SetStep( | |||
4018 | SemaRef.ActOnIntegerConstant( | |||
4019 | CE->getLocStart(), | |||
4020 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), | |||
4021 | false); | |||
4022 | break; | |||
4023 | case OO_PlusEqual: | |||
4024 | case OO_MinusEqual: | |||
4025 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) | |||
4026 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); | |||
4027 | break; | |||
4028 | case OO_Equal: | |||
4029 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) | |||
4030 | return CheckIncRHS(CE->getArg(1)); | |||
4031 | break; | |||
4032 | default: | |||
4033 | break; | |||
4034 | } | |||
4035 | } | |||
4036 | if (Dependent() || SemaRef.CurContext->isDependentContext()) | |||
4037 | return false; | |||
4038 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) | |||
4039 | << S->getSourceRange() << LCDecl; | |||
4040 | return true; | |||
4041 | } | |||
4042 | ||||
4043 | static ExprResult | |||
4044 | tryBuildCapture(Sema &SemaRef, Expr *Capture, | |||
4045 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { | |||
4046 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) | |||
4047 | return SemaRef.PerformImplicitConversion( | |||
4048 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, | |||
4049 | /*AllowExplicit=*/true); | |||
4050 | auto I = Captures.find(Capture); | |||
4051 | if (I != Captures.end()) | |||
4052 | return buildCapture(SemaRef, Capture, I->second); | |||
4053 | DeclRefExpr *Ref = nullptr; | |||
4054 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); | |||
4055 | Captures[Capture] = Ref; | |||
4056 | return Res; | |||
4057 | } | |||
4058 | ||||
4059 | /// \brief Build the expression to calculate the number of iterations. | |||
4060 | Expr *OpenMPIterationSpaceChecker::BuildNumIterations( | |||
4061 | Scope *S, const bool LimitedType, | |||
4062 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { | |||
4063 | ExprResult Diff; | |||
4064 | auto VarType = LCDecl->getType().getNonReferenceType(); | |||
4065 | if (VarType->isIntegerType() || VarType->isPointerType() || | |||
4066 | SemaRef.getLangOpts().CPlusPlus) { | |||
4067 | // Upper - Lower | |||
4068 | auto *UBExpr = TestIsLessOp ? UB : LB; | |||
4069 | auto *LBExpr = TestIsLessOp ? LB : UB; | |||
4070 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); | |||
4071 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); | |||
4072 | if (!Upper || !Lower) | |||
4073 | return nullptr; | |||
4074 | ||||
4075 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); | |||
4076 | ||||
4077 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { | |||
4078 | // BuildBinOp already emitted error, this one is to point user to upper | |||
4079 | // and lower bound, and to tell what is passed to 'operator-'. | |||
4080 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) | |||
4081 | << Upper->getSourceRange() << Lower->getSourceRange(); | |||
4082 | return nullptr; | |||
4083 | } | |||
4084 | } | |||
4085 | ||||
4086 | if (!Diff.isUsable()) | |||
4087 | return nullptr; | |||
4088 | ||||
4089 | // Upper - Lower [- 1] | |||
4090 | if (TestIsStrictOp) | |||
4091 | Diff = SemaRef.BuildBinOp( | |||
4092 | S, DefaultLoc, BO_Sub, Diff.get(), | |||
4093 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); | |||
4094 | if (!Diff.isUsable()) | |||
4095 | return nullptr; | |||
4096 | ||||
4097 | // Upper - Lower [- 1] + Step | |||
4098 | auto NewStep = tryBuildCapture(SemaRef, Step, Captures); | |||
4099 | if (!NewStep.isUsable()) | |||
4100 | return nullptr; | |||
4101 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); | |||
4102 | if (!Diff.isUsable()) | |||
4103 | return nullptr; | |||
4104 | ||||
4105 | // Parentheses (for dumping/debugging purposes only). | |||
4106 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); | |||
4107 | if (!Diff.isUsable()) | |||
4108 | return nullptr; | |||
4109 | ||||
4110 | // (Upper - Lower [- 1] + Step) / Step | |||
4111 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); | |||
4112 | if (!Diff.isUsable()) | |||
4113 | return nullptr; | |||
4114 | ||||
4115 | // OpenMP runtime requires 32-bit or 64-bit loop variables. | |||
4116 | QualType Type = Diff.get()->getType(); | |||
4117 | auto &C = SemaRef.Context; | |||
4118 | bool UseVarType = VarType->hasIntegerRepresentation() && | |||
4119 | C.getTypeSize(Type) > C.getTypeSize(VarType); | |||
4120 | if (!Type->isIntegerType() || UseVarType) { | |||
4121 | unsigned NewSize = | |||
4122 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); | |||
4123 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() | |||
4124 | : Type->hasSignedIntegerRepresentation(); | |||
4125 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); | |||
4126 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { | |||
4127 | Diff = SemaRef.PerformImplicitConversion( | |||
4128 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); | |||
4129 | if (!Diff.isUsable()) | |||
4130 | return nullptr; | |||
4131 | } | |||
4132 | } | |||
4133 | if (LimitedType) { | |||
4134 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; | |||
4135 | if (NewSize != C.getTypeSize(Type)) { | |||
4136 | if (NewSize < C.getTypeSize(Type)) { | |||
4137 | assert(NewSize == 64 && "incorrect loop var size")((NewSize == 64 && "incorrect loop var size") ? static_cast <void> (0) : __assert_fail ("NewSize == 64 && \"incorrect loop var size\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 4137, __PRETTY_FUNCTION__)); | |||
4138 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) | |||
4139 | << InitSrcRange << ConditionSrcRange; | |||
4140 | } | |||
4141 | QualType NewType = C.getIntTypeForBitwidth( | |||
4142 | NewSize, Type->hasSignedIntegerRepresentation() || | |||
4143 | C.getTypeSize(Type) < NewSize); | |||
4144 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { | |||
4145 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, | |||
4146 | Sema::AA_Converting, true); | |||
4147 | if (!Diff.isUsable()) | |||
4148 | return nullptr; | |||
4149 | } | |||
4150 | } | |||
4151 | } | |||
4152 | ||||
4153 | return Diff.get(); | |||
4154 | } | |||
4155 | ||||
4156 | Expr *OpenMPIterationSpaceChecker::BuildPreCond( | |||
4157 | Scope *S, Expr *Cond, | |||
4158 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { | |||
4159 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. | |||
4160 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); | |||
4161 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); | |||
4162 | ||||
4163 | auto NewLB = tryBuildCapture(SemaRef, LB, Captures); | |||
4164 | auto NewUB = tryBuildCapture(SemaRef, UB, Captures); | |||
4165 | if (!NewLB.isUsable() || !NewUB.isUsable()) | |||
4166 | return nullptr; | |||
4167 | ||||
4168 | auto CondExpr = SemaRef.BuildBinOp( | |||
4169 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) | |||
4170 | : (TestIsStrictOp ? BO_GT : BO_GE), | |||
4171 | NewLB.get(), NewUB.get()); | |||
4172 | if (CondExpr.isUsable()) { | |||
4173 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), | |||
4174 | SemaRef.Context.BoolTy)) | |||
4175 | CondExpr = SemaRef.PerformImplicitConversion( | |||
4176 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, | |||
4177 | /*AllowExplicit=*/true); | |||
4178 | } | |||
4179 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); | |||
4180 | // Otherwise use original loop conditon and evaluate it in runtime. | |||
4181 | return CondExpr.isUsable() ? CondExpr.get() : Cond; | |||
4182 | } | |||
4183 | ||||
4184 | /// \brief Build reference expression to the counter be used for codegen. | |||
4185 | DeclRefExpr *OpenMPIterationSpaceChecker::BuildCounterVar( | |||
4186 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures, DSAStackTy &DSA) const { | |||
4187 | auto *VD = dyn_cast<VarDecl>(LCDecl); | |||
4188 | if (!VD) { | |||
4189 | VD = SemaRef.IsOpenMPCapturedDecl(LCDecl); | |||
4190 | auto *Ref = buildDeclRefExpr( | |||
4191 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); | |||
4192 | DSAStackTy::DSAVarData Data = DSA.getTopDSA(LCDecl, /*FromParent=*/false); | |||
4193 | // If the loop control decl is explicitly marked as private, do not mark it | |||
4194 | // as captured again. | |||
4195 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) | |||
4196 | Captures.insert(std::make_pair(LCRef, Ref)); | |||
4197 | return Ref; | |||
4198 | } | |||
4199 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), | |||
4200 | DefaultLoc); | |||
4201 | } | |||
4202 | ||||
4203 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { | |||
4204 | if (LCDecl && !LCDecl->isInvalidDecl()) { | |||
4205 | auto Type = LCDecl->getType().getNonReferenceType(); | |||
4206 | auto *PrivateVar = | |||
4207 | buildVarDecl(SemaRef, DefaultLoc, Type, LCDecl->getName(), | |||
4208 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr); | |||
4209 | if (PrivateVar->isInvalidDecl()) | |||
4210 | return nullptr; | |||
4211 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); | |||
4212 | } | |||
4213 | return nullptr; | |||
4214 | } | |||
4215 | ||||
4216 | /// \brief Build initization of the counter be used for codegen. | |||
4217 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } | |||
4218 | ||||
4219 | /// \brief Build step of the counter be used for codegen. | |||
4220 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } | |||
4221 | ||||
4222 | /// \brief Iteration space of a single for loop. | |||
4223 | struct LoopIterationSpace final { | |||
4224 | /// \brief Condition of the loop. | |||
4225 | Expr *PreCond = nullptr; | |||
4226 | /// \brief This expression calculates the number of iterations in the loop. | |||
4227 | /// It is always possible to calculate it before starting the loop. | |||
4228 | Expr *NumIterations = nullptr; | |||
4229 | /// \brief The loop counter variable. | |||
4230 | Expr *CounterVar = nullptr; | |||
4231 | /// \brief Private loop counter variable. | |||
4232 | Expr *PrivateCounterVar = nullptr; | |||
4233 | /// \brief This is initializer for the initial value of #CounterVar. | |||
4234 | Expr *CounterInit = nullptr; | |||
4235 | /// \brief This is step for the #CounterVar used to generate its update: | |||
4236 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. | |||
4237 | Expr *CounterStep = nullptr; | |||
4238 | /// \brief Should step be subtracted? | |||
4239 | bool Subtract = false; | |||
4240 | /// \brief Source range of the loop init. | |||
4241 | SourceRange InitSrcRange; | |||
4242 | /// \brief Source range of the loop condition. | |||
4243 | SourceRange CondSrcRange; | |||
4244 | /// \brief Source range of the loop increment. | |||
4245 | SourceRange IncSrcRange; | |||
4246 | }; | |||
4247 | ||||
4248 | } // namespace | |||
4249 | ||||
4250 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { | |||
4251 | assert(getLangOpts().OpenMP && "OpenMP is not active.")((getLangOpts().OpenMP && "OpenMP is not active.") ? static_cast <void> (0) : __assert_fail ("getLangOpts().OpenMP && \"OpenMP is not active.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 4251, __PRETTY_FUNCTION__)); | |||
4252 | assert(Init && "Expected loop in canonical form.")((Init && "Expected loop in canonical form.") ? static_cast <void> (0) : __assert_fail ("Init && \"Expected loop in canonical form.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 4252, __PRETTY_FUNCTION__)); | |||
4253 | unsigned AssociatedLoops = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getAssociatedLoops(); | |||
4254 | if (AssociatedLoops > 0 && | |||
4255 | isOpenMPLoopDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) { | |||
4256 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); | |||
4257 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { | |||
4258 | if (auto *D = ISC.GetLoopDecl()) { | |||
4259 | auto *VD = dyn_cast<VarDecl>(D); | |||
4260 | if (!VD) { | |||
4261 | if (auto *Private = IsOpenMPCapturedDecl(D)) | |||
4262 | VD = Private; | |||
4263 | else { | |||
4264 | auto *Ref = buildCapture(*this, D, ISC.GetLoopDeclRefExpr(), | |||
4265 | /*WithInit=*/false); | |||
4266 | VD = cast<VarDecl>(Ref->getDecl()); | |||
4267 | } | |||
4268 | } | |||
4269 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addLoopControlVariable(D, VD); | |||
4270 | } | |||
4271 | } | |||
4272 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setAssociatedLoops(AssociatedLoops - 1); | |||
4273 | } | |||
4274 | } | |||
4275 | ||||
4276 | /// \brief Called on a for stmt to check and extract its iteration space | |||
4277 | /// for further processing (such as collapsing). | |||
4278 | static bool CheckOpenMPIterationSpace( | |||
4279 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, | |||
4280 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, | |||
4281 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, | |||
4282 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, | |||
4283 | LoopIterationSpace &ResultIterSpace, | |||
4284 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { | |||
4285 | // OpenMP [2.6, Canonical Loop Form] | |||
4286 | // for (init-expr; test-expr; incr-expr) structured-block | |||
4287 | auto For = dyn_cast_or_null<ForStmt>(S); | |||
4288 | if (!For) { | |||
4289 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) | |||
4290 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) | |||
4291 | << getOpenMPDirectiveName(DKind) << NestedLoopCount | |||
4292 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; | |||
4293 | if (NestedLoopCount > 1) { | |||
4294 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) | |||
4295 | SemaRef.Diag(DSA.getConstructLoc(), | |||
4296 | diag::note_omp_collapse_ordered_expr) | |||
4297 | << 2 << CollapseLoopCountExpr->getSourceRange() | |||
4298 | << OrderedLoopCountExpr->getSourceRange(); | |||
4299 | else if (CollapseLoopCountExpr) | |||
4300 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), | |||
4301 | diag::note_omp_collapse_ordered_expr) | |||
4302 | << 0 << CollapseLoopCountExpr->getSourceRange(); | |||
4303 | else | |||
4304 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), | |||
4305 | diag::note_omp_collapse_ordered_expr) | |||
4306 | << 1 << OrderedLoopCountExpr->getSourceRange(); | |||
4307 | } | |||
4308 | return true; | |||
4309 | } | |||
4310 | assert(For->getBody())((For->getBody()) ? static_cast<void> (0) : __assert_fail ("For->getBody()", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 4310, __PRETTY_FUNCTION__)); | |||
4311 | ||||
4312 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); | |||
4313 | ||||
4314 | // Check init. | |||
4315 | auto Init = For->getInit(); | |||
4316 | if (ISC.CheckInit(Init)) | |||
4317 | return true; | |||
4318 | ||||
4319 | bool HasErrors = false; | |||
4320 | ||||
4321 | // Check loop variable's type. | |||
4322 | if (auto *LCDecl = ISC.GetLoopDecl()) { | |||
4323 | auto *LoopDeclRefExpr = ISC.GetLoopDeclRefExpr(); | |||
4324 | ||||
4325 | // OpenMP [2.6, Canonical Loop Form] | |||
4326 | // Var is one of the following: | |||
4327 | // A variable of signed or unsigned integer type. | |||
4328 | // For C++, a variable of a random access iterator type. | |||
4329 | // For C, a variable of a pointer type. | |||
4330 | auto VarType = LCDecl->getType().getNonReferenceType(); | |||
4331 | if (!VarType->isDependentType() && !VarType->isIntegerType() && | |||
4332 | !VarType->isPointerType() && | |||
4333 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { | |||
4334 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) | |||
4335 | << SemaRef.getLangOpts().CPlusPlus; | |||
4336 | HasErrors = true; | |||
4337 | } | |||
4338 | ||||
4339 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in | |||
4340 | // a Construct | |||
4341 | // The loop iteration variable(s) in the associated for-loop(s) of a for or | |||
4342 | // parallel for construct is (are) private. | |||
4343 | // The loop iteration variable in the associated for-loop of a simd | |||
4344 | // construct with just one associated for-loop is linear with a | |||
4345 | // constant-linear-step that is the increment of the associated for-loop. | |||
4346 | // Exclude loop var from the list of variables with implicitly defined data | |||
4347 | // sharing attributes. | |||
4348 | VarsWithImplicitDSA.erase(LCDecl); | |||
4349 | ||||
4350 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
4351 | // in a Construct, C/C++]. | |||
4352 | // The loop iteration variable in the associated for-loop of a simd | |||
4353 | // construct with just one associated for-loop may be listed in a linear | |||
4354 | // clause with a constant-linear-step that is the increment of the | |||
4355 | // associated for-loop. | |||
4356 | // The loop iteration variable(s) in the associated for-loop(s) of a for or | |||
4357 | // parallel for construct may be listed in a private or lastprivate clause. | |||
4358 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); | |||
4359 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is | |||
4360 | // declared in the loop and it is predetermined as a private. | |||
4361 | auto PredeterminedCKind = | |||
4362 | isOpenMPSimdDirective(DKind) | |||
4363 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) | |||
4364 | : OMPC_private; | |||
4365 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && | |||
4366 | DVar.CKind != PredeterminedCKind) || | |||
4367 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || | |||
4368 | isOpenMPDistributeDirective(DKind)) && | |||
4369 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && | |||
4370 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && | |||
4371 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { | |||
4372 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) | |||
4373 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) | |||
4374 | << getOpenMPClauseName(PredeterminedCKind); | |||
4375 | if (DVar.RefExpr == nullptr) | |||
4376 | DVar.CKind = PredeterminedCKind; | |||
4377 | ReportOriginalDSA(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); | |||
4378 | HasErrors = true; | |||
4379 | } else if (LoopDeclRefExpr != nullptr) { | |||
4380 | // Make the loop iteration variable private (for worksharing constructs), | |||
4381 | // linear (for simd directives with the only one associated loop) or | |||
4382 | // lastprivate (for simd directives with several collapsed or ordered | |||
4383 | // loops). | |||
4384 | if (DVar.CKind == OMPC_unknown) | |||
4385 | DVar = DSA.hasDSA(LCDecl, isOpenMPPrivate, | |||
4386 | [](OpenMPDirectiveKind) -> bool { return true; }, | |||
4387 | /*FromParent=*/false); | |||
4388 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); | |||
4389 | } | |||
4390 | ||||
4391 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars")((isOpenMPLoopDirective(DKind) && "DSA for non-loop vars" ) ? static_cast<void> (0) : __assert_fail ("isOpenMPLoopDirective(DKind) && \"DSA for non-loop vars\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 4391, __PRETTY_FUNCTION__)); | |||
4392 | ||||
4393 | // Check test-expr. | |||
4394 | HasErrors |= ISC.CheckCond(For->getCond()); | |||
4395 | ||||
4396 | // Check incr-expr. | |||
4397 | HasErrors |= ISC.CheckInc(For->getInc()); | |||
4398 | } | |||
4399 | ||||
4400 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) | |||
4401 | return HasErrors; | |||
4402 | ||||
4403 | // Build the loop's iteration space representation. | |||
4404 | ResultIterSpace.PreCond = | |||
4405 | ISC.BuildPreCond(DSA.getCurScope(), For->getCond(), Captures); | |||
4406 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( | |||
4407 | DSA.getCurScope(), | |||
4408 | (isOpenMPWorksharingDirective(DKind) || | |||
4409 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), | |||
4410 | Captures); | |||
4411 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures, DSA); | |||
4412 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); | |||
4413 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); | |||
4414 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); | |||
4415 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); | |||
4416 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); | |||
4417 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); | |||
4418 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); | |||
4419 | ||||
4420 | HasErrors |= (ResultIterSpace.PreCond == nullptr || | |||
4421 | ResultIterSpace.NumIterations == nullptr || | |||
4422 | ResultIterSpace.CounterVar == nullptr || | |||
4423 | ResultIterSpace.PrivateCounterVar == nullptr || | |||
4424 | ResultIterSpace.CounterInit == nullptr || | |||
4425 | ResultIterSpace.CounterStep == nullptr); | |||
4426 | ||||
4427 | return HasErrors; | |||
4428 | } | |||
4429 | ||||
4430 | /// \brief Build 'VarRef = Start. | |||
4431 | static ExprResult | |||
4432 | BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, | |||
4433 | ExprResult Start, | |||
4434 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { | |||
4435 | // Build 'VarRef = Start. | |||
4436 | auto NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); | |||
4437 | if (!NewStart.isUsable()) | |||
4438 | return ExprError(); | |||
4439 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), | |||
4440 | VarRef.get()->getType())) { | |||
4441 | NewStart = SemaRef.PerformImplicitConversion( | |||
4442 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, | |||
4443 | /*AllowExplicit=*/true); | |||
4444 | if (!NewStart.isUsable()) | |||
4445 | return ExprError(); | |||
4446 | } | |||
4447 | ||||
4448 | auto Init = | |||
4449 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); | |||
4450 | return Init; | |||
4451 | } | |||
4452 | ||||
4453 | /// \brief Build 'VarRef = Start + Iter * Step'. | |||
4454 | static ExprResult | |||
4455 | BuildCounterUpdate(Sema &SemaRef, Scope *S, SourceLocation Loc, | |||
4456 | ExprResult VarRef, ExprResult Start, ExprResult Iter, | |||
4457 | ExprResult Step, bool Subtract, | |||
4458 | llvm::MapVector<Expr *, DeclRefExpr *> *Captures = nullptr) { | |||
4459 | // Add parentheses (for debugging purposes only). | |||
4460 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); | |||
4461 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || | |||
4462 | !Step.isUsable()) | |||
4463 | return ExprError(); | |||
4464 | ||||
4465 | ExprResult NewStep = Step; | |||
4466 | if (Captures) | |||
4467 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); | |||
4468 | if (NewStep.isInvalid()) | |||
4469 | return ExprError(); | |||
4470 | ExprResult Update = | |||
4471 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); | |||
4472 | if (!Update.isUsable()) | |||
4473 | return ExprError(); | |||
4474 | ||||
4475 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or | |||
4476 | // 'VarRef = Start (+|-) Iter * Step'. | |||
4477 | ExprResult NewStart = Start; | |||
4478 | if (Captures) | |||
4479 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); | |||
4480 | if (NewStart.isInvalid()) | |||
4481 | return ExprError(); | |||
4482 | ||||
4483 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. | |||
4484 | ExprResult SavedUpdate = Update; | |||
4485 | ExprResult UpdateVal; | |||
4486 | if (VarRef.get()->getType()->isOverloadableType() || | |||
4487 | NewStart.get()->getType()->isOverloadableType() || | |||
4488 | Update.get()->getType()->isOverloadableType()) { | |||
4489 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); | |||
4490 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); | |||
4491 | Update = | |||
4492 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); | |||
4493 | if (Update.isUsable()) { | |||
4494 | UpdateVal = | |||
4495 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, | |||
4496 | VarRef.get(), SavedUpdate.get()); | |||
4497 | if (UpdateVal.isUsable()) { | |||
4498 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), | |||
4499 | UpdateVal.get()); | |||
4500 | } | |||
4501 | } | |||
4502 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); | |||
4503 | } | |||
4504 | ||||
4505 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. | |||
4506 | if (!Update.isUsable() || !UpdateVal.isUsable()) { | |||
4507 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, | |||
4508 | NewStart.get(), SavedUpdate.get()); | |||
4509 | if (!Update.isUsable()) | |||
4510 | return ExprError(); | |||
4511 | ||||
4512 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), | |||
4513 | VarRef.get()->getType())) { | |||
4514 | Update = SemaRef.PerformImplicitConversion( | |||
4515 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); | |||
4516 | if (!Update.isUsable()) | |||
4517 | return ExprError(); | |||
4518 | } | |||
4519 | ||||
4520 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); | |||
4521 | } | |||
4522 | return Update; | |||
4523 | } | |||
4524 | ||||
4525 | /// \brief Convert integer expression \a E to make it have at least \a Bits | |||
4526 | /// bits. | |||
4527 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, | |||
4528 | Sema &SemaRef) { | |||
4529 | if (E == nullptr) | |||
4530 | return ExprError(); | |||
4531 | auto &C = SemaRef.Context; | |||
4532 | QualType OldType = E->getType(); | |||
4533 | unsigned HasBits = C.getTypeSize(OldType); | |||
4534 | if (HasBits >= Bits) | |||
4535 | return ExprResult(E); | |||
4536 | // OK to convert to signed, because new type has more bits than old. | |||
4537 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); | |||
4538 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, | |||
4539 | true); | |||
4540 | } | |||
4541 | ||||
4542 | /// \brief Check if the given expression \a E is a constant integer that fits | |||
4543 | /// into \a Bits bits. | |||
4544 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { | |||
4545 | if (E == nullptr) | |||
4546 | return false; | |||
4547 | llvm::APSInt Result; | |||
4548 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) | |||
4549 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); | |||
4550 | return false; | |||
4551 | } | |||
4552 | ||||
4553 | /// Build preinits statement for the given declarations. | |||
4554 | static Stmt *buildPreInits(ASTContext &Context, | |||
4555 | SmallVectorImpl<Decl *> &PreInits) { | |||
4556 | if (!PreInits.empty()) { | |||
4557 | return new (Context) DeclStmt( | |||
4558 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), | |||
4559 | SourceLocation(), SourceLocation()); | |||
4560 | } | |||
4561 | return nullptr; | |||
4562 | } | |||
4563 | ||||
4564 | /// Build preinits statement for the given declarations. | |||
4565 | static Stmt *buildPreInits(ASTContext &Context, | |||
4566 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { | |||
4567 | if (!Captures.empty()) { | |||
4568 | SmallVector<Decl *, 16> PreInits; | |||
4569 | for (auto &Pair : Captures) | |||
4570 | PreInits.push_back(Pair.second->getDecl()); | |||
4571 | return buildPreInits(Context, PreInits); | |||
4572 | } | |||
4573 | return nullptr; | |||
4574 | } | |||
4575 | ||||
4576 | /// Build postupdate expression for the given list of postupdates expressions. | |||
4577 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { | |||
4578 | Expr *PostUpdate = nullptr; | |||
4579 | if (!PostUpdates.empty()) { | |||
4580 | for (auto *E : PostUpdates) { | |||
4581 | Expr *ConvE = S.BuildCStyleCastExpr( | |||
4582 | E->getExprLoc(), | |||
4583 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), | |||
4584 | E->getExprLoc(), E) | |||
4585 | .get(); | |||
4586 | PostUpdate = PostUpdate | |||
4587 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, | |||
4588 | PostUpdate, ConvE) | |||
4589 | .get() | |||
4590 | : ConvE; | |||
4591 | } | |||
4592 | } | |||
4593 | return PostUpdate; | |||
4594 | } | |||
4595 | ||||
4596 | /// \brief Called on a for stmt to check itself and nested loops (if any). | |||
4597 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, | |||
4598 | /// number of collapsed loops otherwise. | |||
4599 | static unsigned | |||
4600 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, | |||
4601 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, | |||
4602 | DSAStackTy &DSA, | |||
4603 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, | |||
4604 | OMPLoopDirective::HelperExprs &Built) { | |||
4605 | unsigned NestedLoopCount = 1; | |||
4606 | if (CollapseLoopCountExpr) { | |||
4607 | // Found 'collapse' clause - calculate collapse number. | |||
4608 | llvm::APSInt Result; | |||
4609 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) | |||
4610 | NestedLoopCount = Result.getLimitedValue(); | |||
4611 | } | |||
4612 | if (OrderedLoopCountExpr) { | |||
4613 | // Found 'ordered' clause - calculate collapse number. | |||
4614 | llvm::APSInt Result; | |||
4615 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { | |||
4616 | if (Result.getLimitedValue() < NestedLoopCount) { | |||
4617 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), | |||
4618 | diag::err_omp_wrong_ordered_loop_count) | |||
4619 | << OrderedLoopCountExpr->getSourceRange(); | |||
4620 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), | |||
4621 | diag::note_collapse_loop_count) | |||
4622 | << CollapseLoopCountExpr->getSourceRange(); | |||
4623 | } | |||
4624 | NestedLoopCount = Result.getLimitedValue(); | |||
4625 | } | |||
4626 | } | |||
4627 | // This is helper routine for loop directives (e.g., 'for', 'simd', | |||
4628 | // 'for simd', etc.). | |||
4629 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; | |||
4630 | SmallVector<LoopIterationSpace, 4> IterSpaces; | |||
4631 | IterSpaces.resize(NestedLoopCount); | |||
4632 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); | |||
4633 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { | |||
4634 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, | |||
4635 | NestedLoopCount, CollapseLoopCountExpr, | |||
4636 | OrderedLoopCountExpr, VarsWithImplicitDSA, | |||
4637 | IterSpaces[Cnt], Captures)) | |||
4638 | return 0; | |||
4639 | // Move on to the next nested for loop, or to the loop body. | |||
4640 | // OpenMP [2.8.1, simd construct, Restrictions] | |||
4641 | // All loops associated with the construct must be perfectly nested; that | |||
4642 | // is, there must be no intervening code nor any OpenMP directive between | |||
4643 | // any two loops. | |||
4644 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); | |||
4645 | } | |||
4646 | ||||
4647 | Built.clear(/* size */ NestedLoopCount); | |||
4648 | ||||
4649 | if (SemaRef.CurContext->isDependentContext()) | |||
4650 | return NestedLoopCount; | |||
4651 | ||||
4652 | // An example of what is generated for the following code: | |||
4653 | // | |||
4654 | // #pragma omp simd collapse(2) ordered(2) | |||
4655 | // for (i = 0; i < NI; ++i) | |||
4656 | // for (k = 0; k < NK; ++k) | |||
4657 | // for (j = J0; j < NJ; j+=2) { | |||
4658 | // <loop body> | |||
4659 | // } | |||
4660 | // | |||
4661 | // We generate the code below. | |||
4662 | // Note: the loop body may be outlined in CodeGen. | |||
4663 | // Note: some counters may be C++ classes, operator- is used to find number of | |||
4664 | // iterations and operator+= to calculate counter value. | |||
4665 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 | |||
4666 | // or i64 is currently supported). | |||
4667 | // | |||
4668 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) | |||
4669 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { | |||
4670 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); | |||
4671 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; | |||
4672 | // // similar updates for vars in clauses (e.g. 'linear') | |||
4673 | // <loop body (using local i and j)> | |||
4674 | // } | |||
4675 | // i = NI; // assign final values of counters | |||
4676 | // j = NJ; | |||
4677 | // | |||
4678 | ||||
4679 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are | |||
4680 | // the iteration counts of the collapsed for loops. | |||
4681 | // Precondition tests if there is at least one iteration (all conditions are | |||
4682 | // true). | |||
4683 | auto PreCond = ExprResult(IterSpaces[0].PreCond); | |||
4684 | auto N0 = IterSpaces[0].NumIterations; | |||
4685 | ExprResult LastIteration32 = WidenIterationCount( | |||
4686 | 32 /* Bits */, SemaRef.PerformImplicitConversion( | |||
4687 | N0->IgnoreImpCasts(), N0->getType(), | |||
4688 | Sema::AA_Converting, /*AllowExplicit=*/true) | |||
4689 | .get(), | |||
4690 | SemaRef); | |||
4691 | ExprResult LastIteration64 = WidenIterationCount( | |||
4692 | 64 /* Bits */, SemaRef.PerformImplicitConversion( | |||
4693 | N0->IgnoreImpCasts(), N0->getType(), | |||
4694 | Sema::AA_Converting, /*AllowExplicit=*/true) | |||
4695 | .get(), | |||
4696 | SemaRef); | |||
4697 | ||||
4698 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) | |||
4699 | return NestedLoopCount; | |||
4700 | ||||
4701 | auto &C = SemaRef.Context; | |||
4702 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; | |||
4703 | ||||
4704 | Scope *CurScope = DSA.getCurScope(); | |||
4705 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { | |||
4706 | if (PreCond.isUsable()) { | |||
4707 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, | |||
4708 | PreCond.get(), IterSpaces[Cnt].PreCond); | |||
4709 | } | |||
4710 | auto N = IterSpaces[Cnt].NumIterations; | |||
4711 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; | |||
4712 | if (LastIteration32.isUsable()) | |||
4713 | LastIteration32 = SemaRef.BuildBinOp( | |||
4714 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), | |||
4715 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), | |||
4716 | Sema::AA_Converting, | |||
4717 | /*AllowExplicit=*/true) | |||
4718 | .get()); | |||
4719 | if (LastIteration64.isUsable()) | |||
4720 | LastIteration64 = SemaRef.BuildBinOp( | |||
4721 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), | |||
4722 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), | |||
4723 | Sema::AA_Converting, | |||
4724 | /*AllowExplicit=*/true) | |||
4725 | .get()); | |||
4726 | } | |||
4727 | ||||
4728 | // Choose either the 32-bit or 64-bit version. | |||
4729 | ExprResult LastIteration = LastIteration64; | |||
4730 | if (LastIteration32.isUsable() && | |||
4731 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && | |||
4732 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || | |||
4733 | FitsInto( | |||
4734 | 32 /* Bits */, | |||
4735 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), | |||
4736 | LastIteration64.get(), SemaRef))) | |||
4737 | LastIteration = LastIteration32; | |||
4738 | QualType VType = LastIteration.get()->getType(); | |||
4739 | QualType RealVType = VType; | |||
4740 | QualType StrideVType = VType; | |||
4741 | if (isOpenMPTaskLoopDirective(DKind)) { | |||
4742 | VType = | |||
4743 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); | |||
4744 | StrideVType = | |||
4745 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); | |||
4746 | } | |||
4747 | ||||
4748 | if (!LastIteration.isUsable()) | |||
4749 | return 0; | |||
4750 | ||||
4751 | // Save the number of iterations. | |||
4752 | ExprResult NumIterations = LastIteration; | |||
4753 | { | |||
4754 | LastIteration = SemaRef.BuildBinOp( | |||
4755 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), | |||
4756 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); | |||
4757 | if (!LastIteration.isUsable()) | |||
4758 | return 0; | |||
4759 | } | |||
4760 | ||||
4761 | // Calculate the last iteration number beforehand instead of doing this on | |||
4762 | // each iteration. Do not do this if the number of iterations may be kfold-ed. | |||
4763 | llvm::APSInt Result; | |||
4764 | bool IsConstant = | |||
4765 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); | |||
4766 | ExprResult CalcLastIteration; | |||
4767 | if (!IsConstant) { | |||
4768 | ExprResult SaveRef = | |||
4769 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); | |||
4770 | LastIteration = SaveRef; | |||
4771 | ||||
4772 | // Prepare SaveRef + 1. | |||
4773 | NumIterations = SemaRef.BuildBinOp( | |||
4774 | CurScope, SourceLocation(), BO_Add, SaveRef.get(), | |||
4775 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); | |||
4776 | if (!NumIterations.isUsable()) | |||
4777 | return 0; | |||
4778 | } | |||
4779 | ||||
4780 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); | |||
4781 | ||||
4782 | // Build variables passed into runtime, nesessary for worksharing directives. | |||
4783 | ExprResult LB, UB, IL, ST, EUB; | |||
4784 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || | |||
4785 | isOpenMPDistributeDirective(DKind)) { | |||
4786 | // Lower bound variable, initialized with zero. | |||
4787 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); | |||
4788 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); | |||
4789 | SemaRef.AddInitializerToDecl( | |||
4790 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), | |||
4791 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); | |||
4792 | ||||
4793 | // Upper bound variable, initialized with last iteration number. | |||
4794 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); | |||
4795 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); | |||
4796 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), | |||
4797 | /*DirectInit*/ false, | |||
4798 | /*TypeMayContainAuto*/ false); | |||
4799 | ||||
4800 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. | |||
4801 | // This will be used to implement clause 'lastprivate'. | |||
4802 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); | |||
4803 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); | |||
4804 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); | |||
4805 | SemaRef.AddInitializerToDecl( | |||
4806 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), | |||
4807 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); | |||
4808 | ||||
4809 | // Stride variable returned by runtime (we initialize it to 1 by default). | |||
4810 | VarDecl *STDecl = | |||
4811 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); | |||
4812 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); | |||
4813 | SemaRef.AddInitializerToDecl( | |||
4814 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), | |||
4815 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); | |||
4816 | ||||
4817 | // Build expression: UB = min(UB, LastIteration) | |||
4818 | // It is nesessary for CodeGen of directives with static scheduling. | |||
4819 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, | |||
4820 | UB.get(), LastIteration.get()); | |||
4821 | ExprResult CondOp = SemaRef.ActOnConditionalOp( | |||
4822 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); | |||
4823 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), | |||
4824 | CondOp.get()); | |||
4825 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); | |||
4826 | } | |||
4827 | ||||
4828 | // Build the iteration variable and its initialization before loop. | |||
4829 | ExprResult IV; | |||
4830 | ExprResult Init; | |||
4831 | { | |||
4832 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); | |||
4833 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); | |||
4834 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || | |||
4835 | isOpenMPTaskLoopDirective(DKind) || | |||
4836 | isOpenMPDistributeDirective(DKind)) | |||
4837 | ? LB.get() | |||
4838 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); | |||
4839 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); | |||
4840 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); | |||
4841 | } | |||
4842 | ||||
4843 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. | |||
4844 | SourceLocation CondLoc; | |||
4845 | ExprResult Cond = | |||
4846 | (isOpenMPWorksharingDirective(DKind) || | |||
4847 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) | |||
4848 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) | |||
4849 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), | |||
4850 | NumIterations.get()); | |||
4851 | ||||
4852 | // Loop increment (IV = IV + 1) | |||
4853 | SourceLocation IncLoc; | |||
4854 | ExprResult Inc = | |||
4855 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), | |||
4856 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); | |||
4857 | if (!Inc.isUsable()) | |||
4858 | return 0; | |||
4859 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); | |||
4860 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); | |||
4861 | if (!Inc.isUsable()) | |||
4862 | return 0; | |||
4863 | ||||
4864 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). | |||
4865 | // Used for directives with static scheduling. | |||
4866 | ExprResult NextLB, NextUB; | |||
4867 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || | |||
4868 | isOpenMPDistributeDirective(DKind)) { | |||
4869 | // LB + ST | |||
4870 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); | |||
4871 | if (!NextLB.isUsable()) | |||
4872 | return 0; | |||
4873 | // LB = LB + ST | |||
4874 | NextLB = | |||
4875 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); | |||
4876 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); | |||
4877 | if (!NextLB.isUsable()) | |||
4878 | return 0; | |||
4879 | // UB + ST | |||
4880 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); | |||
4881 | if (!NextUB.isUsable()) | |||
4882 | return 0; | |||
4883 | // UB = UB + ST | |||
4884 | NextUB = | |||
4885 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); | |||
4886 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); | |||
4887 | if (!NextUB.isUsable()) | |||
4888 | return 0; | |||
4889 | } | |||
4890 | ||||
4891 | // Build updates and final values of the loop counters. | |||
4892 | bool HasErrors = false; | |||
4893 | Built.Counters.resize(NestedLoopCount); | |||
4894 | Built.Inits.resize(NestedLoopCount); | |||
4895 | Built.Updates.resize(NestedLoopCount); | |||
4896 | Built.Finals.resize(NestedLoopCount); | |||
4897 | SmallVector<Expr *, 4> LoopMultipliers; | |||
4898 | { | |||
4899 | ExprResult Div; | |||
4900 | // Go from inner nested loop to outer. | |||
4901 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { | |||
4902 | LoopIterationSpace &IS = IterSpaces[Cnt]; | |||
4903 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); | |||
4904 | // Build: Iter = (IV / Div) % IS.NumIters | |||
4905 | // where Div is product of previous iterations' IS.NumIters. | |||
4906 | ExprResult Iter; | |||
4907 | if (Div.isUsable()) { | |||
4908 | Iter = | |||
4909 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); | |||
4910 | } else { | |||
4911 | Iter = IV; | |||
4912 | assert((Cnt == (int)NestedLoopCount - 1) &&(((Cnt == (int)NestedLoopCount - 1) && "unusable div expected on first iteration only" ) ? static_cast<void> (0) : __assert_fail ("(Cnt == (int)NestedLoopCount - 1) && \"unusable div expected on first iteration only\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 4913, __PRETTY_FUNCTION__)) | |||
4913 | "unusable div expected on first iteration only")(((Cnt == (int)NestedLoopCount - 1) && "unusable div expected on first iteration only" ) ? static_cast<void> (0) : __assert_fail ("(Cnt == (int)NestedLoopCount - 1) && \"unusable div expected on first iteration only\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 4913, __PRETTY_FUNCTION__)); | |||
4914 | } | |||
4915 | ||||
4916 | if (Cnt != 0 && Iter.isUsable()) | |||
4917 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), | |||
4918 | IS.NumIterations); | |||
4919 | if (!Iter.isUsable()) { | |||
4920 | HasErrors = true; | |||
4921 | break; | |||
4922 | } | |||
4923 | ||||
4924 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step | |||
4925 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); | |||
4926 | auto *CounterVar = buildDeclRefExpr(SemaRef, VD, IS.CounterVar->getType(), | |||
4927 | IS.CounterVar->getExprLoc(), | |||
4928 | /*RefersToCapture=*/true); | |||
4929 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, | |||
4930 | IS.CounterInit, Captures); | |||
4931 | if (!Init.isUsable()) { | |||
4932 | HasErrors = true; | |||
4933 | break; | |||
4934 | } | |||
4935 | ExprResult Update = BuildCounterUpdate( | |||
4936 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, | |||
4937 | IS.CounterStep, IS.Subtract, &Captures); | |||
4938 | if (!Update.isUsable()) { | |||
4939 | HasErrors = true; | |||
4940 | break; | |||
4941 | } | |||
4942 | ||||
4943 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step | |||
4944 | ExprResult Final = BuildCounterUpdate( | |||
4945 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, | |||
4946 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); | |||
4947 | if (!Final.isUsable()) { | |||
4948 | HasErrors = true; | |||
4949 | break; | |||
4950 | } | |||
4951 | ||||
4952 | // Build Div for the next iteration: Div <- Div * IS.NumIters | |||
4953 | if (Cnt != 0) { | |||
4954 | if (Div.isUnset()) | |||
4955 | Div = IS.NumIterations; | |||
4956 | else | |||
4957 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), | |||
4958 | IS.NumIterations); | |||
4959 | ||||
4960 | // Add parentheses (for debugging purposes only). | |||
4961 | if (Div.isUsable()) | |||
4962 | Div = tryBuildCapture(SemaRef, Div.get(), Captures); | |||
4963 | if (!Div.isUsable()) { | |||
4964 | HasErrors = true; | |||
4965 | break; | |||
4966 | } | |||
4967 | LoopMultipliers.push_back(Div.get()); | |||
4968 | } | |||
4969 | if (!Update.isUsable() || !Final.isUsable()) { | |||
4970 | HasErrors = true; | |||
4971 | break; | |||
4972 | } | |||
4973 | // Save results | |||
4974 | Built.Counters[Cnt] = IS.CounterVar; | |||
4975 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; | |||
4976 | Built.Inits[Cnt] = Init.get(); | |||
4977 | Built.Updates[Cnt] = Update.get(); | |||
4978 | Built.Finals[Cnt] = Final.get(); | |||
4979 | } | |||
4980 | } | |||
4981 | ||||
4982 | if (HasErrors) | |||
4983 | return 0; | |||
4984 | ||||
4985 | // Save results | |||
4986 | Built.IterationVarRef = IV.get(); | |||
4987 | Built.LastIteration = LastIteration.get(); | |||
4988 | Built.NumIterations = NumIterations.get(); | |||
4989 | Built.CalcLastIteration = | |||
4990 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); | |||
4991 | Built.PreCond = PreCond.get(); | |||
4992 | Built.PreInits = buildPreInits(C, Captures); | |||
4993 | Built.Cond = Cond.get(); | |||
4994 | Built.Init = Init.get(); | |||
4995 | Built.Inc = Inc.get(); | |||
4996 | Built.LB = LB.get(); | |||
4997 | Built.UB = UB.get(); | |||
4998 | Built.IL = IL.get(); | |||
4999 | Built.ST = ST.get(); | |||
5000 | Built.EUB = EUB.get(); | |||
5001 | Built.NLB = NextLB.get(); | |||
5002 | Built.NUB = NextUB.get(); | |||
5003 | ||||
5004 | Expr *CounterVal = SemaRef.DefaultLvalueConversion(IV.get()).get(); | |||
5005 | // Fill data for doacross depend clauses. | |||
5006 | for (auto Pair : DSA.getDoacrossDependClauses()) { | |||
5007 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_source) | |||
5008 | Pair.first->setCounterValue(CounterVal); | |||
5009 | else { | |||
5010 | if (NestedLoopCount != Pair.second.size() || | |||
5011 | NestedLoopCount != LoopMultipliers.size() + 1) { | |||
5012 | // Erroneous case - clause has some problems. | |||
5013 | Pair.first->setCounterValue(CounterVal); | |||
5014 | continue; | |||
5015 | } | |||
5016 | assert(Pair.first->getDependencyKind() == OMPC_DEPEND_sink)((Pair.first->getDependencyKind() == OMPC_DEPEND_sink) ? static_cast <void> (0) : __assert_fail ("Pair.first->getDependencyKind() == OMPC_DEPEND_sink" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5016, __PRETTY_FUNCTION__)); | |||
5017 | auto I = Pair.second.rbegin(); | |||
5018 | auto IS = IterSpaces.rbegin(); | |||
5019 | auto ILM = LoopMultipliers.rbegin(); | |||
5020 | Expr *UpCounterVal = CounterVal; | |||
5021 | Expr *Multiplier = nullptr; | |||
5022 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { | |||
5023 | if (I->first) { | |||
5024 | assert(IS->CounterStep)((IS->CounterStep) ? static_cast<void> (0) : __assert_fail ("IS->CounterStep", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5024, __PRETTY_FUNCTION__)); | |||
5025 | Expr *NormalizedOffset = | |||
5026 | SemaRef | |||
5027 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Div, | |||
5028 | I->first, IS->CounterStep) | |||
5029 | .get(); | |||
5030 | if (Multiplier) { | |||
5031 | NormalizedOffset = | |||
5032 | SemaRef | |||
5033 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Mul, | |||
5034 | NormalizedOffset, Multiplier) | |||
5035 | .get(); | |||
5036 | } | |||
5037 | assert(I->second == OO_Plus || I->second == OO_Minus)((I->second == OO_Plus || I->second == OO_Minus) ? static_cast <void> (0) : __assert_fail ("I->second == OO_Plus || I->second == OO_Minus" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5037, __PRETTY_FUNCTION__)); | |||
5038 | BinaryOperatorKind BOK = (I->second == OO_Plus) ? BO_Add : BO_Sub; | |||
5039 | UpCounterVal = | |||
5040 | SemaRef.BuildBinOp(CurScope, I->first->getExprLoc(), BOK, | |||
5041 | UpCounterVal, NormalizedOffset).get(); | |||
5042 | } | |||
5043 | Multiplier = *ILM; | |||
5044 | ++I; | |||
5045 | ++IS; | |||
5046 | ++ILM; | |||
5047 | } | |||
5048 | Pair.first->setCounterValue(UpCounterVal); | |||
5049 | } | |||
5050 | } | |||
5051 | ||||
5052 | return NestedLoopCount; | |||
5053 | } | |||
5054 | ||||
5055 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { | |||
5056 | auto CollapseClauses = | |||
5057 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); | |||
5058 | if (CollapseClauses.begin() != CollapseClauses.end()) | |||
5059 | return (*CollapseClauses.begin())->getNumForLoops(); | |||
5060 | return nullptr; | |||
5061 | } | |||
5062 | ||||
5063 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { | |||
5064 | auto OrderedClauses = | |||
5065 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); | |||
5066 | if (OrderedClauses.begin() != OrderedClauses.end()) | |||
5067 | return (*OrderedClauses.begin())->getNumForLoops(); | |||
5068 | return nullptr; | |||
5069 | } | |||
5070 | ||||
5071 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, | |||
5072 | const Expr *Safelen) { | |||
5073 | llvm::APSInt SimdlenRes, SafelenRes; | |||
5074 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || | |||
5075 | Simdlen->isInstantiationDependent() || | |||
5076 | Simdlen->containsUnexpandedParameterPack()) | |||
5077 | return false; | |||
5078 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || | |||
5079 | Safelen->isInstantiationDependent() || | |||
5080 | Safelen->containsUnexpandedParameterPack()) | |||
5081 | return false; | |||
5082 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); | |||
5083 | Safelen->EvaluateAsInt(SafelenRes, S.Context); | |||
5084 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] | |||
5085 | // If both simdlen and safelen clauses are specified, the value of the simdlen | |||
5086 | // parameter must be less than or equal to the value of the safelen parameter. | |||
5087 | if (SimdlenRes > SafelenRes) { | |||
5088 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) | |||
5089 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); | |||
5090 | return true; | |||
5091 | } | |||
5092 | return false; | |||
5093 | } | |||
5094 | ||||
5095 | StmtResult Sema::ActOnOpenMPSimdDirective( | |||
5096 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, | |||
5097 | SourceLocation EndLoc, | |||
5098 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { | |||
5099 | if (!AStmt) | |||
5100 | return StmtError(); | |||
5101 | ||||
5102 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5102, __PRETTY_FUNCTION__)); | |||
5103 | OMPLoopDirective::HelperExprs B; | |||
5104 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will | |||
5105 | // define the nested loops number. | |||
5106 | unsigned NestedLoopCount = CheckOpenMPLoop( | |||
5107 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), | |||
5108 | AStmt, *this, *DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), VarsWithImplicitDSA, B); | |||
5109 | if (NestedLoopCount == 0) | |||
5110 | return StmtError(); | |||
5111 | ||||
5112 | assert((CurContext->isDependentContext() || B.builtAll()) &&(((CurContext->isDependentContext() || B.builtAll()) && "omp simd loop exprs were not built") ? static_cast<void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp simd loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5113, __PRETTY_FUNCTION__)) | |||
5113 | "omp simd loop exprs were not built")(((CurContext->isDependentContext() || B.builtAll()) && "omp simd loop exprs were not built") ? static_cast<void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp simd loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5113, __PRETTY_FUNCTION__)); | |||
5114 | ||||
5115 | if (!CurContext->isDependentContext()) { | |||
5116 | // Finalize the clauses that need pre-built expressions for CodeGen. | |||
5117 | for (auto C : Clauses) { | |||
5118 | if (auto LC = dyn_cast<OMPLinearClause>(C)) | |||
5119 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), | |||
5120 | B.NumIterations, *this, CurScope, | |||
5121 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ))) | |||
5122 | return StmtError(); | |||
5123 | } | |||
5124 | } | |||
5125 | ||||
5126 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] | |||
5127 | // If both simdlen and safelen clauses are specified, the value of the simdlen | |||
5128 | // parameter must be less than or equal to the value of the safelen parameter. | |||
5129 | OMPSafelenClause *Safelen = nullptr; | |||
5130 | OMPSimdlenClause *Simdlen = nullptr; | |||
5131 | for (auto *Clause : Clauses) { | |||
5132 | if (Clause->getClauseKind() == OMPC_safelen) | |||
5133 | Safelen = cast<OMPSafelenClause>(Clause); | |||
5134 | else if (Clause->getClauseKind() == OMPC_simdlen) | |||
5135 | Simdlen = cast<OMPSimdlenClause>(Clause); | |||
5136 | if (Safelen && Simdlen) | |||
5137 | break; | |||
5138 | } | |||
5139 | if (Simdlen && Safelen && | |||
5140 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), | |||
5141 | Safelen->getSafelen())) | |||
5142 | return StmtError(); | |||
5143 | ||||
5144 | getCurFunction()->setHasBranchProtectedScope(); | |||
5145 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, | |||
5146 | Clauses, AStmt, B); | |||
5147 | } | |||
5148 | ||||
5149 | StmtResult Sema::ActOnOpenMPForDirective( | |||
5150 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, | |||
5151 | SourceLocation EndLoc, | |||
5152 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { | |||
5153 | if (!AStmt) | |||
5154 | return StmtError(); | |||
5155 | ||||
5156 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5156, __PRETTY_FUNCTION__)); | |||
5157 | OMPLoopDirective::HelperExprs B; | |||
5158 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will | |||
5159 | // define the nested loops number. | |||
5160 | unsigned NestedLoopCount = CheckOpenMPLoop( | |||
5161 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), | |||
5162 | AStmt, *this, *DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), VarsWithImplicitDSA, B); | |||
5163 | if (NestedLoopCount == 0) | |||
5164 | return StmtError(); | |||
5165 | ||||
5166 | assert((CurContext->isDependentContext() || B.builtAll()) &&(((CurContext->isDependentContext() || B.builtAll()) && "omp for loop exprs were not built") ? static_cast<void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp for loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5167, __PRETTY_FUNCTION__)) | |||
5167 | "omp for loop exprs were not built")(((CurContext->isDependentContext() || B.builtAll()) && "omp for loop exprs were not built") ? static_cast<void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp for loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5167, __PRETTY_FUNCTION__)); | |||
5168 | ||||
5169 | if (!CurContext->isDependentContext()) { | |||
5170 | // Finalize the clauses that need pre-built expressions for CodeGen. | |||
5171 | for (auto C : Clauses) { | |||
5172 | if (auto LC = dyn_cast<OMPLinearClause>(C)) | |||
5173 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), | |||
5174 | B.NumIterations, *this, CurScope, | |||
5175 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ))) | |||
5176 | return StmtError(); | |||
5177 | } | |||
5178 | } | |||
5179 | ||||
5180 | getCurFunction()->setHasBranchProtectedScope(); | |||
5181 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, | |||
5182 | Clauses, AStmt, B, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isCancelRegion()); | |||
5183 | } | |||
5184 | ||||
5185 | StmtResult Sema::ActOnOpenMPForSimdDirective( | |||
5186 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, | |||
5187 | SourceLocation EndLoc, | |||
5188 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { | |||
5189 | if (!AStmt) | |||
5190 | return StmtError(); | |||
5191 | ||||
5192 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5192, __PRETTY_FUNCTION__)); | |||
5193 | OMPLoopDirective::HelperExprs B; | |||
5194 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will | |||
5195 | // define the nested loops number. | |||
5196 | unsigned NestedLoopCount = | |||
5197 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), | |||
5198 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), | |||
5199 | VarsWithImplicitDSA, B); | |||
5200 | if (NestedLoopCount == 0) | |||
5201 | return StmtError(); | |||
5202 | ||||
5203 | assert((CurContext->isDependentContext() || B.builtAll()) &&(((CurContext->isDependentContext() || B.builtAll()) && "omp for simd loop exprs were not built") ? static_cast<void > (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp for simd loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5204, __PRETTY_FUNCTION__)) | |||
5204 | "omp for simd loop exprs were not built")(((CurContext->isDependentContext() || B.builtAll()) && "omp for simd loop exprs were not built") ? static_cast<void > (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp for simd loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5204, __PRETTY_FUNCTION__)); | |||
5205 | ||||
5206 | if (!CurContext->isDependentContext()) { | |||
5207 | // Finalize the clauses that need pre-built expressions for CodeGen. | |||
5208 | for (auto C : Clauses) { | |||
5209 | if (auto LC = dyn_cast<OMPLinearClause>(C)) | |||
5210 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), | |||
5211 | B.NumIterations, *this, CurScope, | |||
5212 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ))) | |||
5213 | return StmtError(); | |||
5214 | } | |||
5215 | } | |||
5216 | ||||
5217 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] | |||
5218 | // If both simdlen and safelen clauses are specified, the value of the simdlen | |||
5219 | // parameter must be less than or equal to the value of the safelen parameter. | |||
5220 | OMPSafelenClause *Safelen = nullptr; | |||
5221 | OMPSimdlenClause *Simdlen = nullptr; | |||
5222 | for (auto *Clause : Clauses) { | |||
5223 | if (Clause->getClauseKind() == OMPC_safelen) | |||
5224 | Safelen = cast<OMPSafelenClause>(Clause); | |||
5225 | else if (Clause->getClauseKind() == OMPC_simdlen) | |||
5226 | Simdlen = cast<OMPSimdlenClause>(Clause); | |||
5227 | if (Safelen && Simdlen) | |||
5228 | break; | |||
5229 | } | |||
5230 | if (Simdlen && Safelen && | |||
5231 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), | |||
5232 | Safelen->getSafelen())) | |||
5233 | return StmtError(); | |||
5234 | ||||
5235 | getCurFunction()->setHasBranchProtectedScope(); | |||
5236 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, | |||
5237 | Clauses, AStmt, B); | |||
5238 | } | |||
5239 | ||||
5240 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, | |||
5241 | Stmt *AStmt, | |||
5242 | SourceLocation StartLoc, | |||
5243 | SourceLocation EndLoc) { | |||
5244 | if (!AStmt) | |||
5245 | return StmtError(); | |||
5246 | ||||
5247 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5247, __PRETTY_FUNCTION__)); | |||
5248 | auto BaseStmt = AStmt; | |||
5249 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) | |||
5250 | BaseStmt = CS->getCapturedStmt(); | |||
5251 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { | |||
5252 | auto S = C->children(); | |||
5253 | if (S.begin() == S.end()) | |||
5254 | return StmtError(); | |||
5255 | // All associated statements must be '#pragma omp section' except for | |||
5256 | // the first one. | |||
5257 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { | |||
5258 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { | |||
5259 | if (SectionStmt) | |||
5260 | Diag(SectionStmt->getLocStart(), | |||
5261 | diag::err_omp_sections_substmt_not_section); | |||
5262 | return StmtError(); | |||
5263 | } | |||
5264 | cast<OMPSectionDirective>(SectionStmt) | |||
5265 | ->setHasCancel(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isCancelRegion()); | |||
5266 | } | |||
5267 | } else { | |||
5268 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); | |||
5269 | return StmtError(); | |||
5270 | } | |||
5271 | ||||
5272 | getCurFunction()->setHasBranchProtectedScope(); | |||
5273 | ||||
5274 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, | |||
5275 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isCancelRegion()); | |||
5276 | } | |||
5277 | ||||
5278 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, | |||
5279 | SourceLocation StartLoc, | |||
5280 | SourceLocation EndLoc) { | |||
5281 | if (!AStmt) | |||
5282 | return StmtError(); | |||
5283 | ||||
5284 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5284, __PRETTY_FUNCTION__)); | |||
5285 | ||||
5286 | getCurFunction()->setHasBranchProtectedScope(); | |||
5287 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setParentCancelRegion(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isCancelRegion()); | |||
5288 | ||||
5289 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, | |||
5290 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isCancelRegion()); | |||
5291 | } | |||
5292 | ||||
5293 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, | |||
5294 | Stmt *AStmt, | |||
5295 | SourceLocation StartLoc, | |||
5296 | SourceLocation EndLoc) { | |||
5297 | if (!AStmt) | |||
5298 | return StmtError(); | |||
5299 | ||||
5300 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5300, __PRETTY_FUNCTION__)); | |||
5301 | ||||
5302 | getCurFunction()->setHasBranchProtectedScope(); | |||
5303 | ||||
5304 | // OpenMP [2.7.3, single Construct, Restrictions] | |||
5305 | // The copyprivate clause must not be used with the nowait clause. | |||
5306 | OMPClause *Nowait = nullptr; | |||
5307 | OMPClause *Copyprivate = nullptr; | |||
5308 | for (auto *Clause : Clauses) { | |||
5309 | if (Clause->getClauseKind() == OMPC_nowait) | |||
5310 | Nowait = Clause; | |||
5311 | else if (Clause->getClauseKind() == OMPC_copyprivate) | |||
5312 | Copyprivate = Clause; | |||
5313 | if (Copyprivate && Nowait) { | |||
5314 | Diag(Copyprivate->getLocStart(), | |||
5315 | diag::err_omp_single_copyprivate_with_nowait); | |||
5316 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); | |||
5317 | return StmtError(); | |||
5318 | } | |||
5319 | } | |||
5320 | ||||
5321 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); | |||
5322 | } | |||
5323 | ||||
5324 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, | |||
5325 | SourceLocation StartLoc, | |||
5326 | SourceLocation EndLoc) { | |||
5327 | if (!AStmt) | |||
5328 | return StmtError(); | |||
5329 | ||||
5330 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5330, __PRETTY_FUNCTION__)); | |||
5331 | ||||
5332 | getCurFunction()->setHasBranchProtectedScope(); | |||
5333 | ||||
5334 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); | |||
5335 | } | |||
5336 | ||||
5337 | StmtResult Sema::ActOnOpenMPCriticalDirective( | |||
5338 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, | |||
5339 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { | |||
5340 | if (!AStmt) | |||
5341 | return StmtError(); | |||
5342 | ||||
5343 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5343, __PRETTY_FUNCTION__)); | |||
5344 | ||||
5345 | bool ErrorFound = false; | |||
5346 | llvm::APSInt Hint; | |||
5347 | SourceLocation HintLoc; | |||
5348 | bool DependentHint = false; | |||
5349 | for (auto *C : Clauses) { | |||
5350 | if (C->getClauseKind() == OMPC_hint) { | |||
5351 | if (!DirName.getName()) { | |||
5352 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); | |||
5353 | ErrorFound = true; | |||
5354 | } | |||
5355 | Expr *E = cast<OMPHintClause>(C)->getHint(); | |||
5356 | if (E->isTypeDependent() || E->isValueDependent() || | |||
5357 | E->isInstantiationDependent()) | |||
5358 | DependentHint = true; | |||
5359 | else { | |||
5360 | Hint = E->EvaluateKnownConstInt(Context); | |||
5361 | HintLoc = C->getLocStart(); | |||
5362 | } | |||
5363 | } | |||
5364 | } | |||
5365 | if (ErrorFound) | |||
5366 | return StmtError(); | |||
5367 | auto Pair = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCriticalWithHint(DirName); | |||
5368 | if (Pair.first && DirName.getName() && !DependentHint) { | |||
5369 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { | |||
5370 | Diag(StartLoc, diag::err_omp_critical_with_hint); | |||
5371 | if (HintLoc.isValid()) { | |||
5372 | Diag(HintLoc, diag::note_omp_critical_hint_here) | |||
5373 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); | |||
5374 | } else | |||
5375 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; | |||
5376 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { | |||
5377 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) | |||
5378 | << 1 | |||
5379 | << C->getHint()->EvaluateKnownConstInt(Context).toString( | |||
5380 | /*Radix=*/10, /*Signed=*/false); | |||
5381 | } else | |||
5382 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; | |||
5383 | } | |||
5384 | } | |||
5385 | ||||
5386 | getCurFunction()->setHasBranchProtectedScope(); | |||
5387 | ||||
5388 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, | |||
5389 | Clauses, AStmt); | |||
5390 | if (!Pair.first && DirName.getName() && !DependentHint) | |||
5391 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addCriticalWithHint(Dir, Hint); | |||
5392 | return Dir; | |||
5393 | } | |||
5394 | ||||
5395 | StmtResult Sema::ActOnOpenMPParallelForDirective( | |||
5396 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, | |||
5397 | SourceLocation EndLoc, | |||
5398 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { | |||
5399 | if (!AStmt) | |||
5400 | return StmtError(); | |||
5401 | ||||
5402 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); | |||
5403 | // 1.2.2 OpenMP Language Terminology | |||
5404 | // Structured block - An executable statement with a single entry at the | |||
5405 | // top and a single exit at the bottom. | |||
5406 | // The point of exit cannot be a branch out of the structured block. | |||
5407 | // longjmp() and throw() must not violate the entry/exit criteria. | |||
5408 | CS->getCapturedDecl()->setNothrow(); | |||
5409 | ||||
5410 | OMPLoopDirective::HelperExprs B; | |||
5411 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will | |||
5412 | // define the nested loops number. | |||
5413 | unsigned NestedLoopCount = | |||
5414 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), | |||
5415 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), | |||
5416 | VarsWithImplicitDSA, B); | |||
5417 | if (NestedLoopCount == 0) | |||
5418 | return StmtError(); | |||
5419 | ||||
5420 | assert((CurContext->isDependentContext() || B.builtAll()) &&(((CurContext->isDependentContext() || B.builtAll()) && "omp parallel for loop exprs were not built") ? static_cast< void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp parallel for loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5421, __PRETTY_FUNCTION__)) | |||
5421 | "omp parallel for loop exprs were not built")(((CurContext->isDependentContext() || B.builtAll()) && "omp parallel for loop exprs were not built") ? static_cast< void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp parallel for loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5421, __PRETTY_FUNCTION__)); | |||
5422 | ||||
5423 | if (!CurContext->isDependentContext()) { | |||
5424 | // Finalize the clauses that need pre-built expressions for CodeGen. | |||
5425 | for (auto C : Clauses) { | |||
5426 | if (auto LC = dyn_cast<OMPLinearClause>(C)) | |||
5427 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), | |||
5428 | B.NumIterations, *this, CurScope, | |||
5429 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ))) | |||
5430 | return StmtError(); | |||
5431 | } | |||
5432 | } | |||
5433 | ||||
5434 | getCurFunction()->setHasBranchProtectedScope(); | |||
5435 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, | |||
5436 | NestedLoopCount, Clauses, AStmt, B, | |||
5437 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isCancelRegion()); | |||
5438 | } | |||
5439 | ||||
5440 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( | |||
5441 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, | |||
5442 | SourceLocation EndLoc, | |||
5443 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { | |||
5444 | if (!AStmt) | |||
5445 | return StmtError(); | |||
5446 | ||||
5447 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); | |||
5448 | // 1.2.2 OpenMP Language Terminology | |||
5449 | // Structured block - An executable statement with a single entry at the | |||
5450 | // top and a single exit at the bottom. | |||
5451 | // The point of exit cannot be a branch out of the structured block. | |||
5452 | // longjmp() and throw() must not violate the entry/exit criteria. | |||
5453 | CS->getCapturedDecl()->setNothrow(); | |||
5454 | ||||
5455 | OMPLoopDirective::HelperExprs B; | |||
5456 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will | |||
5457 | // define the nested loops number. | |||
5458 | unsigned NestedLoopCount = | |||
5459 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), | |||
5460 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), | |||
5461 | VarsWithImplicitDSA, B); | |||
5462 | if (NestedLoopCount == 0) | |||
5463 | return StmtError(); | |||
5464 | ||||
5465 | if (!CurContext->isDependentContext()) { | |||
5466 | // Finalize the clauses that need pre-built expressions for CodeGen. | |||
5467 | for (auto C : Clauses) { | |||
5468 | if (auto LC = dyn_cast<OMPLinearClause>(C)) | |||
5469 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), | |||
5470 | B.NumIterations, *this, CurScope, | |||
5471 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ))) | |||
5472 | return StmtError(); | |||
5473 | } | |||
5474 | } | |||
5475 | ||||
5476 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] | |||
5477 | // If both simdlen and safelen clauses are specified, the value of the simdlen | |||
5478 | // parameter must be less than or equal to the value of the safelen parameter. | |||
5479 | OMPSafelenClause *Safelen = nullptr; | |||
5480 | OMPSimdlenClause *Simdlen = nullptr; | |||
5481 | for (auto *Clause : Clauses) { | |||
5482 | if (Clause->getClauseKind() == OMPC_safelen) | |||
5483 | Safelen = cast<OMPSafelenClause>(Clause); | |||
5484 | else if (Clause->getClauseKind() == OMPC_simdlen) | |||
5485 | Simdlen = cast<OMPSimdlenClause>(Clause); | |||
5486 | if (Safelen && Simdlen) | |||
5487 | break; | |||
5488 | } | |||
5489 | if (Simdlen && Safelen && | |||
5490 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), | |||
5491 | Safelen->getSafelen())) | |||
5492 | return StmtError(); | |||
5493 | ||||
5494 | getCurFunction()->setHasBranchProtectedScope(); | |||
5495 | return OMPParallelForSimdDirective::Create( | |||
5496 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); | |||
5497 | } | |||
5498 | ||||
5499 | StmtResult | |||
5500 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, | |||
5501 | Stmt *AStmt, SourceLocation StartLoc, | |||
5502 | SourceLocation EndLoc) { | |||
5503 | if (!AStmt) | |||
5504 | return StmtError(); | |||
5505 | ||||
5506 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5506, __PRETTY_FUNCTION__)); | |||
5507 | auto BaseStmt = AStmt; | |||
5508 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) | |||
5509 | BaseStmt = CS->getCapturedStmt(); | |||
5510 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { | |||
5511 | auto S = C->children(); | |||
5512 | if (S.begin() == S.end()) | |||
5513 | return StmtError(); | |||
5514 | // All associated statements must be '#pragma omp section' except for | |||
5515 | // the first one. | |||
5516 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { | |||
5517 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { | |||
5518 | if (SectionStmt) | |||
5519 | Diag(SectionStmt->getLocStart(), | |||
5520 | diag::err_omp_parallel_sections_substmt_not_section); | |||
5521 | return StmtError(); | |||
5522 | } | |||
5523 | cast<OMPSectionDirective>(SectionStmt) | |||
5524 | ->setHasCancel(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isCancelRegion()); | |||
5525 | } | |||
5526 | } else { | |||
5527 | Diag(AStmt->getLocStart(), | |||
5528 | diag::err_omp_parallel_sections_not_compound_stmt); | |||
5529 | return StmtError(); | |||
5530 | } | |||
5531 | ||||
5532 | getCurFunction()->setHasBranchProtectedScope(); | |||
5533 | ||||
5534 | return OMPParallelSectionsDirective::Create( | |||
5535 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isCancelRegion()); | |||
5536 | } | |||
5537 | ||||
5538 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, | |||
5539 | Stmt *AStmt, SourceLocation StartLoc, | |||
5540 | SourceLocation EndLoc) { | |||
5541 | if (!AStmt) | |||
5542 | return StmtError(); | |||
5543 | ||||
5544 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); | |||
5545 | // 1.2.2 OpenMP Language Terminology | |||
5546 | // Structured block - An executable statement with a single entry at the | |||
5547 | // top and a single exit at the bottom. | |||
5548 | // The point of exit cannot be a branch out of the structured block. | |||
5549 | // longjmp() and throw() must not violate the entry/exit criteria. | |||
5550 | CS->getCapturedDecl()->setNothrow(); | |||
5551 | ||||
5552 | getCurFunction()->setHasBranchProtectedScope(); | |||
5553 | ||||
5554 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, | |||
5555 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isCancelRegion()); | |||
5556 | } | |||
5557 | ||||
5558 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, | |||
5559 | SourceLocation EndLoc) { | |||
5560 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); | |||
5561 | } | |||
5562 | ||||
5563 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, | |||
5564 | SourceLocation EndLoc) { | |||
5565 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); | |||
5566 | } | |||
5567 | ||||
5568 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, | |||
5569 | SourceLocation EndLoc) { | |||
5570 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); | |||
5571 | } | |||
5572 | ||||
5573 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, | |||
5574 | SourceLocation StartLoc, | |||
5575 | SourceLocation EndLoc) { | |||
5576 | if (!AStmt) | |||
5577 | return StmtError(); | |||
5578 | ||||
5579 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5579, __PRETTY_FUNCTION__)); | |||
5580 | ||||
5581 | getCurFunction()->setHasBranchProtectedScope(); | |||
5582 | ||||
5583 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); | |||
5584 | } | |||
5585 | ||||
5586 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, | |||
5587 | SourceLocation StartLoc, | |||
5588 | SourceLocation EndLoc) { | |||
5589 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive")((Clauses.size() <= 1 && "Extra clauses in flush directive" ) ? static_cast<void> (0) : __assert_fail ("Clauses.size() <= 1 && \"Extra clauses in flush directive\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5589, __PRETTY_FUNCTION__)); | |||
5590 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); | |||
5591 | } | |||
5592 | ||||
5593 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, | |||
5594 | Stmt *AStmt, | |||
5595 | SourceLocation StartLoc, | |||
5596 | SourceLocation EndLoc) { | |||
5597 | OMPClause *DependFound = nullptr; | |||
5598 | OMPClause *DependSourceClause = nullptr; | |||
5599 | OMPClause *DependSinkClause = nullptr; | |||
5600 | bool ErrorFound = false; | |||
5601 | OMPThreadsClause *TC = nullptr; | |||
5602 | OMPSIMDClause *SC = nullptr; | |||
5603 | for (auto *C : Clauses) { | |||
5604 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { | |||
5605 | DependFound = C; | |||
5606 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { | |||
5607 | if (DependSourceClause) { | |||
5608 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) | |||
5609 | << getOpenMPDirectiveName(OMPD_ordered) | |||
5610 | << getOpenMPClauseName(OMPC_depend) << 2; | |||
5611 | ErrorFound = true; | |||
5612 | } else | |||
5613 | DependSourceClause = C; | |||
5614 | if (DependSinkClause) { | |||
5615 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) | |||
5616 | << 0; | |||
5617 | ErrorFound = true; | |||
5618 | } | |||
5619 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { | |||
5620 | if (DependSourceClause) { | |||
5621 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) | |||
5622 | << 1; | |||
5623 | ErrorFound = true; | |||
5624 | } | |||
5625 | DependSinkClause = C; | |||
5626 | } | |||
5627 | } else if (C->getClauseKind() == OMPC_threads) | |||
5628 | TC = cast<OMPThreadsClause>(C); | |||
5629 | else if (C->getClauseKind() == OMPC_simd) | |||
5630 | SC = cast<OMPSIMDClause>(C); | |||
5631 | } | |||
5632 | if (!ErrorFound && !SC && | |||
5633 | isOpenMPSimdDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getParentDirective())) { | |||
5634 | // OpenMP [2.8.1,simd Construct, Restrictions] | |||
5635 | // An ordered construct with the simd clause is the only OpenMP construct | |||
5636 | // that can appear in the simd region. | |||
5637 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); | |||
5638 | ErrorFound = true; | |||
5639 | } else if (DependFound && (TC || SC)) { | |||
5640 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) | |||
5641 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); | |||
5642 | ErrorFound = true; | |||
5643 | } else if (DependFound && !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getParentOrderedRegionParam()) { | |||
5644 | Diag(DependFound->getLocStart(), | |||
5645 | diag::err_omp_ordered_directive_without_param); | |||
5646 | ErrorFound = true; | |||
5647 | } else if (TC || Clauses.empty()) { | |||
5648 | if (auto *Param = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getParentOrderedRegionParam()) { | |||
5649 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; | |||
5650 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) | |||
5651 | << (TC != nullptr); | |||
5652 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); | |||
5653 | ErrorFound = true; | |||
5654 | } | |||
5655 | } | |||
5656 | if ((!AStmt && !DependFound) || ErrorFound) | |||
5657 | return StmtError(); | |||
5658 | ||||
5659 | if (AStmt) { | |||
5660 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 5660, __PRETTY_FUNCTION__)); | |||
5661 | ||||
5662 | getCurFunction()->setHasBranchProtectedScope(); | |||
5663 | } | |||
5664 | ||||
5665 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); | |||
5666 | } | |||
5667 | ||||
5668 | namespace { | |||
5669 | /// \brief Helper class for checking expression in 'omp atomic [update]' | |||
5670 | /// construct. | |||
5671 | class OpenMPAtomicUpdateChecker { | |||
5672 | /// \brief Error results for atomic update expressions. | |||
5673 | enum ExprAnalysisErrorCode { | |||
5674 | /// \brief A statement is not an expression statement. | |||
5675 | NotAnExpression, | |||
5676 | /// \brief Expression is not builtin binary or unary operation. | |||
5677 | NotABinaryOrUnaryExpression, | |||
5678 | /// \brief Unary operation is not post-/pre- increment/decrement operation. | |||
5679 | NotAnUnaryIncDecExpression, | |||
5680 | /// \brief An expression is not of scalar type. | |||
5681 | NotAScalarType, | |||
5682 | /// \brief A binary operation is not an assignment operation. | |||
5683 | NotAnAssignmentOp, | |||
5684 | /// \brief RHS part of the binary operation is not a binary expression. | |||
5685 | NotABinaryExpression, | |||
5686 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary | |||
5687 | /// expression. | |||
5688 | NotABinaryOperator, | |||
5689 | /// \brief RHS binary operation does not have reference to the updated LHS | |||
5690 | /// part. | |||
5691 | NotAnUpdateExpression, | |||
5692 | /// \brief No errors is found. | |||
5693 | NoError | |||
5694 | }; | |||
5695 | /// \brief Reference to Sema. | |||
5696 | Sema &SemaRef; | |||
5697 | /// \brief A location for note diagnostics (when error is found). | |||
5698 | SourceLocation NoteLoc; | |||
5699 | /// \brief 'x' lvalue part of the source atomic expression. | |||
5700 | Expr *X; | |||
5701 | /// \brief 'expr' rvalue part of the source atomic expression. | |||
5702 | Expr *E; | |||
5703 | /// \brief Helper expression of the form | |||
5704 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or | |||
5705 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. | |||
5706 | Expr *UpdateExpr; | |||
5707 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is | |||
5708 | /// important for non-associative operations. | |||
5709 | bool IsXLHSInRHSPart; | |||
5710 | BinaryOperatorKind Op; | |||
5711 | SourceLocation OpLoc; | |||
5712 | /// \brief true if the source expression is a postfix unary operation, false | |||
5713 | /// if it is a prefix unary operation. | |||
5714 | bool IsPostfixUpdate; | |||
5715 | ||||
5716 | public: | |||
5717 | OpenMPAtomicUpdateChecker(Sema &SemaRef) | |||
5718 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), | |||
5719 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} | |||
5720 | /// \brief Check specified statement that it is suitable for 'atomic update' | |||
5721 | /// constructs and extract 'x', 'expr' and Operation from the original | |||
5722 | /// expression. If DiagId and NoteId == 0, then only check is performed | |||
5723 | /// without error notification. | |||
5724 | /// \param DiagId Diagnostic which should be emitted if error is found. | |||
5725 | /// \param NoteId Diagnostic note for the main error message. | |||
5726 | /// \return true if statement is not an update expression, false otherwise. | |||
5727 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); | |||
5728 | /// \brief Return the 'x' lvalue part of the source atomic expression. | |||
5729 | Expr *getX() const { return X; } | |||
5730 | /// \brief Return the 'expr' rvalue part of the source atomic expression. | |||
5731 | Expr *getExpr() const { return E; } | |||
5732 | /// \brief Return the update expression used in calculation of the updated | |||
5733 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or | |||
5734 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. | |||
5735 | Expr *getUpdateExpr() const { return UpdateExpr; } | |||
5736 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, | |||
5737 | /// false otherwise. | |||
5738 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } | |||
5739 | ||||
5740 | /// \brief true if the source expression is a postfix unary operation, false | |||
5741 | /// if it is a prefix unary operation. | |||
5742 | bool isPostfixUpdate() const { return IsPostfixUpdate; } | |||
5743 | ||||
5744 | private: | |||
5745 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, | |||
5746 | unsigned NoteId = 0); | |||
5747 | }; | |||
5748 | } // namespace | |||
5749 | ||||
5750 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( | |||
5751 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { | |||
5752 | ExprAnalysisErrorCode ErrorFound = NoError; | |||
5753 | SourceLocation ErrorLoc, NoteLoc; | |||
5754 | SourceRange ErrorRange, NoteRange; | |||
5755 | // Allowed constructs are: | |||
5756 | // x = x binop expr; | |||
5757 | // x = expr binop x; | |||
5758 | if (AtomicBinOp->getOpcode() == BO_Assign) { | |||
5759 | X = AtomicBinOp->getLHS(); | |||
5760 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( | |||
5761 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { | |||
5762 | if (AtomicInnerBinOp->isMultiplicativeOp() || | |||
5763 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || | |||
5764 | AtomicInnerBinOp->isBitwiseOp()) { | |||
5765 | Op = AtomicInnerBinOp->getOpcode(); | |||
5766 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); | |||
5767 | auto *LHS = AtomicInnerBinOp->getLHS(); | |||
5768 | auto *RHS = AtomicInnerBinOp->getRHS(); | |||
5769 | llvm::FoldingSetNodeID XId, LHSId, RHSId; | |||
5770 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), | |||
5771 | /*Canonical=*/true); | |||
5772 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), | |||
5773 | /*Canonical=*/true); | |||
5774 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), | |||
5775 | /*Canonical=*/true); | |||
5776 | if (XId == LHSId) { | |||
5777 | E = RHS; | |||
5778 | IsXLHSInRHSPart = true; | |||
5779 | } else if (XId == RHSId) { | |||
5780 | E = LHS; | |||
5781 | IsXLHSInRHSPart = false; | |||
5782 | } else { | |||
5783 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); | |||
5784 | ErrorRange = AtomicInnerBinOp->getSourceRange(); | |||
5785 | NoteLoc = X->getExprLoc(); | |||
5786 | NoteRange = X->getSourceRange(); | |||
5787 | ErrorFound = NotAnUpdateExpression; | |||
5788 | } | |||
5789 | } else { | |||
5790 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); | |||
5791 | ErrorRange = AtomicInnerBinOp->getSourceRange(); | |||
5792 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); | |||
5793 | NoteRange = SourceRange(NoteLoc, NoteLoc); | |||
5794 | ErrorFound = NotABinaryOperator; | |||
5795 | } | |||
5796 | } else { | |||
5797 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); | |||
5798 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); | |||
5799 | ErrorFound = NotABinaryExpression; | |||
5800 | } | |||
5801 | } else { | |||
5802 | ErrorLoc = AtomicBinOp->getExprLoc(); | |||
5803 | ErrorRange = AtomicBinOp->getSourceRange(); | |||
5804 | NoteLoc = AtomicBinOp->getOperatorLoc(); | |||
5805 | NoteRange = SourceRange(NoteLoc, NoteLoc); | |||
5806 | ErrorFound = NotAnAssignmentOp; | |||
5807 | } | |||
5808 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { | |||
5809 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; | |||
5810 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; | |||
5811 | return true; | |||
5812 | } else if (SemaRef.CurContext->isDependentContext()) | |||
5813 | E = X = UpdateExpr = nullptr; | |||
5814 | return ErrorFound != NoError; | |||
5815 | } | |||
5816 | ||||
5817 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, | |||
5818 | unsigned NoteId) { | |||
5819 | ExprAnalysisErrorCode ErrorFound = NoError; | |||
5820 | SourceLocation ErrorLoc, NoteLoc; | |||
5821 | SourceRange ErrorRange, NoteRange; | |||
5822 | // Allowed constructs are: | |||
5823 | // x++; | |||
5824 | // x--; | |||
5825 | // ++x; | |||
5826 | // --x; | |||
5827 | // x binop= expr; | |||
5828 | // x = x binop expr; | |||
5829 | // x = expr binop x; | |||
5830 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { | |||
5831 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); | |||
5832 | if (AtomicBody->getType()->isScalarType() || | |||
5833 | AtomicBody->isInstantiationDependent()) { | |||
5834 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( | |||
5835 | AtomicBody->IgnoreParenImpCasts())) { | |||
5836 | // Check for Compound Assignment Operation | |||
5837 | Op = BinaryOperator::getOpForCompoundAssignment( | |||
5838 | AtomicCompAssignOp->getOpcode()); | |||
5839 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); | |||
5840 | E = AtomicCompAssignOp->getRHS(); | |||
5841 | X = AtomicCompAssignOp->getLHS(); | |||
5842 | IsXLHSInRHSPart = true; | |||
5843 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( | |||
5844 | AtomicBody->IgnoreParenImpCasts())) { | |||
5845 | // Check for Binary Operation | |||
5846 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) | |||
5847 | return true; | |||
5848 | } else if (auto *AtomicUnaryOp = | |||
5849 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { | |||
5850 | // Check for Unary Operation | |||
5851 | if (AtomicUnaryOp->isIncrementDecrementOp()) { | |||
5852 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); | |||
5853 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; | |||
5854 | OpLoc = AtomicUnaryOp->getOperatorLoc(); | |||
5855 | X = AtomicUnaryOp->getSubExpr(); | |||
5856 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); | |||
5857 | IsXLHSInRHSPart = true; | |||
5858 | } else { | |||
5859 | ErrorFound = NotAnUnaryIncDecExpression; | |||
5860 | ErrorLoc = AtomicUnaryOp->getExprLoc(); | |||
5861 | ErrorRange = AtomicUnaryOp->getSourceRange(); | |||
5862 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); | |||
5863 | NoteRange = SourceRange(NoteLoc, NoteLoc); | |||
5864 | } | |||
5865 | } else if (!AtomicBody->isInstantiationDependent()) { | |||
5866 | ErrorFound = NotABinaryOrUnaryExpression; | |||
5867 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); | |||
5868 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); | |||
5869 | } | |||
5870 | } else { | |||
5871 | ErrorFound = NotAScalarType; | |||
5872 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); | |||
5873 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); | |||
5874 | } | |||
5875 | } else { | |||
5876 | ErrorFound = NotAnExpression; | |||
5877 | NoteLoc = ErrorLoc = S->getLocStart(); | |||
5878 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); | |||
5879 | } | |||
5880 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { | |||
5881 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; | |||
5882 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; | |||
5883 | return true; | |||
5884 | } else if (SemaRef.CurContext->isDependentContext()) | |||
5885 | E = X = UpdateExpr = nullptr; | |||
5886 | if (ErrorFound == NoError && E && X) { | |||
5887 | // Build an update expression of form 'OpaqueValueExpr(x) binop | |||
5888 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop | |||
5889 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. | |||
5890 | auto *OVEX = new (SemaRef.getASTContext()) | |||
5891 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); | |||
5892 | auto *OVEExpr = new (SemaRef.getASTContext()) | |||
5893 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); | |||
5894 | auto Update = | |||
5895 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, | |||
5896 | IsXLHSInRHSPart ? OVEExpr : OVEX); | |||
5897 | if (Update.isInvalid()) | |||
5898 | return true; | |||
5899 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), | |||
5900 | Sema::AA_Casting); | |||
5901 | if (Update.isInvalid()) | |||
5902 | return true; | |||
5903 | UpdateExpr = Update.get(); | |||
5904 | } | |||
5905 | return ErrorFound != NoError; | |||
5906 | } | |||
5907 | ||||
5908 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, | |||
5909 | Stmt *AStmt, | |||
5910 | SourceLocation StartLoc, | |||
5911 | SourceLocation EndLoc) { | |||
5912 | if (!AStmt) | |||
5913 | return StmtError(); | |||
5914 | ||||
5915 | auto CS = cast<CapturedStmt>(AStmt); | |||
5916 | // 1.2.2 OpenMP Language Terminology | |||
5917 | // Structured block - An executable statement with a single entry at the | |||
5918 | // top and a single exit at the bottom. | |||
5919 | // The point of exit cannot be a branch out of the structured block. | |||
5920 | // longjmp() and throw() must not violate the entry/exit criteria. | |||
5921 | OpenMPClauseKind AtomicKind = OMPC_unknown; | |||
5922 | SourceLocation AtomicKindLoc; | |||
5923 | for (auto *C : Clauses) { | |||
5924 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || | |||
5925 | C->getClauseKind() == OMPC_update || | |||
5926 | C->getClauseKind() == OMPC_capture) { | |||
5927 | if (AtomicKind != OMPC_unknown) { | |||
5928 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) | |||
5929 | << SourceRange(C->getLocStart(), C->getLocEnd()); | |||
5930 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) | |||
5931 | << getOpenMPClauseName(AtomicKind); | |||
5932 | } else { | |||
5933 | AtomicKind = C->getClauseKind(); | |||
5934 | AtomicKindLoc = C->getLocStart(); | |||
5935 | } | |||
5936 | } | |||
5937 | } | |||
5938 | ||||
5939 | auto Body = CS->getCapturedStmt(); | |||
5940 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) | |||
5941 | Body = EWC->getSubExpr(); | |||
5942 | ||||
5943 | Expr *X = nullptr; | |||
5944 | Expr *V = nullptr; | |||
5945 | Expr *E = nullptr; | |||
5946 | Expr *UE = nullptr; | |||
5947 | bool IsXLHSInRHSPart = false; | |||
5948 | bool IsPostfixUpdate = false; | |||
5949 | // OpenMP [2.12.6, atomic Construct] | |||
5950 | // In the next expressions: | |||
5951 | // * x and v (as applicable) are both l-value expressions with scalar type. | |||
5952 | // * During the execution of an atomic region, multiple syntactic | |||
5953 | // occurrences of x must designate the same storage location. | |||
5954 | // * Neither of v and expr (as applicable) may access the storage location | |||
5955 | // designated by x. | |||
5956 | // * Neither of x and expr (as applicable) may access the storage location | |||
5957 | // designated by v. | |||
5958 | // * expr is an expression with scalar type. | |||
5959 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. | |||
5960 | // * binop, binop=, ++, and -- are not overloaded operators. | |||
5961 | // * The expression x binop expr must be numerically equivalent to x binop | |||
5962 | // (expr). This requirement is satisfied if the operators in expr have | |||
5963 | // precedence greater than binop, or by using parentheses around expr or | |||
5964 | // subexpressions of expr. | |||
5965 | // * The expression expr binop x must be numerically equivalent to (expr) | |||
5966 | // binop x. This requirement is satisfied if the operators in expr have | |||
5967 | // precedence equal to or greater than binop, or by using parentheses around | |||
5968 | // expr or subexpressions of expr. | |||
5969 | // * For forms that allow multiple occurrences of x, the number of times | |||
5970 | // that x is evaluated is unspecified. | |||
5971 | if (AtomicKind == OMPC_read) { | |||
5972 | enum { | |||
5973 | NotAnExpression, | |||
5974 | NotAnAssignmentOp, | |||
5975 | NotAScalarType, | |||
5976 | NotAnLValue, | |||
5977 | NoError | |||
5978 | } ErrorFound = NoError; | |||
5979 | SourceLocation ErrorLoc, NoteLoc; | |||
5980 | SourceRange ErrorRange, NoteRange; | |||
5981 | // If clause is read: | |||
5982 | // v = x; | |||
5983 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { | |||
5984 | auto AtomicBinOp = | |||
5985 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); | |||
5986 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { | |||
5987 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); | |||
5988 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); | |||
5989 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && | |||
5990 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { | |||
5991 | if (!X->isLValue() || !V->isLValue()) { | |||
5992 | auto NotLValueExpr = X->isLValue() ? V : X; | |||
5993 | ErrorFound = NotAnLValue; | |||
5994 | ErrorLoc = AtomicBinOp->getExprLoc(); | |||
5995 | ErrorRange = AtomicBinOp->getSourceRange(); | |||
5996 | NoteLoc = NotLValueExpr->getExprLoc(); | |||
5997 | NoteRange = NotLValueExpr->getSourceRange(); | |||
5998 | } | |||
5999 | } else if (!X->isInstantiationDependent() || | |||
6000 | !V->isInstantiationDependent()) { | |||
6001 | auto NotScalarExpr = | |||
6002 | (X->isInstantiationDependent() || X->getType()->isScalarType()) | |||
6003 | ? V | |||
6004 | : X; | |||
6005 | ErrorFound = NotAScalarType; | |||
6006 | ErrorLoc = AtomicBinOp->getExprLoc(); | |||
6007 | ErrorRange = AtomicBinOp->getSourceRange(); | |||
6008 | NoteLoc = NotScalarExpr->getExprLoc(); | |||
6009 | NoteRange = NotScalarExpr->getSourceRange(); | |||
6010 | } | |||
6011 | } else if (!AtomicBody->isInstantiationDependent()) { | |||
6012 | ErrorFound = NotAnAssignmentOp; | |||
6013 | ErrorLoc = AtomicBody->getExprLoc(); | |||
6014 | ErrorRange = AtomicBody->getSourceRange(); | |||
6015 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() | |||
6016 | : AtomicBody->getExprLoc(); | |||
6017 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() | |||
6018 | : AtomicBody->getSourceRange(); | |||
6019 | } | |||
6020 | } else { | |||
6021 | ErrorFound = NotAnExpression; | |||
6022 | NoteLoc = ErrorLoc = Body->getLocStart(); | |||
6023 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); | |||
6024 | } | |||
6025 | if (ErrorFound != NoError) { | |||
6026 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) | |||
6027 | << ErrorRange; | |||
6028 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound | |||
6029 | << NoteRange; | |||
6030 | return StmtError(); | |||
6031 | } else if (CurContext->isDependentContext()) | |||
6032 | V = X = nullptr; | |||
6033 | } else if (AtomicKind == OMPC_write) { | |||
6034 | enum { | |||
6035 | NotAnExpression, | |||
6036 | NotAnAssignmentOp, | |||
6037 | NotAScalarType, | |||
6038 | NotAnLValue, | |||
6039 | NoError | |||
6040 | } ErrorFound = NoError; | |||
6041 | SourceLocation ErrorLoc, NoteLoc; | |||
6042 | SourceRange ErrorRange, NoteRange; | |||
6043 | // If clause is write: | |||
6044 | // x = expr; | |||
6045 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { | |||
6046 | auto AtomicBinOp = | |||
6047 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); | |||
6048 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { | |||
6049 | X = AtomicBinOp->getLHS(); | |||
6050 | E = AtomicBinOp->getRHS(); | |||
6051 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && | |||
6052 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { | |||
6053 | if (!X->isLValue()) { | |||
6054 | ErrorFound = NotAnLValue; | |||
6055 | ErrorLoc = AtomicBinOp->getExprLoc(); | |||
6056 | ErrorRange = AtomicBinOp->getSourceRange(); | |||
6057 | NoteLoc = X->getExprLoc(); | |||
6058 | NoteRange = X->getSourceRange(); | |||
6059 | } | |||
6060 | } else if (!X->isInstantiationDependent() || | |||
6061 | !E->isInstantiationDependent()) { | |||
6062 | auto NotScalarExpr = | |||
6063 | (X->isInstantiationDependent() || X->getType()->isScalarType()) | |||
6064 | ? E | |||
6065 | : X; | |||
6066 | ErrorFound = NotAScalarType; | |||
6067 | ErrorLoc = AtomicBinOp->getExprLoc(); | |||
6068 | ErrorRange = AtomicBinOp->getSourceRange(); | |||
6069 | NoteLoc = NotScalarExpr->getExprLoc(); | |||
6070 | NoteRange = NotScalarExpr->getSourceRange(); | |||
6071 | } | |||
6072 | } else if (!AtomicBody->isInstantiationDependent()) { | |||
6073 | ErrorFound = NotAnAssignmentOp; | |||
6074 | ErrorLoc = AtomicBody->getExprLoc(); | |||
6075 | ErrorRange = AtomicBody->getSourceRange(); | |||
6076 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() | |||
6077 | : AtomicBody->getExprLoc(); | |||
6078 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() | |||
6079 | : AtomicBody->getSourceRange(); | |||
6080 | } | |||
6081 | } else { | |||
6082 | ErrorFound = NotAnExpression; | |||
6083 | NoteLoc = ErrorLoc = Body->getLocStart(); | |||
6084 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); | |||
6085 | } | |||
6086 | if (ErrorFound != NoError) { | |||
6087 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) | |||
6088 | << ErrorRange; | |||
6089 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound | |||
6090 | << NoteRange; | |||
6091 | return StmtError(); | |||
6092 | } else if (CurContext->isDependentContext()) | |||
6093 | E = X = nullptr; | |||
6094 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { | |||
6095 | // If clause is update: | |||
6096 | // x++; | |||
6097 | // x--; | |||
6098 | // ++x; | |||
6099 | // --x; | |||
6100 | // x binop= expr; | |||
6101 | // x = x binop expr; | |||
6102 | // x = expr binop x; | |||
6103 | OpenMPAtomicUpdateChecker Checker(*this); | |||
6104 | if (Checker.checkStatement( | |||
6105 | Body, (AtomicKind == OMPC_update) | |||
6106 | ? diag::err_omp_atomic_update_not_expression_statement | |||
6107 | : diag::err_omp_atomic_not_expression_statement, | |||
6108 | diag::note_omp_atomic_update)) | |||
6109 | return StmtError(); | |||
6110 | if (!CurContext->isDependentContext()) { | |||
6111 | E = Checker.getExpr(); | |||
6112 | X = Checker.getX(); | |||
6113 | UE = Checker.getUpdateExpr(); | |||
6114 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); | |||
6115 | } | |||
6116 | } else if (AtomicKind == OMPC_capture) { | |||
6117 | enum { | |||
6118 | NotAnAssignmentOp, | |||
6119 | NotACompoundStatement, | |||
6120 | NotTwoSubstatements, | |||
6121 | NotASpecificExpression, | |||
6122 | NoError | |||
6123 | } ErrorFound = NoError; | |||
6124 | SourceLocation ErrorLoc, NoteLoc; | |||
6125 | SourceRange ErrorRange, NoteRange; | |||
6126 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { | |||
6127 | // If clause is a capture: | |||
6128 | // v = x++; | |||
6129 | // v = x--; | |||
6130 | // v = ++x; | |||
6131 | // v = --x; | |||
6132 | // v = x binop= expr; | |||
6133 | // v = x = x binop expr; | |||
6134 | // v = x = expr binop x; | |||
6135 | auto *AtomicBinOp = | |||
6136 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); | |||
6137 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { | |||
6138 | V = AtomicBinOp->getLHS(); | |||
6139 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); | |||
6140 | OpenMPAtomicUpdateChecker Checker(*this); | |||
6141 | if (Checker.checkStatement( | |||
6142 | Body, diag::err_omp_atomic_capture_not_expression_statement, | |||
6143 | diag::note_omp_atomic_update)) | |||
6144 | return StmtError(); | |||
6145 | E = Checker.getExpr(); | |||
6146 | X = Checker.getX(); | |||
6147 | UE = Checker.getUpdateExpr(); | |||
6148 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); | |||
6149 | IsPostfixUpdate = Checker.isPostfixUpdate(); | |||
6150 | } else if (!AtomicBody->isInstantiationDependent()) { | |||
6151 | ErrorLoc = AtomicBody->getExprLoc(); | |||
6152 | ErrorRange = AtomicBody->getSourceRange(); | |||
6153 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() | |||
6154 | : AtomicBody->getExprLoc(); | |||
6155 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() | |||
6156 | : AtomicBody->getSourceRange(); | |||
6157 | ErrorFound = NotAnAssignmentOp; | |||
6158 | } | |||
6159 | if (ErrorFound != NoError) { | |||
6160 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) | |||
6161 | << ErrorRange; | |||
6162 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; | |||
6163 | return StmtError(); | |||
6164 | } else if (CurContext->isDependentContext()) { | |||
6165 | UE = V = E = X = nullptr; | |||
6166 | } | |||
6167 | } else { | |||
6168 | // If clause is a capture: | |||
6169 | // { v = x; x = expr; } | |||
6170 | // { v = x; x++; } | |||
6171 | // { v = x; x--; } | |||
6172 | // { v = x; ++x; } | |||
6173 | // { v = x; --x; } | |||
6174 | // { v = x; x binop= expr; } | |||
6175 | // { v = x; x = x binop expr; } | |||
6176 | // { v = x; x = expr binop x; } | |||
6177 | // { x++; v = x; } | |||
6178 | // { x--; v = x; } | |||
6179 | // { ++x; v = x; } | |||
6180 | // { --x; v = x; } | |||
6181 | // { x binop= expr; v = x; } | |||
6182 | // { x = x binop expr; v = x; } | |||
6183 | // { x = expr binop x; v = x; } | |||
6184 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { | |||
6185 | // Check that this is { expr1; expr2; } | |||
6186 | if (CS->size() == 2) { | |||
6187 | auto *First = CS->body_front(); | |||
6188 | auto *Second = CS->body_back(); | |||
6189 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) | |||
6190 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); | |||
6191 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) | |||
6192 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); | |||
6193 | // Need to find what subexpression is 'v' and what is 'x'. | |||
6194 | OpenMPAtomicUpdateChecker Checker(*this); | |||
6195 | bool IsUpdateExprFound = !Checker.checkStatement(Second); | |||
6196 | BinaryOperator *BinOp = nullptr; | |||
6197 | if (IsUpdateExprFound) { | |||
6198 | BinOp = dyn_cast<BinaryOperator>(First); | |||
6199 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; | |||
6200 | } | |||
6201 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { | |||
6202 | // { v = x; x++; } | |||
6203 | // { v = x; x--; } | |||
6204 | // { v = x; ++x; } | |||
6205 | // { v = x; --x; } | |||
6206 | // { v = x; x binop= expr; } | |||
6207 | // { v = x; x = x binop expr; } | |||
6208 | // { v = x; x = expr binop x; } | |||
6209 | // Check that the first expression has form v = x. | |||
6210 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); | |||
6211 | llvm::FoldingSetNodeID XId, PossibleXId; | |||
6212 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); | |||
6213 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); | |||
6214 | IsUpdateExprFound = XId == PossibleXId; | |||
6215 | if (IsUpdateExprFound) { | |||
6216 | V = BinOp->getLHS(); | |||
6217 | X = Checker.getX(); | |||
6218 | E = Checker.getExpr(); | |||
6219 | UE = Checker.getUpdateExpr(); | |||
6220 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); | |||
6221 | IsPostfixUpdate = true; | |||
6222 | } | |||
6223 | } | |||
6224 | if (!IsUpdateExprFound) { | |||
6225 | IsUpdateExprFound = !Checker.checkStatement(First); | |||
6226 | BinOp = nullptr; | |||
6227 | if (IsUpdateExprFound) { | |||
6228 | BinOp = dyn_cast<BinaryOperator>(Second); | |||
6229 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; | |||
6230 | } | |||
6231 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { | |||
6232 | // { x++; v = x; } | |||
6233 | // { x--; v = x; } | |||
6234 | // { ++x; v = x; } | |||
6235 | // { --x; v = x; } | |||
6236 | // { x binop= expr; v = x; } | |||
6237 | // { x = x binop expr; v = x; } | |||
6238 | // { x = expr binop x; v = x; } | |||
6239 | // Check that the second expression has form v = x. | |||
6240 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); | |||
6241 | llvm::FoldingSetNodeID XId, PossibleXId; | |||
6242 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); | |||
6243 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); | |||
6244 | IsUpdateExprFound = XId == PossibleXId; | |||
6245 | if (IsUpdateExprFound) { | |||
6246 | V = BinOp->getLHS(); | |||
6247 | X = Checker.getX(); | |||
6248 | E = Checker.getExpr(); | |||
6249 | UE = Checker.getUpdateExpr(); | |||
6250 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); | |||
6251 | IsPostfixUpdate = false; | |||
6252 | } | |||
6253 | } | |||
6254 | } | |||
6255 | if (!IsUpdateExprFound) { | |||
6256 | // { v = x; x = expr; } | |||
6257 | auto *FirstExpr = dyn_cast<Expr>(First); | |||
6258 | auto *SecondExpr = dyn_cast<Expr>(Second); | |||
6259 | if (!FirstExpr || !SecondExpr || | |||
6260 | !(FirstExpr->isInstantiationDependent() || | |||
6261 | SecondExpr->isInstantiationDependent())) { | |||
6262 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); | |||
6263 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { | |||
6264 | ErrorFound = NotAnAssignmentOp; | |||
6265 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() | |||
6266 | : First->getLocStart(); | |||
6267 | NoteRange = ErrorRange = FirstBinOp | |||
6268 | ? FirstBinOp->getSourceRange() | |||
6269 | : SourceRange(ErrorLoc, ErrorLoc); | |||
6270 | } else { | |||
6271 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); | |||
6272 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { | |||
6273 | ErrorFound = NotAnAssignmentOp; | |||
6274 | NoteLoc = ErrorLoc = SecondBinOp | |||
6275 | ? SecondBinOp->getOperatorLoc() | |||
6276 | : Second->getLocStart(); | |||
6277 | NoteRange = ErrorRange = | |||
6278 | SecondBinOp ? SecondBinOp->getSourceRange() | |||
6279 | : SourceRange(ErrorLoc, ErrorLoc); | |||
6280 | } else { | |||
6281 | auto *PossibleXRHSInFirst = | |||
6282 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); | |||
6283 | auto *PossibleXLHSInSecond = | |||
6284 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); | |||
6285 | llvm::FoldingSetNodeID X1Id, X2Id; | |||
6286 | PossibleXRHSInFirst->Profile(X1Id, Context, | |||
6287 | /*Canonical=*/true); | |||
6288 | PossibleXLHSInSecond->Profile(X2Id, Context, | |||
6289 | /*Canonical=*/true); | |||
6290 | IsUpdateExprFound = X1Id == X2Id; | |||
6291 | if (IsUpdateExprFound) { | |||
6292 | V = FirstBinOp->getLHS(); | |||
6293 | X = SecondBinOp->getLHS(); | |||
6294 | E = SecondBinOp->getRHS(); | |||
6295 | UE = nullptr; | |||
6296 | IsXLHSInRHSPart = false; | |||
6297 | IsPostfixUpdate = true; | |||
6298 | } else { | |||
6299 | ErrorFound = NotASpecificExpression; | |||
6300 | ErrorLoc = FirstBinOp->getExprLoc(); | |||
6301 | ErrorRange = FirstBinOp->getSourceRange(); | |||
6302 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); | |||
6303 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); | |||
6304 | } | |||
6305 | } | |||
6306 | } | |||
6307 | } | |||
6308 | } | |||
6309 | } else { | |||
6310 | NoteLoc = ErrorLoc = Body->getLocStart(); | |||
6311 | NoteRange = ErrorRange = | |||
6312 | SourceRange(Body->getLocStart(), Body->getLocStart()); | |||
6313 | ErrorFound = NotTwoSubstatements; | |||
6314 | } | |||
6315 | } else { | |||
6316 | NoteLoc = ErrorLoc = Body->getLocStart(); | |||
6317 | NoteRange = ErrorRange = | |||
6318 | SourceRange(Body->getLocStart(), Body->getLocStart()); | |||
6319 | ErrorFound = NotACompoundStatement; | |||
6320 | } | |||
6321 | if (ErrorFound != NoError) { | |||
6322 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) | |||
6323 | << ErrorRange; | |||
6324 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; | |||
6325 | return StmtError(); | |||
6326 | } else if (CurContext->isDependentContext()) { | |||
6327 | UE = V = E = X = nullptr; | |||
6328 | } | |||
6329 | } | |||
6330 | } | |||
6331 | ||||
6332 | getCurFunction()->setHasBranchProtectedScope(); | |||
6333 | ||||
6334 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, | |||
6335 | X, V, E, UE, IsXLHSInRHSPart, | |||
6336 | IsPostfixUpdate); | |||
6337 | } | |||
6338 | ||||
6339 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, | |||
6340 | Stmt *AStmt, | |||
6341 | SourceLocation StartLoc, | |||
6342 | SourceLocation EndLoc) { | |||
6343 | if (!AStmt) | |||
6344 | return StmtError(); | |||
6345 | ||||
6346 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); | |||
6347 | // 1.2.2 OpenMP Language Terminology | |||
6348 | // Structured block - An executable statement with a single entry at the | |||
6349 | // top and a single exit at the bottom. | |||
6350 | // The point of exit cannot be a branch out of the structured block. | |||
6351 | // longjmp() and throw() must not violate the entry/exit criteria. | |||
6352 | CS->getCapturedDecl()->setNothrow(); | |||
6353 | ||||
6354 | // OpenMP [2.16, Nesting of Regions] | |||
6355 | // If specified, a teams construct must be contained within a target | |||
6356 | // construct. That target construct must contain no statements or directives | |||
6357 | // outside of the teams construct. | |||
6358 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasInnerTeamsRegion()) { | |||
6359 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); | |||
6360 | bool OMPTeamsFound = true; | |||
6361 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { | |||
6362 | auto I = CS->body_begin(); | |||
6363 | while (I != CS->body_end()) { | |||
6364 | auto OED = dyn_cast<OMPExecutableDirective>(*I); | |||
6365 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { | |||
6366 | OMPTeamsFound = false; | |||
6367 | break; | |||
6368 | } | |||
6369 | ++I; | |||
6370 | } | |||
6371 | assert(I != CS->body_end() && "Not found statement")((I != CS->body_end() && "Not found statement") ? static_cast <void> (0) : __assert_fail ("I != CS->body_end() && \"Not found statement\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6371, __PRETTY_FUNCTION__)); | |||
6372 | S = *I; | |||
6373 | } | |||
6374 | if (!OMPTeamsFound) { | |||
6375 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); | |||
6376 | Diag(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getInnerTeamsRegionLoc(), | |||
6377 | diag::note_omp_nested_teams_construct_here); | |||
6378 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) | |||
6379 | << isa<OMPExecutableDirective>(S); | |||
6380 | return StmtError(); | |||
6381 | } | |||
6382 | } | |||
6383 | ||||
6384 | getCurFunction()->setHasBranchProtectedScope(); | |||
6385 | ||||
6386 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); | |||
6387 | } | |||
6388 | ||||
6389 | StmtResult | |||
6390 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, | |||
6391 | Stmt *AStmt, SourceLocation StartLoc, | |||
6392 | SourceLocation EndLoc) { | |||
6393 | if (!AStmt) | |||
6394 | return StmtError(); | |||
6395 | ||||
6396 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); | |||
6397 | // 1.2.2 OpenMP Language Terminology | |||
6398 | // Structured block - An executable statement with a single entry at the | |||
6399 | // top and a single exit at the bottom. | |||
6400 | // The point of exit cannot be a branch out of the structured block. | |||
6401 | // longjmp() and throw() must not violate the entry/exit criteria. | |||
6402 | CS->getCapturedDecl()->setNothrow(); | |||
6403 | ||||
6404 | getCurFunction()->setHasBranchProtectedScope(); | |||
6405 | ||||
6406 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, | |||
6407 | AStmt); | |||
6408 | } | |||
6409 | ||||
6410 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( | |||
6411 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, | |||
6412 | SourceLocation EndLoc, | |||
6413 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { | |||
6414 | if (!AStmt) | |||
6415 | return StmtError(); | |||
6416 | ||||
6417 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); | |||
6418 | // 1.2.2 OpenMP Language Terminology | |||
6419 | // Structured block - An executable statement with a single entry at the | |||
6420 | // top and a single exit at the bottom. | |||
6421 | // The point of exit cannot be a branch out of the structured block. | |||
6422 | // longjmp() and throw() must not violate the entry/exit criteria. | |||
6423 | CS->getCapturedDecl()->setNothrow(); | |||
6424 | ||||
6425 | OMPLoopDirective::HelperExprs B; | |||
6426 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will | |||
6427 | // define the nested loops number. | |||
6428 | unsigned NestedLoopCount = | |||
6429 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), | |||
6430 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), | |||
6431 | VarsWithImplicitDSA, B); | |||
6432 | if (NestedLoopCount == 0) | |||
6433 | return StmtError(); | |||
6434 | ||||
6435 | assert((CurContext->isDependentContext() || B.builtAll()) &&(((CurContext->isDependentContext() || B.builtAll()) && "omp target parallel for loop exprs were not built") ? static_cast <void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp target parallel for loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6436, __PRETTY_FUNCTION__)) | |||
6436 | "omp target parallel for loop exprs were not built")(((CurContext->isDependentContext() || B.builtAll()) && "omp target parallel for loop exprs were not built") ? static_cast <void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp target parallel for loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6436, __PRETTY_FUNCTION__)); | |||
6437 | ||||
6438 | if (!CurContext->isDependentContext()) { | |||
6439 | // Finalize the clauses that need pre-built expressions for CodeGen. | |||
6440 | for (auto C : Clauses) { | |||
6441 | if (auto LC = dyn_cast<OMPLinearClause>(C)) | |||
6442 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), | |||
6443 | B.NumIterations, *this, CurScope, | |||
6444 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ))) | |||
6445 | return StmtError(); | |||
6446 | } | |||
6447 | } | |||
6448 | ||||
6449 | getCurFunction()->setHasBranchProtectedScope(); | |||
6450 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, | |||
6451 | NestedLoopCount, Clauses, AStmt, | |||
6452 | B, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isCancelRegion()); | |||
6453 | } | |||
6454 | ||||
6455 | /// \brief Check for existence of a map clause in the list of clauses. | |||
6456 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { | |||
6457 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); | |||
6458 | I != E; ++I) { | |||
6459 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { | |||
6460 | return true; | |||
6461 | } | |||
6462 | } | |||
6463 | ||||
6464 | return false; | |||
6465 | } | |||
6466 | ||||
6467 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, | |||
6468 | Stmt *AStmt, | |||
6469 | SourceLocation StartLoc, | |||
6470 | SourceLocation EndLoc) { | |||
6471 | if (!AStmt) | |||
6472 | return StmtError(); | |||
6473 | ||||
6474 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6474, __PRETTY_FUNCTION__)); | |||
6475 | ||||
6476 | // OpenMP [2.10.1, Restrictions, p. 97] | |||
6477 | // At least one map clause must appear on the directive. | |||
6478 | if (!HasMapClause(Clauses)) { | |||
6479 | Diag(StartLoc, diag::err_omp_no_map_for_directive) << | |||
6480 | getOpenMPDirectiveName(OMPD_target_data); | |||
6481 | return StmtError(); | |||
6482 | } | |||
6483 | ||||
6484 | getCurFunction()->setHasBranchProtectedScope(); | |||
6485 | ||||
6486 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, | |||
6487 | AStmt); | |||
6488 | } | |||
6489 | ||||
6490 | StmtResult | |||
6491 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, | |||
6492 | SourceLocation StartLoc, | |||
6493 | SourceLocation EndLoc) { | |||
6494 | // OpenMP [2.10.2, Restrictions, p. 99] | |||
6495 | // At least one map clause must appear on the directive. | |||
6496 | if (!HasMapClause(Clauses)) { | |||
6497 | Diag(StartLoc, diag::err_omp_no_map_for_directive) | |||
6498 | << getOpenMPDirectiveName(OMPD_target_enter_data); | |||
6499 | return StmtError(); | |||
6500 | } | |||
6501 | ||||
6502 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, | |||
6503 | Clauses); | |||
6504 | } | |||
6505 | ||||
6506 | StmtResult | |||
6507 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, | |||
6508 | SourceLocation StartLoc, | |||
6509 | SourceLocation EndLoc) { | |||
6510 | // OpenMP [2.10.3, Restrictions, p. 102] | |||
6511 | // At least one map clause must appear on the directive. | |||
6512 | if (!HasMapClause(Clauses)) { | |||
6513 | Diag(StartLoc, diag::err_omp_no_map_for_directive) | |||
6514 | << getOpenMPDirectiveName(OMPD_target_exit_data); | |||
6515 | return StmtError(); | |||
6516 | } | |||
6517 | ||||
6518 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); | |||
6519 | } | |||
6520 | ||||
6521 | StmtResult Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, | |||
6522 | SourceLocation StartLoc, | |||
6523 | SourceLocation EndLoc) { | |||
6524 | bool seenMotionClause = false; | |||
6525 | for (auto *C : Clauses) { | |||
6526 | if (C->getClauseKind() == OMPC_to || C->getClauseKind() == OMPC_from) | |||
6527 | seenMotionClause = true; | |||
6528 | } | |||
6529 | if (!seenMotionClause) { | |||
6530 | Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required); | |||
6531 | return StmtError(); | |||
6532 | } | |||
6533 | return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses); | |||
6534 | } | |||
6535 | ||||
6536 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, | |||
6537 | Stmt *AStmt, SourceLocation StartLoc, | |||
6538 | SourceLocation EndLoc) { | |||
6539 | if (!AStmt) | |||
6540 | return StmtError(); | |||
6541 | ||||
6542 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); | |||
6543 | // 1.2.2 OpenMP Language Terminology | |||
6544 | // Structured block - An executable statement with a single entry at the | |||
6545 | // top and a single exit at the bottom. | |||
6546 | // The point of exit cannot be a branch out of the structured block. | |||
6547 | // longjmp() and throw() must not violate the entry/exit criteria. | |||
6548 | CS->getCapturedDecl()->setNothrow(); | |||
6549 | ||||
6550 | getCurFunction()->setHasBranchProtectedScope(); | |||
6551 | ||||
6552 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); | |||
6553 | } | |||
6554 | ||||
6555 | StmtResult | |||
6556 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, | |||
6557 | SourceLocation EndLoc, | |||
6558 | OpenMPDirectiveKind CancelRegion) { | |||
6559 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && | |||
6560 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { | |||
6561 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) | |||
6562 | << getOpenMPDirectiveName(CancelRegion); | |||
6563 | return StmtError(); | |||
6564 | } | |||
6565 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isParentNowaitRegion()) { | |||
6566 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; | |||
6567 | return StmtError(); | |||
6568 | } | |||
6569 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isParentOrderedRegion()) { | |||
6570 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; | |||
6571 | return StmtError(); | |||
6572 | } | |||
6573 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, | |||
6574 | CancelRegion); | |||
6575 | } | |||
6576 | ||||
6577 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, | |||
6578 | SourceLocation StartLoc, | |||
6579 | SourceLocation EndLoc, | |||
6580 | OpenMPDirectiveKind CancelRegion) { | |||
6581 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && | |||
6582 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { | |||
6583 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) | |||
6584 | << getOpenMPDirectiveName(CancelRegion); | |||
6585 | return StmtError(); | |||
6586 | } | |||
6587 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isParentNowaitRegion()) { | |||
6588 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; | |||
6589 | return StmtError(); | |||
6590 | } | |||
6591 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isParentOrderedRegion()) { | |||
6592 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; | |||
6593 | return StmtError(); | |||
6594 | } | |||
6595 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setParentCancelRegion(/*Cancel=*/true); | |||
6596 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, | |||
6597 | CancelRegion); | |||
6598 | } | |||
6599 | ||||
6600 | static bool checkGrainsizeNumTasksClauses(Sema &S, | |||
6601 | ArrayRef<OMPClause *> Clauses) { | |||
6602 | OMPClause *PrevClause = nullptr; | |||
6603 | bool ErrorFound = false; | |||
6604 | for (auto *C : Clauses) { | |||
6605 | if (C->getClauseKind() == OMPC_grainsize || | |||
6606 | C->getClauseKind() == OMPC_num_tasks) { | |||
6607 | if (!PrevClause) | |||
6608 | PrevClause = C; | |||
6609 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { | |||
6610 | S.Diag(C->getLocStart(), | |||
6611 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) | |||
6612 | << getOpenMPClauseName(C->getClauseKind()) | |||
6613 | << getOpenMPClauseName(PrevClause->getClauseKind()); | |||
6614 | S.Diag(PrevClause->getLocStart(), | |||
6615 | diag::note_omp_previous_grainsize_num_tasks) | |||
6616 | << getOpenMPClauseName(PrevClause->getClauseKind()); | |||
6617 | ErrorFound = true; | |||
6618 | } | |||
6619 | } | |||
6620 | } | |||
6621 | return ErrorFound; | |||
6622 | } | |||
6623 | ||||
6624 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( | |||
6625 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, | |||
6626 | SourceLocation EndLoc, | |||
6627 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { | |||
6628 | if (!AStmt) | |||
6629 | return StmtError(); | |||
6630 | ||||
6631 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6631, __PRETTY_FUNCTION__)); | |||
6632 | OMPLoopDirective::HelperExprs B; | |||
6633 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will | |||
6634 | // define the nested loops number. | |||
6635 | unsigned NestedLoopCount = | |||
6636 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), | |||
6637 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), | |||
6638 | VarsWithImplicitDSA, B); | |||
6639 | if (NestedLoopCount == 0) | |||
6640 | return StmtError(); | |||
6641 | ||||
6642 | assert((CurContext->isDependentContext() || B.builtAll()) &&(((CurContext->isDependentContext() || B.builtAll()) && "omp for loop exprs were not built") ? static_cast<void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp for loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6643, __PRETTY_FUNCTION__)) | |||
6643 | "omp for loop exprs were not built")(((CurContext->isDependentContext() || B.builtAll()) && "omp for loop exprs were not built") ? static_cast<void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp for loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6643, __PRETTY_FUNCTION__)); | |||
6644 | ||||
6645 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] | |||
6646 | // The grainsize clause and num_tasks clause are mutually exclusive and may | |||
6647 | // not appear on the same taskloop directive. | |||
6648 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) | |||
6649 | return StmtError(); | |||
6650 | ||||
6651 | getCurFunction()->setHasBranchProtectedScope(); | |||
6652 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, | |||
6653 | NestedLoopCount, Clauses, AStmt, B); | |||
6654 | } | |||
6655 | ||||
6656 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( | |||
6657 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, | |||
6658 | SourceLocation EndLoc, | |||
6659 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { | |||
6660 | if (!AStmt) | |||
6661 | return StmtError(); | |||
6662 | ||||
6663 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6663, __PRETTY_FUNCTION__)); | |||
6664 | OMPLoopDirective::HelperExprs B; | |||
6665 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will | |||
6666 | // define the nested loops number. | |||
6667 | unsigned NestedLoopCount = | |||
6668 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), | |||
6669 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), | |||
6670 | VarsWithImplicitDSA, B); | |||
6671 | if (NestedLoopCount == 0) | |||
6672 | return StmtError(); | |||
6673 | ||||
6674 | assert((CurContext->isDependentContext() || B.builtAll()) &&(((CurContext->isDependentContext() || B.builtAll()) && "omp for loop exprs were not built") ? static_cast<void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp for loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6675, __PRETTY_FUNCTION__)) | |||
6675 | "omp for loop exprs were not built")(((CurContext->isDependentContext() || B.builtAll()) && "omp for loop exprs were not built") ? static_cast<void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp for loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6675, __PRETTY_FUNCTION__)); | |||
6676 | ||||
6677 | if (!CurContext->isDependentContext()) { | |||
6678 | // Finalize the clauses that need pre-built expressions for CodeGen. | |||
6679 | for (auto C : Clauses) { | |||
6680 | if (auto LC = dyn_cast<OMPLinearClause>(C)) | |||
6681 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), | |||
6682 | B.NumIterations, *this, CurScope, | |||
6683 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ))) | |||
6684 | return StmtError(); | |||
6685 | } | |||
6686 | } | |||
6687 | ||||
6688 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] | |||
6689 | // The grainsize clause and num_tasks clause are mutually exclusive and may | |||
6690 | // not appear on the same taskloop directive. | |||
6691 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) | |||
6692 | return StmtError(); | |||
6693 | ||||
6694 | getCurFunction()->setHasBranchProtectedScope(); | |||
6695 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, | |||
6696 | NestedLoopCount, Clauses, AStmt, B); | |||
6697 | } | |||
6698 | ||||
6699 | StmtResult Sema::ActOnOpenMPDistributeDirective( | |||
6700 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, | |||
6701 | SourceLocation EndLoc, | |||
6702 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { | |||
6703 | if (!AStmt) | |||
6704 | return StmtError(); | |||
6705 | ||||
6706 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6706, __PRETTY_FUNCTION__)); | |||
6707 | OMPLoopDirective::HelperExprs B; | |||
6708 | // In presence of clause 'collapse' with number of loops, it will | |||
6709 | // define the nested loops number. | |||
6710 | unsigned NestedLoopCount = | |||
6711 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), | |||
6712 | nullptr /*ordered not a clause on distribute*/, AStmt, | |||
6713 | *this, *DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), VarsWithImplicitDSA, B); | |||
6714 | if (NestedLoopCount == 0) | |||
6715 | return StmtError(); | |||
6716 | ||||
6717 | assert((CurContext->isDependentContext() || B.builtAll()) &&(((CurContext->isDependentContext() || B.builtAll()) && "omp for loop exprs were not built") ? static_cast<void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp for loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6718, __PRETTY_FUNCTION__)) | |||
6718 | "omp for loop exprs were not built")(((CurContext->isDependentContext() || B.builtAll()) && "omp for loop exprs were not built") ? static_cast<void> (0) : __assert_fail ("(CurContext->isDependentContext() || B.builtAll()) && \"omp for loop exprs were not built\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6718, __PRETTY_FUNCTION__)); | |||
6719 | ||||
6720 | getCurFunction()->setHasBranchProtectedScope(); | |||
6721 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, | |||
6722 | NestedLoopCount, Clauses, AStmt, B); | |||
6723 | } | |||
6724 | ||||
6725 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, | |||
6726 | SourceLocation StartLoc, | |||
6727 | SourceLocation LParenLoc, | |||
6728 | SourceLocation EndLoc) { | |||
6729 | OMPClause *Res = nullptr; | |||
6730 | switch (Kind) { | |||
6731 | case OMPC_final: | |||
6732 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); | |||
6733 | break; | |||
6734 | case OMPC_num_threads: | |||
6735 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); | |||
6736 | break; | |||
6737 | case OMPC_safelen: | |||
6738 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); | |||
6739 | break; | |||
6740 | case OMPC_simdlen: | |||
6741 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); | |||
6742 | break; | |||
6743 | case OMPC_collapse: | |||
6744 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); | |||
6745 | break; | |||
6746 | case OMPC_ordered: | |||
6747 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); | |||
6748 | break; | |||
6749 | case OMPC_device: | |||
6750 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); | |||
6751 | break; | |||
6752 | case OMPC_num_teams: | |||
6753 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); | |||
6754 | break; | |||
6755 | case OMPC_thread_limit: | |||
6756 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); | |||
6757 | break; | |||
6758 | case OMPC_priority: | |||
6759 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); | |||
6760 | break; | |||
6761 | case OMPC_grainsize: | |||
6762 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); | |||
6763 | break; | |||
6764 | case OMPC_num_tasks: | |||
6765 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); | |||
6766 | break; | |||
6767 | case OMPC_hint: | |||
6768 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); | |||
6769 | break; | |||
6770 | case OMPC_if: | |||
6771 | case OMPC_default: | |||
6772 | case OMPC_proc_bind: | |||
6773 | case OMPC_schedule: | |||
6774 | case OMPC_private: | |||
6775 | case OMPC_firstprivate: | |||
6776 | case OMPC_lastprivate: | |||
6777 | case OMPC_shared: | |||
6778 | case OMPC_reduction: | |||
6779 | case OMPC_linear: | |||
6780 | case OMPC_aligned: | |||
6781 | case OMPC_copyin: | |||
6782 | case OMPC_copyprivate: | |||
6783 | case OMPC_nowait: | |||
6784 | case OMPC_untied: | |||
6785 | case OMPC_mergeable: | |||
6786 | case OMPC_threadprivate: | |||
6787 | case OMPC_flush: | |||
6788 | case OMPC_read: | |||
6789 | case OMPC_write: | |||
6790 | case OMPC_update: | |||
6791 | case OMPC_capture: | |||
6792 | case OMPC_seq_cst: | |||
6793 | case OMPC_depend: | |||
6794 | case OMPC_threads: | |||
6795 | case OMPC_simd: | |||
6796 | case OMPC_map: | |||
6797 | case OMPC_nogroup: | |||
6798 | case OMPC_dist_schedule: | |||
6799 | case OMPC_defaultmap: | |||
6800 | case OMPC_unknown: | |||
6801 | case OMPC_uniform: | |||
6802 | case OMPC_to: | |||
6803 | case OMPC_from: | |||
6804 | llvm_unreachable("Clause is not allowed.")::llvm::llvm_unreachable_internal("Clause is not allowed.", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6804); | |||
6805 | } | |||
6806 | return Res; | |||
6807 | } | |||
6808 | ||||
6809 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, | |||
6810 | Expr *Condition, SourceLocation StartLoc, | |||
6811 | SourceLocation LParenLoc, | |||
6812 | SourceLocation NameModifierLoc, | |||
6813 | SourceLocation ColonLoc, | |||
6814 | SourceLocation EndLoc) { | |||
6815 | Expr *ValExpr = Condition; | |||
6816 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && | |||
6817 | !Condition->isInstantiationDependent() && | |||
6818 | !Condition->containsUnexpandedParameterPack()) { | |||
6819 | ExprResult Val = ActOnBooleanCondition(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurScope(), | |||
6820 | Condition->getExprLoc(), Condition); | |||
6821 | if (Val.isInvalid()) | |||
6822 | return nullptr; | |||
6823 | ||||
6824 | ValExpr = Val.get(); | |||
6825 | } | |||
6826 | ||||
6827 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, | |||
6828 | NameModifierLoc, ColonLoc, EndLoc); | |||
6829 | } | |||
6830 | ||||
6831 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, | |||
6832 | SourceLocation StartLoc, | |||
6833 | SourceLocation LParenLoc, | |||
6834 | SourceLocation EndLoc) { | |||
6835 | Expr *ValExpr = Condition; | |||
6836 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && | |||
6837 | !Condition->isInstantiationDependent() && | |||
6838 | !Condition->containsUnexpandedParameterPack()) { | |||
6839 | ExprResult Val = ActOnBooleanCondition(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurScope(), | |||
6840 | Condition->getExprLoc(), Condition); | |||
6841 | if (Val.isInvalid()) | |||
6842 | return nullptr; | |||
6843 | ||||
6844 | ValExpr = Val.get(); | |||
6845 | } | |||
6846 | ||||
6847 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); | |||
6848 | } | |||
6849 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, | |||
6850 | Expr *Op) { | |||
6851 | if (!Op) | |||
6852 | return ExprError(); | |||
6853 | ||||
6854 | class IntConvertDiagnoser : public ICEConvertDiagnoser { | |||
6855 | public: | |||
6856 | IntConvertDiagnoser() | |||
6857 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} | |||
6858 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, | |||
6859 | QualType T) override { | |||
6860 | return S.Diag(Loc, diag::err_omp_not_integral) << T; | |||
6861 | } | |||
6862 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, | |||
6863 | QualType T) override { | |||
6864 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; | |||
6865 | } | |||
6866 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, | |||
6867 | QualType T, | |||
6868 | QualType ConvTy) override { | |||
6869 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; | |||
6870 | } | |||
6871 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, | |||
6872 | QualType ConvTy) override { | |||
6873 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) | |||
6874 | << ConvTy->isEnumeralType() << ConvTy; | |||
6875 | } | |||
6876 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, | |||
6877 | QualType T) override { | |||
6878 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; | |||
6879 | } | |||
6880 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, | |||
6881 | QualType ConvTy) override { | |||
6882 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) | |||
6883 | << ConvTy->isEnumeralType() << ConvTy; | |||
6884 | } | |||
6885 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, | |||
6886 | QualType) override { | |||
6887 | llvm_unreachable("conversion functions are permitted")::llvm::llvm_unreachable_internal("conversion functions are permitted" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 6887); | |||
6888 | } | |||
6889 | } ConvertDiagnoser; | |||
6890 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); | |||
6891 | } | |||
6892 | ||||
6893 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, | |||
6894 | OpenMPClauseKind CKind, | |||
6895 | bool StrictlyPositive) { | |||
6896 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && | |||
6897 | !ValExpr->isInstantiationDependent()) { | |||
6898 | SourceLocation Loc = ValExpr->getExprLoc(); | |||
6899 | ExprResult Value = | |||
6900 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); | |||
6901 | if (Value.isInvalid()) | |||
6902 | return false; | |||
6903 | ||||
6904 | ValExpr = Value.get(); | |||
6905 | // The expression must evaluate to a non-negative integer value. | |||
6906 | llvm::APSInt Result; | |||
6907 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && | |||
6908 | Result.isSigned() && | |||
6909 | !((!StrictlyPositive && Result.isNonNegative()) || | |||
6910 | (StrictlyPositive && Result.isStrictlyPositive()))) { | |||
6911 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) | |||
6912 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) | |||
6913 | << ValExpr->getSourceRange(); | |||
6914 | return false; | |||
6915 | } | |||
6916 | } | |||
6917 | return true; | |||
6918 | } | |||
6919 | ||||
6920 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, | |||
6921 | SourceLocation StartLoc, | |||
6922 | SourceLocation LParenLoc, | |||
6923 | SourceLocation EndLoc) { | |||
6924 | Expr *ValExpr = NumThreads; | |||
6925 | ||||
6926 | // OpenMP [2.5, Restrictions] | |||
6927 | // The num_threads expression must evaluate to a positive integer value. | |||
6928 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, | |||
6929 | /*StrictlyPositive=*/true)) | |||
6930 | return nullptr; | |||
6931 | ||||
6932 | return new (Context) | |||
6933 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); | |||
6934 | } | |||
6935 | ||||
6936 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, | |||
6937 | OpenMPClauseKind CKind, | |||
6938 | bool StrictlyPositive) { | |||
6939 | if (!E) | |||
6940 | return ExprError(); | |||
6941 | if (E->isValueDependent() || E->isTypeDependent() || | |||
6942 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) | |||
6943 | return E; | |||
6944 | llvm::APSInt Result; | |||
6945 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); | |||
6946 | if (ICE.isInvalid()) | |||
6947 | return ExprError(); | |||
6948 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || | |||
6949 | (!StrictlyPositive && !Result.isNonNegative())) { | |||
6950 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) | |||
6951 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) | |||
6952 | << E->getSourceRange(); | |||
6953 | return ExprError(); | |||
6954 | } | |||
6955 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { | |||
6956 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) | |||
6957 | << E->getSourceRange(); | |||
6958 | return ExprError(); | |||
6959 | } | |||
6960 | if (CKind == OMPC_collapse && DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getAssociatedLoops() == 1) | |||
6961 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setAssociatedLoops(Result.getExtValue()); | |||
6962 | else if (CKind == OMPC_ordered) | |||
6963 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setAssociatedLoops(Result.getExtValue()); | |||
6964 | return ICE; | |||
6965 | } | |||
6966 | ||||
6967 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, | |||
6968 | SourceLocation LParenLoc, | |||
6969 | SourceLocation EndLoc) { | |||
6970 | // OpenMP [2.8.1, simd construct, Description] | |||
6971 | // The parameter of the safelen clause must be a constant | |||
6972 | // positive integer expression. | |||
6973 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); | |||
6974 | if (Safelen.isInvalid()) | |||
6975 | return nullptr; | |||
6976 | return new (Context) | |||
6977 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); | |||
6978 | } | |||
6979 | ||||
6980 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, | |||
6981 | SourceLocation LParenLoc, | |||
6982 | SourceLocation EndLoc) { | |||
6983 | // OpenMP [2.8.1, simd construct, Description] | |||
6984 | // The parameter of the simdlen clause must be a constant | |||
6985 | // positive integer expression. | |||
6986 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); | |||
6987 | if (Simdlen.isInvalid()) | |||
6988 | return nullptr; | |||
6989 | return new (Context) | |||
6990 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); | |||
6991 | } | |||
6992 | ||||
6993 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, | |||
6994 | SourceLocation StartLoc, | |||
6995 | SourceLocation LParenLoc, | |||
6996 | SourceLocation EndLoc) { | |||
6997 | // OpenMP [2.7.1, loop construct, Description] | |||
6998 | // OpenMP [2.8.1, simd construct, Description] | |||
6999 | // OpenMP [2.9.6, distribute construct, Description] | |||
7000 | // The parameter of the collapse clause must be a constant | |||
7001 | // positive integer expression. | |||
7002 | ExprResult NumForLoopsResult = | |||
7003 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); | |||
7004 | if (NumForLoopsResult.isInvalid()) | |||
7005 | return nullptr; | |||
7006 | return new (Context) | |||
7007 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); | |||
7008 | } | |||
7009 | ||||
7010 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, | |||
7011 | SourceLocation EndLoc, | |||
7012 | SourceLocation LParenLoc, | |||
7013 | Expr *NumForLoops) { | |||
7014 | // OpenMP [2.7.1, loop construct, Description] | |||
7015 | // OpenMP [2.8.1, simd construct, Description] | |||
7016 | // OpenMP [2.9.6, distribute construct, Description] | |||
7017 | // The parameter of the ordered clause must be a constant | |||
7018 | // positive integer expression if any. | |||
7019 | if (NumForLoops && LParenLoc.isValid()) { | |||
7020 | ExprResult NumForLoopsResult = | |||
7021 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); | |||
7022 | if (NumForLoopsResult.isInvalid()) | |||
7023 | return nullptr; | |||
7024 | NumForLoops = NumForLoopsResult.get(); | |||
7025 | } else | |||
7026 | NumForLoops = nullptr; | |||
7027 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); | |||
7028 | return new (Context) | |||
7029 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); | |||
7030 | } | |||
7031 | ||||
7032 | OMPClause *Sema::ActOnOpenMPSimpleClause( | |||
7033 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, | |||
7034 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { | |||
7035 | OMPClause *Res = nullptr; | |||
7036 | switch (Kind) { | |||
7037 | case OMPC_default: | |||
7038 | Res = | |||
7039 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), | |||
7040 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); | |||
7041 | break; | |||
7042 | case OMPC_proc_bind: | |||
7043 | Res = ActOnOpenMPProcBindClause( | |||
7044 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, | |||
7045 | LParenLoc, EndLoc); | |||
7046 | break; | |||
7047 | case OMPC_if: | |||
7048 | case OMPC_final: | |||
7049 | case OMPC_num_threads: | |||
7050 | case OMPC_safelen: | |||
7051 | case OMPC_simdlen: | |||
7052 | case OMPC_collapse: | |||
7053 | case OMPC_schedule: | |||
7054 | case OMPC_private: | |||
7055 | case OMPC_firstprivate: | |||
7056 | case OMPC_lastprivate: | |||
7057 | case OMPC_shared: | |||
7058 | case OMPC_reduction: | |||
7059 | case OMPC_linear: | |||
7060 | case OMPC_aligned: | |||
7061 | case OMPC_copyin: | |||
7062 | case OMPC_copyprivate: | |||
7063 | case OMPC_ordered: | |||
7064 | case OMPC_nowait: | |||
7065 | case OMPC_untied: | |||
7066 | case OMPC_mergeable: | |||
7067 | case OMPC_threadprivate: | |||
7068 | case OMPC_flush: | |||
7069 | case OMPC_read: | |||
7070 | case OMPC_write: | |||
7071 | case OMPC_update: | |||
7072 | case OMPC_capture: | |||
7073 | case OMPC_seq_cst: | |||
7074 | case OMPC_depend: | |||
7075 | case OMPC_device: | |||
7076 | case OMPC_threads: | |||
7077 | case OMPC_simd: | |||
7078 | case OMPC_map: | |||
7079 | case OMPC_num_teams: | |||
7080 | case OMPC_thread_limit: | |||
7081 | case OMPC_priority: | |||
7082 | case OMPC_grainsize: | |||
7083 | case OMPC_nogroup: | |||
7084 | case OMPC_num_tasks: | |||
7085 | case OMPC_hint: | |||
7086 | case OMPC_dist_schedule: | |||
7087 | case OMPC_defaultmap: | |||
7088 | case OMPC_unknown: | |||
7089 | case OMPC_uniform: | |||
7090 | case OMPC_to: | |||
7091 | case OMPC_from: | |||
7092 | llvm_unreachable("Clause is not allowed.")::llvm::llvm_unreachable_internal("Clause is not allowed.", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 7092); | |||
7093 | } | |||
7094 | return Res; | |||
7095 | } | |||
7096 | ||||
7097 | static std::string | |||
7098 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, | |||
7099 | ArrayRef<unsigned> Exclude = llvm::None) { | |||
7100 | std::string Values; | |||
7101 | unsigned Bound = Last >= 2 ? Last - 2 : 0; | |||
7102 | unsigned Skipped = Exclude.size(); | |||
7103 | auto S = Exclude.begin(), E = Exclude.end(); | |||
7104 | for (unsigned i = First; i < Last; ++i) { | |||
7105 | if (std::find(S, E, i) != E) { | |||
7106 | --Skipped; | |||
7107 | continue; | |||
7108 | } | |||
7109 | Values += "'"; | |||
7110 | Values += getOpenMPSimpleClauseTypeName(K, i); | |||
7111 | Values += "'"; | |||
7112 | if (i == Bound - Skipped) | |||
7113 | Values += " or "; | |||
7114 | else if (i != Bound + 1 - Skipped) | |||
7115 | Values += ", "; | |||
7116 | } | |||
7117 | return Values; | |||
7118 | } | |||
7119 | ||||
7120 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, | |||
7121 | SourceLocation KindKwLoc, | |||
7122 | SourceLocation StartLoc, | |||
7123 | SourceLocation LParenLoc, | |||
7124 | SourceLocation EndLoc) { | |||
7125 | if (Kind == OMPC_DEFAULT_unknown) { | |||
7126 | static_assert(OMPC_DEFAULT_unknown > 0, | |||
7127 | "OMPC_DEFAULT_unknown not greater than 0"); | |||
7128 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) | |||
7129 | << getListOfPossibleValues(OMPC_default, /*First=*/0, | |||
7130 | /*Last=*/OMPC_DEFAULT_unknown) | |||
7131 | << getOpenMPClauseName(OMPC_default); | |||
7132 | return nullptr; | |||
7133 | } | |||
7134 | switch (Kind) { | |||
7135 | case OMPC_DEFAULT_none: | |||
7136 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setDefaultDSANone(KindKwLoc); | |||
7137 | break; | |||
7138 | case OMPC_DEFAULT_shared: | |||
7139 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setDefaultDSAShared(KindKwLoc); | |||
7140 | break; | |||
7141 | case OMPC_DEFAULT_unknown: | |||
7142 | llvm_unreachable("Clause kind is not allowed.")::llvm::llvm_unreachable_internal("Clause kind is not allowed." , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 7142); | |||
7143 | break; | |||
7144 | } | |||
7145 | return new (Context) | |||
7146 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); | |||
7147 | } | |||
7148 | ||||
7149 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, | |||
7150 | SourceLocation KindKwLoc, | |||
7151 | SourceLocation StartLoc, | |||
7152 | SourceLocation LParenLoc, | |||
7153 | SourceLocation EndLoc) { | |||
7154 | if (Kind == OMPC_PROC_BIND_unknown) { | |||
7155 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) | |||
7156 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, | |||
7157 | /*Last=*/OMPC_PROC_BIND_unknown) | |||
7158 | << getOpenMPClauseName(OMPC_proc_bind); | |||
7159 | return nullptr; | |||
7160 | } | |||
7161 | return new (Context) | |||
7162 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); | |||
7163 | } | |||
7164 | ||||
7165 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( | |||
7166 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, | |||
7167 | SourceLocation StartLoc, SourceLocation LParenLoc, | |||
7168 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, | |||
7169 | SourceLocation EndLoc) { | |||
7170 | OMPClause *Res = nullptr; | |||
7171 | switch (Kind) { | |||
7172 | case OMPC_schedule: | |||
7173 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; | |||
7174 | assert(Argument.size() == NumberOfElements &&((Argument.size() == NumberOfElements && ArgumentLoc. size() == NumberOfElements) ? static_cast<void> (0) : __assert_fail ("Argument.size() == NumberOfElements && ArgumentLoc.size() == NumberOfElements" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 7175, __PRETTY_FUNCTION__)) | |||
7175 | ArgumentLoc.size() == NumberOfElements)((Argument.size() == NumberOfElements && ArgumentLoc. size() == NumberOfElements) ? static_cast<void> (0) : __assert_fail ("Argument.size() == NumberOfElements && ArgumentLoc.size() == NumberOfElements" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 7175, __PRETTY_FUNCTION__)); | |||
7176 | Res = ActOnOpenMPScheduleClause( | |||
7177 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), | |||
7178 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), | |||
7179 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, | |||
7180 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], | |||
7181 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); | |||
7182 | break; | |||
7183 | case OMPC_if: | |||
7184 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1)((Argument.size() == 1 && ArgumentLoc.size() == 1) ? static_cast <void> (0) : __assert_fail ("Argument.size() == 1 && ArgumentLoc.size() == 1" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 7184, __PRETTY_FUNCTION__)); | |||
7185 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), | |||
7186 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), | |||
7187 | DelimLoc, EndLoc); | |||
7188 | break; | |||
7189 | case OMPC_dist_schedule: | |||
7190 | Res = ActOnOpenMPDistScheduleClause( | |||
7191 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, | |||
7192 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); | |||
7193 | break; | |||
7194 | case OMPC_defaultmap: | |||
7195 | enum { Modifier, DefaultmapKind }; | |||
7196 | Res = ActOnOpenMPDefaultmapClause( | |||
7197 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), | |||
7198 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), | |||
7199 | StartLoc, LParenLoc, ArgumentLoc[Modifier], | |||
7200 | ArgumentLoc[DefaultmapKind], EndLoc); | |||
7201 | break; | |||
7202 | case OMPC_final: | |||
7203 | case OMPC_num_threads: | |||
7204 | case OMPC_safelen: | |||
7205 | case OMPC_simdlen: | |||
7206 | case OMPC_collapse: | |||
7207 | case OMPC_default: | |||
7208 | case OMPC_proc_bind: | |||
7209 | case OMPC_private: | |||
7210 | case OMPC_firstprivate: | |||
7211 | case OMPC_lastprivate: | |||
7212 | case OMPC_shared: | |||
7213 | case OMPC_reduction: | |||
7214 | case OMPC_linear: | |||
7215 | case OMPC_aligned: | |||
7216 | case OMPC_copyin: | |||
7217 | case OMPC_copyprivate: | |||
7218 | case OMPC_ordered: | |||
7219 | case OMPC_nowait: | |||
7220 | case OMPC_untied: | |||
7221 | case OMPC_mergeable: | |||
7222 | case OMPC_threadprivate: | |||
7223 | case OMPC_flush: | |||
7224 | case OMPC_read: | |||
7225 | case OMPC_write: | |||
7226 | case OMPC_update: | |||
7227 | case OMPC_capture: | |||
7228 | case OMPC_seq_cst: | |||
7229 | case OMPC_depend: | |||
7230 | case OMPC_device: | |||
7231 | case OMPC_threads: | |||
7232 | case OMPC_simd: | |||
7233 | case OMPC_map: | |||
7234 | case OMPC_num_teams: | |||
7235 | case OMPC_thread_limit: | |||
7236 | case OMPC_priority: | |||
7237 | case OMPC_grainsize: | |||
7238 | case OMPC_nogroup: | |||
7239 | case OMPC_num_tasks: | |||
7240 | case OMPC_hint: | |||
7241 | case OMPC_unknown: | |||
7242 | case OMPC_uniform: | |||
7243 | case OMPC_to: | |||
7244 | case OMPC_from: | |||
7245 | llvm_unreachable("Clause is not allowed.")::llvm::llvm_unreachable_internal("Clause is not allowed.", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 7245); | |||
7246 | } | |||
7247 | return Res; | |||
7248 | } | |||
7249 | ||||
7250 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, | |||
7251 | OpenMPScheduleClauseModifier M2, | |||
7252 | SourceLocation M1Loc, SourceLocation M2Loc) { | |||
7253 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { | |||
7254 | SmallVector<unsigned, 2> Excluded; | |||
7255 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) | |||
7256 | Excluded.push_back(M2); | |||
7257 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) | |||
7258 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); | |||
7259 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) | |||
7260 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); | |||
7261 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) | |||
7262 | << getListOfPossibleValues(OMPC_schedule, | |||
7263 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, | |||
7264 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, | |||
7265 | Excluded) | |||
7266 | << getOpenMPClauseName(OMPC_schedule); | |||
7267 | return true; | |||
7268 | } | |||
7269 | return false; | |||
7270 | } | |||
7271 | ||||
7272 | OMPClause *Sema::ActOnOpenMPScheduleClause( | |||
7273 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, | |||
7274 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, | |||
7275 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, | |||
7276 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { | |||
7277 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || | |||
7278 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) | |||
7279 | return nullptr; | |||
7280 | // OpenMP, 2.7.1, Loop Construct, Restrictions | |||
7281 | // Either the monotonic modifier or the nonmonotonic modifier can be specified | |||
7282 | // but not both. | |||
7283 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || | |||
7284 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && | |||
7285 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || | |||
7286 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && | |||
7287 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { | |||
7288 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) | |||
7289 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) | |||
7290 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); | |||
7291 | return nullptr; | |||
7292 | } | |||
7293 | if (Kind == OMPC_SCHEDULE_unknown) { | |||
7294 | std::string Values; | |||
7295 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { | |||
7296 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; | |||
7297 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, | |||
7298 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, | |||
7299 | Exclude); | |||
7300 | } else { | |||
7301 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, | |||
7302 | /*Last=*/OMPC_SCHEDULE_unknown); | |||
7303 | } | |||
7304 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) | |||
7305 | << Values << getOpenMPClauseName(OMPC_schedule); | |||
7306 | return nullptr; | |||
7307 | } | |||
7308 | // OpenMP, 2.7.1, Loop Construct, Restrictions | |||
7309 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or | |||
7310 | // schedule(guided). | |||
7311 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || | |||
7312 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && | |||
7313 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { | |||
7314 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, | |||
7315 | diag::err_omp_schedule_nonmonotonic_static); | |||
7316 | return nullptr; | |||
7317 | } | |||
7318 | Expr *ValExpr = ChunkSize; | |||
7319 | Stmt *HelperValStmt = nullptr; | |||
7320 | if (ChunkSize) { | |||
7321 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && | |||
7322 | !ChunkSize->isInstantiationDependent() && | |||
7323 | !ChunkSize->containsUnexpandedParameterPack()) { | |||
7324 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); | |||
7325 | ExprResult Val = | |||
7326 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); | |||
7327 | if (Val.isInvalid()) | |||
7328 | return nullptr; | |||
7329 | ||||
7330 | ValExpr = Val.get(); | |||
7331 | ||||
7332 | // OpenMP [2.7.1, Restrictions] | |||
7333 | // chunk_size must be a loop invariant integer expression with a positive | |||
7334 | // value. | |||
7335 | llvm::APSInt Result; | |||
7336 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { | |||
7337 | if (Result.isSigned() && !Result.isStrictlyPositive()) { | |||
7338 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) | |||
7339 | << "schedule" << 1 << ChunkSize->getSourceRange(); | |||
7340 | return nullptr; | |||
7341 | } | |||
7342 | } else if (isParallelOrTaskRegion(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) { | |||
7343 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; | |||
7344 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); | |||
7345 | HelperValStmt = buildPreInits(Context, Captures); | |||
7346 | } | |||
7347 | } | |||
7348 | } | |||
7349 | ||||
7350 | return new (Context) | |||
7351 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, | |||
7352 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); | |||
7353 | } | |||
7354 | ||||
7355 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, | |||
7356 | SourceLocation StartLoc, | |||
7357 | SourceLocation EndLoc) { | |||
7358 | OMPClause *Res = nullptr; | |||
7359 | switch (Kind) { | |||
7360 | case OMPC_ordered: | |||
7361 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); | |||
7362 | break; | |||
7363 | case OMPC_nowait: | |||
7364 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); | |||
7365 | break; | |||
7366 | case OMPC_untied: | |||
7367 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); | |||
7368 | break; | |||
7369 | case OMPC_mergeable: | |||
7370 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); | |||
7371 | break; | |||
7372 | case OMPC_read: | |||
7373 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); | |||
7374 | break; | |||
7375 | case OMPC_write: | |||
7376 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); | |||
7377 | break; | |||
7378 | case OMPC_update: | |||
7379 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); | |||
7380 | break; | |||
7381 | case OMPC_capture: | |||
7382 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); | |||
7383 | break; | |||
7384 | case OMPC_seq_cst: | |||
7385 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); | |||
7386 | break; | |||
7387 | case OMPC_threads: | |||
7388 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); | |||
7389 | break; | |||
7390 | case OMPC_simd: | |||
7391 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); | |||
7392 | break; | |||
7393 | case OMPC_nogroup: | |||
7394 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); | |||
7395 | break; | |||
7396 | case OMPC_if: | |||
7397 | case OMPC_final: | |||
7398 | case OMPC_num_threads: | |||
7399 | case OMPC_safelen: | |||
7400 | case OMPC_simdlen: | |||
7401 | case OMPC_collapse: | |||
7402 | case OMPC_schedule: | |||
7403 | case OMPC_private: | |||
7404 | case OMPC_firstprivate: | |||
7405 | case OMPC_lastprivate: | |||
7406 | case OMPC_shared: | |||
7407 | case OMPC_reduction: | |||
7408 | case OMPC_linear: | |||
7409 | case OMPC_aligned: | |||
7410 | case OMPC_copyin: | |||
7411 | case OMPC_copyprivate: | |||
7412 | case OMPC_default: | |||
7413 | case OMPC_proc_bind: | |||
7414 | case OMPC_threadprivate: | |||
7415 | case OMPC_flush: | |||
7416 | case OMPC_depend: | |||
7417 | case OMPC_device: | |||
7418 | case OMPC_map: | |||
7419 | case OMPC_num_teams: | |||
7420 | case OMPC_thread_limit: | |||
7421 | case OMPC_priority: | |||
7422 | case OMPC_grainsize: | |||
7423 | case OMPC_num_tasks: | |||
7424 | case OMPC_hint: | |||
7425 | case OMPC_dist_schedule: | |||
7426 | case OMPC_defaultmap: | |||
7427 | case OMPC_unknown: | |||
7428 | case OMPC_uniform: | |||
7429 | case OMPC_to: | |||
7430 | case OMPC_from: | |||
7431 | llvm_unreachable("Clause is not allowed.")::llvm::llvm_unreachable_internal("Clause is not allowed.", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 7431); | |||
7432 | } | |||
7433 | return Res; | |||
7434 | } | |||
7435 | ||||
7436 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, | |||
7437 | SourceLocation EndLoc) { | |||
7438 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setNowaitRegion(); | |||
7439 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); | |||
7440 | } | |||
7441 | ||||
7442 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, | |||
7443 | SourceLocation EndLoc) { | |||
7444 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); | |||
7445 | } | |||
7446 | ||||
7447 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, | |||
7448 | SourceLocation EndLoc) { | |||
7449 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); | |||
7450 | } | |||
7451 | ||||
7452 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, | |||
7453 | SourceLocation EndLoc) { | |||
7454 | return new (Context) OMPReadClause(StartLoc, EndLoc); | |||
7455 | } | |||
7456 | ||||
7457 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, | |||
7458 | SourceLocation EndLoc) { | |||
7459 | return new (Context) OMPWriteClause(StartLoc, EndLoc); | |||
7460 | } | |||
7461 | ||||
7462 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, | |||
7463 | SourceLocation EndLoc) { | |||
7464 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); | |||
7465 | } | |||
7466 | ||||
7467 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, | |||
7468 | SourceLocation EndLoc) { | |||
7469 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); | |||
7470 | } | |||
7471 | ||||
7472 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, | |||
7473 | SourceLocation EndLoc) { | |||
7474 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); | |||
7475 | } | |||
7476 | ||||
7477 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, | |||
7478 | SourceLocation EndLoc) { | |||
7479 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); | |||
7480 | } | |||
7481 | ||||
7482 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, | |||
7483 | SourceLocation EndLoc) { | |||
7484 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); | |||
7485 | } | |||
7486 | ||||
7487 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, | |||
7488 | SourceLocation EndLoc) { | |||
7489 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); | |||
7490 | } | |||
7491 | ||||
7492 | OMPClause *Sema::ActOnOpenMPVarListClause( | |||
7493 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, | |||
7494 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, | |||
7495 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, | |||
7496 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, | |||
7497 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, | |||
7498 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, | |||
7499 | SourceLocation DepLinMapLoc) { | |||
7500 | OMPClause *Res = nullptr; | |||
7501 | switch (Kind) { | |||
7502 | case OMPC_private: | |||
7503 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); | |||
7504 | break; | |||
7505 | case OMPC_firstprivate: | |||
7506 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); | |||
7507 | break; | |||
7508 | case OMPC_lastprivate: | |||
7509 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); | |||
7510 | break; | |||
7511 | case OMPC_shared: | |||
7512 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); | |||
7513 | break; | |||
7514 | case OMPC_reduction: | |||
7515 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, | |||
7516 | EndLoc, ReductionIdScopeSpec, ReductionId); | |||
7517 | break; | |||
7518 | case OMPC_linear: | |||
7519 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, | |||
7520 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); | |||
7521 | break; | |||
7522 | case OMPC_aligned: | |||
7523 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, | |||
7524 | ColonLoc, EndLoc); | |||
7525 | break; | |||
7526 | case OMPC_copyin: | |||
7527 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); | |||
7528 | break; | |||
7529 | case OMPC_copyprivate: | |||
7530 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); | |||
7531 | break; | |||
7532 | case OMPC_flush: | |||
7533 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); | |||
7534 | break; | |||
7535 | case OMPC_depend: | |||
7536 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, | |||
7537 | StartLoc, LParenLoc, EndLoc); | |||
7538 | break; | |||
7539 | case OMPC_map: | |||
7540 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, | |||
7541 | DepLinMapLoc, ColonLoc, VarList, StartLoc, | |||
7542 | LParenLoc, EndLoc); | |||
7543 | break; | |||
7544 | case OMPC_to: | |||
7545 | Res = ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc); | |||
7546 | break; | |||
7547 | case OMPC_from: | |||
7548 | Res = ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc, EndLoc); | |||
7549 | break; | |||
7550 | case OMPC_if: | |||
7551 | case OMPC_final: | |||
7552 | case OMPC_num_threads: | |||
7553 | case OMPC_safelen: | |||
7554 | case OMPC_simdlen: | |||
7555 | case OMPC_collapse: | |||
7556 | case OMPC_default: | |||
7557 | case OMPC_proc_bind: | |||
7558 | case OMPC_schedule: | |||
7559 | case OMPC_ordered: | |||
7560 | case OMPC_nowait: | |||
7561 | case OMPC_untied: | |||
7562 | case OMPC_mergeable: | |||
7563 | case OMPC_threadprivate: | |||
7564 | case OMPC_read: | |||
7565 | case OMPC_write: | |||
7566 | case OMPC_update: | |||
7567 | case OMPC_capture: | |||
7568 | case OMPC_seq_cst: | |||
7569 | case OMPC_device: | |||
7570 | case OMPC_threads: | |||
7571 | case OMPC_simd: | |||
7572 | case OMPC_num_teams: | |||
7573 | case OMPC_thread_limit: | |||
7574 | case OMPC_priority: | |||
7575 | case OMPC_grainsize: | |||
7576 | case OMPC_nogroup: | |||
7577 | case OMPC_num_tasks: | |||
7578 | case OMPC_hint: | |||
7579 | case OMPC_dist_schedule: | |||
7580 | case OMPC_defaultmap: | |||
7581 | case OMPC_unknown: | |||
7582 | case OMPC_uniform: | |||
7583 | llvm_unreachable("Clause is not allowed.")::llvm::llvm_unreachable_internal("Clause is not allowed.", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 7583); | |||
7584 | } | |||
7585 | return Res; | |||
7586 | } | |||
7587 | ||||
7588 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, | |||
7589 | ExprObjectKind OK, SourceLocation Loc) { | |||
7590 | ExprResult Res = BuildDeclRefExpr( | |||
7591 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); | |||
7592 | if (!Res.isUsable()) | |||
7593 | return ExprError(); | |||
7594 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { | |||
7595 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); | |||
7596 | if (!Res.isUsable()) | |||
7597 | return ExprError(); | |||
7598 | } | |||
7599 | if (VK != VK_LValue && Res.get()->isGLValue()) { | |||
7600 | Res = DefaultLvalueConversion(Res.get()); | |||
7601 | if (!Res.isUsable()) | |||
7602 | return ExprError(); | |||
7603 | } | |||
7604 | return Res; | |||
7605 | } | |||
7606 | ||||
7607 | static std::pair<ValueDecl *, bool> | |||
7608 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, | |||
7609 | SourceRange &ERange, bool AllowArraySection = false) { | |||
7610 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || | |||
7611 | RefExpr->containsUnexpandedParameterPack()) | |||
7612 | return std::make_pair(nullptr, true); | |||
7613 | ||||
7614 | // OpenMP [3.1, C/C++] | |||
7615 | // A list item is a variable name. | |||
7616 | // OpenMP [2.9.3.3, Restrictions, p.1] | |||
7617 | // A variable that is part of another variable (as an array or | |||
7618 | // structure element) cannot appear in a private clause. | |||
7619 | RefExpr = RefExpr->IgnoreParens(); | |||
7620 | enum { | |||
7621 | NoArrayExpr = -1, | |||
7622 | ArraySubscript = 0, | |||
7623 | OMPArraySection = 1 | |||
7624 | } IsArrayExpr = NoArrayExpr; | |||
7625 | if (AllowArraySection) { | |||
7626 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { | |||
7627 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); | |||
7628 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) | |||
7629 | Base = TempASE->getBase()->IgnoreParenImpCasts(); | |||
7630 | RefExpr = Base; | |||
7631 | IsArrayExpr = ArraySubscript; | |||
7632 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { | |||
7633 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); | |||
7634 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) | |||
7635 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); | |||
7636 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) | |||
7637 | Base = TempASE->getBase()->IgnoreParenImpCasts(); | |||
7638 | RefExpr = Base; | |||
7639 | IsArrayExpr = OMPArraySection; | |||
7640 | } | |||
7641 | } | |||
7642 | ELoc = RefExpr->getExprLoc(); | |||
7643 | ERange = RefExpr->getSourceRange(); | |||
7644 | RefExpr = RefExpr->IgnoreParenImpCasts(); | |||
7645 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); | |||
7646 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); | |||
7647 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && | |||
7648 | (S.getCurrentThisType().isNull() || !ME || | |||
7649 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || | |||
7650 | !isa<FieldDecl>(ME->getMemberDecl()))) { | |||
7651 | if (IsArrayExpr != NoArrayExpr) | |||
7652 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr | |||
7653 | << ERange; | |||
7654 | else { | |||
7655 | S.Diag(ELoc, | |||
7656 | AllowArraySection | |||
7657 | ? diag::err_omp_expected_var_name_member_expr_or_array_item | |||
7658 | : diag::err_omp_expected_var_name_member_expr) | |||
7659 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; | |||
7660 | } | |||
7661 | return std::make_pair(nullptr, false); | |||
7662 | } | |||
7663 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); | |||
7664 | } | |||
7665 | ||||
7666 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, | |||
7667 | SourceLocation StartLoc, | |||
7668 | SourceLocation LParenLoc, | |||
7669 | SourceLocation EndLoc) { | |||
7670 | SmallVector<Expr *, 8> Vars; | |||
7671 | SmallVector<Expr *, 8> PrivateCopies; | |||
7672 | for (auto &RefExpr : VarList) { | |||
7673 | assert(RefExpr && "NULL expr in OpenMP private clause.")((RefExpr && "NULL expr in OpenMP private clause.") ? static_cast<void> (0) : __assert_fail ("RefExpr && \"NULL expr in OpenMP private clause.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 7673, __PRETTY_FUNCTION__)); | |||
7674 | SourceLocation ELoc; | |||
7675 | SourceRange ERange; | |||
7676 | Expr *SimpleRefExpr = RefExpr; | |||
7677 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); | |||
7678 | if (Res.second) { | |||
7679 | // It will be analyzed later. | |||
7680 | Vars.push_back(RefExpr); | |||
7681 | PrivateCopies.push_back(nullptr); | |||
7682 | } | |||
7683 | ValueDecl *D = Res.first; | |||
7684 | if (!D) | |||
7685 | continue; | |||
7686 | ||||
7687 | QualType Type = D->getType(); | |||
7688 | auto *VD = dyn_cast<VarDecl>(D); | |||
7689 | ||||
7690 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] | |||
7691 | // A variable that appears in a private clause must not have an incomplete | |||
7692 | // type or a reference type. | |||
7693 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) | |||
7694 | continue; | |||
7695 | Type = Type.getNonReferenceType(); | |||
7696 | ||||
7697 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
7698 | // in a Construct] | |||
7699 | // Variables with the predetermined data-sharing attributes may not be | |||
7700 | // listed in data-sharing attributes clauses, except for the cases | |||
7701 | // listed below. For these exceptions only, listing a predetermined | |||
7702 | // variable in a data-sharing attribute clause is allowed and overrides | |||
7703 | // the variable's predetermined data-sharing attributes. | |||
7704 | DSAStackTy::DSAVarData DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, false); | |||
7705 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { | |||
7706 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) | |||
7707 | << getOpenMPClauseName(OMPC_private); | |||
7708 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
7709 | continue; | |||
7710 | } | |||
7711 | ||||
7712 | // Variably modified types are not supported for tasks. | |||
7713 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && | |||
7714 | isOpenMPTaskingDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) { | |||
7715 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) | |||
7716 | << getOpenMPClauseName(OMPC_private) << Type | |||
7717 | << getOpenMPDirectiveName(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()); | |||
7718 | bool IsDecl = | |||
7719 | !VD || | |||
7720 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
7721 | Diag(D->getLocation(), | |||
7722 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
7723 | << D; | |||
7724 | continue; | |||
7725 | } | |||
7726 | ||||
7727 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] | |||
7728 | // A list item cannot appear in both a map clause and a data-sharing | |||
7729 | // attribute clause on the same construct | |||
7730 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective() == OMPD_target) { | |||
7731 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->checkMappableExprComponentListsForDecl( | |||
7732 | VD, /* CurrentRegionOnly = */ true, | |||
7733 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef) | |||
7734 | -> bool { return true; })) { | |||
7735 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) | |||
7736 | << getOpenMPClauseName(OMPC_private) | |||
7737 | << getOpenMPDirectiveName(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()); | |||
7738 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
7739 | continue; | |||
7740 | } | |||
7741 | } | |||
7742 | ||||
7743 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] | |||
7744 | // A variable of class type (or array thereof) that appears in a private | |||
7745 | // clause requires an accessible, unambiguous default constructor for the | |||
7746 | // class type. | |||
7747 | // Generate helper private variable and initialize it with the default | |||
7748 | // value. The address of the original variable is replaced by the address of | |||
7749 | // the new private variable in CodeGen. This new variable is not added to | |||
7750 | // IdResolver, so the code in the OpenMP region uses original variable for | |||
7751 | // proper diagnostics. | |||
7752 | Type = Type.getUnqualifiedType(); | |||
7753 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), | |||
7754 | D->hasAttrs() ? &D->getAttrs() : nullptr); | |||
7755 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); | |||
7756 | if (VDPrivate->isInvalidDecl()) | |||
7757 | continue; | |||
7758 | auto VDPrivateRefExpr = buildDeclRefExpr( | |||
7759 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); | |||
7760 | ||||
7761 | DeclRefExpr *Ref = nullptr; | |||
7762 | if (!VD) | |||
7763 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); | |||
7764 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); | |||
7765 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); | |||
7766 | PrivateCopies.push_back(VDPrivateRefExpr); | |||
7767 | } | |||
7768 | ||||
7769 | if (Vars.empty()) | |||
7770 | return nullptr; | |||
7771 | ||||
7772 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, | |||
7773 | PrivateCopies); | |||
7774 | } | |||
7775 | ||||
7776 | namespace { | |||
7777 | class DiagsUninitializedSeveretyRAII { | |||
7778 | private: | |||
7779 | DiagnosticsEngine &Diags; | |||
7780 | SourceLocation SavedLoc; | |||
7781 | bool IsIgnored; | |||
7782 | ||||
7783 | public: | |||
7784 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, | |||
7785 | bool IsIgnored) | |||
7786 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { | |||
7787 | if (!IsIgnored) { | |||
7788 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, | |||
7789 | /*Map*/ diag::Severity::Ignored, Loc); | |||
7790 | } | |||
7791 | } | |||
7792 | ~DiagsUninitializedSeveretyRAII() { | |||
7793 | if (!IsIgnored) | |||
7794 | Diags.popMappings(SavedLoc); | |||
7795 | } | |||
7796 | }; | |||
7797 | } | |||
7798 | ||||
7799 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, | |||
7800 | SourceLocation StartLoc, | |||
7801 | SourceLocation LParenLoc, | |||
7802 | SourceLocation EndLoc) { | |||
7803 | SmallVector<Expr *, 8> Vars; | |||
7804 | SmallVector<Expr *, 8> PrivateCopies; | |||
7805 | SmallVector<Expr *, 8> Inits; | |||
7806 | SmallVector<Decl *, 4> ExprCaptures; | |||
7807 | bool IsImplicitClause = | |||
7808 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); | |||
7809 | auto ImplicitClauseLoc = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(); | |||
7810 | ||||
7811 | for (auto &RefExpr : VarList) { | |||
7812 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause.")((RefExpr && "NULL expr in OpenMP firstprivate clause." ) ? static_cast<void> (0) : __assert_fail ("RefExpr && \"NULL expr in OpenMP firstprivate clause.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 7812, __PRETTY_FUNCTION__)); | |||
7813 | SourceLocation ELoc; | |||
7814 | SourceRange ERange; | |||
7815 | Expr *SimpleRefExpr = RefExpr; | |||
7816 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); | |||
7817 | if (Res.second) { | |||
7818 | // It will be analyzed later. | |||
7819 | Vars.push_back(RefExpr); | |||
7820 | PrivateCopies.push_back(nullptr); | |||
7821 | Inits.push_back(nullptr); | |||
7822 | } | |||
7823 | ValueDecl *D = Res.first; | |||
7824 | if (!D) | |||
7825 | continue; | |||
7826 | ||||
7827 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; | |||
7828 | QualType Type = D->getType(); | |||
7829 | auto *VD = dyn_cast<VarDecl>(D); | |||
7830 | ||||
7831 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] | |||
7832 | // A variable that appears in a private clause must not have an incomplete | |||
7833 | // type or a reference type. | |||
7834 | if (RequireCompleteType(ELoc, Type, | |||
7835 | diag::err_omp_firstprivate_incomplete_type)) | |||
7836 | continue; | |||
7837 | Type = Type.getNonReferenceType(); | |||
7838 | ||||
7839 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] | |||
7840 | // A variable of class type (or array thereof) that appears in a private | |||
7841 | // clause requires an accessible, unambiguous copy constructor for the | |||
7842 | // class type. | |||
7843 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); | |||
7844 | ||||
7845 | // If an implicit firstprivate variable found it was checked already. | |||
7846 | DSAStackTy::DSAVarData TopDVar; | |||
7847 | if (!IsImplicitClause) { | |||
7848 | DSAStackTy::DSAVarData DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, false); | |||
7849 | TopDVar = DVar; | |||
7850 | bool IsConstant = ElemType.isConstant(Context); | |||
7851 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] | |||
7852 | // A list item that specifies a given variable may not appear in more | |||
7853 | // than one clause on the same directive, except that a variable may be | |||
7854 | // specified in both firstprivate and lastprivate clauses. | |||
7855 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && | |||
7856 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { | |||
7857 | Diag(ELoc, diag::err_omp_wrong_dsa) | |||
7858 | << getOpenMPClauseName(DVar.CKind) | |||
7859 | << getOpenMPClauseName(OMPC_firstprivate); | |||
7860 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
7861 | continue; | |||
7862 | } | |||
7863 | ||||
7864 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
7865 | // in a Construct] | |||
7866 | // Variables with the predetermined data-sharing attributes may not be | |||
7867 | // listed in data-sharing attributes clauses, except for the cases | |||
7868 | // listed below. For these exceptions only, listing a predetermined | |||
7869 | // variable in a data-sharing attribute clause is allowed and overrides | |||
7870 | // the variable's predetermined data-sharing attributes. | |||
7871 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
7872 | // in a Construct, C/C++, p.2] | |||
7873 | // Variables with const-qualified type having no mutable member may be | |||
7874 | // listed in a firstprivate clause, even if they are static data members. | |||
7875 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && | |||
7876 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { | |||
7877 | Diag(ELoc, diag::err_omp_wrong_dsa) | |||
7878 | << getOpenMPClauseName(DVar.CKind) | |||
7879 | << getOpenMPClauseName(OMPC_firstprivate); | |||
7880 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
7881 | continue; | |||
7882 | } | |||
7883 | ||||
7884 | OpenMPDirectiveKind CurrDir = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective(); | |||
7885 | // OpenMP [2.9.3.4, Restrictions, p.2] | |||
7886 | // A list item that is private within a parallel region must not appear | |||
7887 | // in a firstprivate clause on a worksharing construct if any of the | |||
7888 | // worksharing regions arising from the worksharing construct ever bind | |||
7889 | // to any of the parallel regions arising from the parallel construct. | |||
7890 | if (isOpenMPWorksharingDirective(CurrDir) && | |||
7891 | !isOpenMPParallelDirective(CurrDir)) { | |||
7892 | DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getImplicitDSA(D, true); | |||
7893 | if (DVar.CKind != OMPC_shared && | |||
7894 | (isOpenMPParallelDirective(DVar.DKind) || | |||
7895 | DVar.DKind == OMPD_unknown)) { | |||
7896 | Diag(ELoc, diag::err_omp_required_access) | |||
7897 | << getOpenMPClauseName(OMPC_firstprivate) | |||
7898 | << getOpenMPClauseName(OMPC_shared); | |||
7899 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
7900 | continue; | |||
7901 | } | |||
7902 | } | |||
7903 | // OpenMP [2.9.3.4, Restrictions, p.3] | |||
7904 | // A list item that appears in a reduction clause of a parallel construct | |||
7905 | // must not appear in a firstprivate clause on a worksharing or task | |||
7906 | // construct if any of the worksharing or task regions arising from the | |||
7907 | // worksharing or task construct ever bind to any of the parallel regions | |||
7908 | // arising from the parallel construct. | |||
7909 | // OpenMP [2.9.3.4, Restrictions, p.4] | |||
7910 | // A list item that appears in a reduction clause in worksharing | |||
7911 | // construct must not appear in a firstprivate clause in a task construct | |||
7912 | // encountered during execution of any of the worksharing regions arising | |||
7913 | // from the worksharing construct. | |||
7914 | if (isOpenMPTaskingDirective(CurrDir)) { | |||
7915 | DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasInnermostDSA( | |||
7916 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, | |||
7917 | [](OpenMPDirectiveKind K) -> bool { | |||
7918 | return isOpenMPParallelDirective(K) || | |||
7919 | isOpenMPWorksharingDirective(K); | |||
7920 | }, | |||
7921 | false); | |||
7922 | if (DVar.CKind == OMPC_reduction && | |||
7923 | (isOpenMPParallelDirective(DVar.DKind) || | |||
7924 | isOpenMPWorksharingDirective(DVar.DKind))) { | |||
7925 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) | |||
7926 | << getOpenMPDirectiveName(DVar.DKind); | |||
7927 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
7928 | continue; | |||
7929 | } | |||
7930 | } | |||
7931 | ||||
7932 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] | |||
7933 | // A list item that is private within a teams region must not appear in a | |||
7934 | // firstprivate clause on a distribute construct if any of the distribute | |||
7935 | // regions arising from the distribute construct ever bind to any of the | |||
7936 | // teams regions arising from the teams construct. | |||
7937 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] | |||
7938 | // A list item that appears in a reduction clause of a teams construct | |||
7939 | // must not appear in a firstprivate clause on a distribute construct if | |||
7940 | // any of the distribute regions arising from the distribute construct | |||
7941 | // ever bind to any of the teams regions arising from the teams construct. | |||
7942 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] | |||
7943 | // A list item may appear in a firstprivate or lastprivate clause but not | |||
7944 | // both. | |||
7945 | if (CurrDir == OMPD_distribute) { | |||
7946 | DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasInnermostDSA( | |||
7947 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_private; }, | |||
7948 | [](OpenMPDirectiveKind K) -> bool { | |||
7949 | return isOpenMPTeamsDirective(K); | |||
7950 | }, | |||
7951 | false); | |||
7952 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { | |||
7953 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); | |||
7954 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
7955 | continue; | |||
7956 | } | |||
7957 | DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasInnermostDSA( | |||
7958 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, | |||
7959 | [](OpenMPDirectiveKind K) -> bool { | |||
7960 | return isOpenMPTeamsDirective(K); | |||
7961 | }, | |||
7962 | false); | |||
7963 | if (DVar.CKind == OMPC_reduction && | |||
7964 | isOpenMPTeamsDirective(DVar.DKind)) { | |||
7965 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); | |||
7966 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
7967 | continue; | |||
7968 | } | |||
7969 | DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, false); | |||
7970 | if (DVar.CKind == OMPC_lastprivate) { | |||
7971 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); | |||
7972 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
7973 | continue; | |||
7974 | } | |||
7975 | } | |||
7976 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] | |||
7977 | // A list item cannot appear in both a map clause and a data-sharing | |||
7978 | // attribute clause on the same construct | |||
7979 | if (CurrDir == OMPD_target) { | |||
7980 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->checkMappableExprComponentListsForDecl( | |||
7981 | VD, /* CurrentRegionOnly = */ true, | |||
7982 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef) | |||
7983 | -> bool { return true; })) { | |||
7984 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) | |||
7985 | << getOpenMPClauseName(OMPC_firstprivate) | |||
7986 | << getOpenMPDirectiveName(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()); | |||
7987 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
7988 | continue; | |||
7989 | } | |||
7990 | } | |||
7991 | } | |||
7992 | ||||
7993 | // Variably modified types are not supported for tasks. | |||
7994 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && | |||
7995 | isOpenMPTaskingDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) { | |||
7996 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) | |||
7997 | << getOpenMPClauseName(OMPC_firstprivate) << Type | |||
7998 | << getOpenMPDirectiveName(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()); | |||
7999 | bool IsDecl = | |||
8000 | !VD || | |||
8001 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
8002 | Diag(D->getLocation(), | |||
8003 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
8004 | << D; | |||
8005 | continue; | |||
8006 | } | |||
8007 | ||||
8008 | Type = Type.getUnqualifiedType(); | |||
8009 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), | |||
8010 | D->hasAttrs() ? &D->getAttrs() : nullptr); | |||
8011 | // Generate helper private variable and initialize it with the value of the | |||
8012 | // original variable. The address of the original variable is replaced by | |||
8013 | // the address of the new private variable in the CodeGen. This new variable | |||
8014 | // is not added to IdResolver, so the code in the OpenMP region uses | |||
8015 | // original variable for proper diagnostics and variable capturing. | |||
8016 | Expr *VDInitRefExpr = nullptr; | |||
8017 | // For arrays generate initializer for single element and replace it by the | |||
8018 | // original array element in CodeGen. | |||
8019 | if (Type->isArrayType()) { | |||
8020 | auto VDInit = | |||
8021 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); | |||
8022 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); | |||
8023 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); | |||
8024 | ElemType = ElemType.getUnqualifiedType(); | |||
8025 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, | |||
8026 | ".firstprivate.temp"); | |||
8027 | InitializedEntity Entity = | |||
8028 | InitializedEntity::InitializeVariable(VDInitTemp); | |||
8029 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); | |||
8030 | ||||
8031 | InitializationSequence InitSeq(*this, Entity, Kind, Init); | |||
8032 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); | |||
8033 | if (Result.isInvalid()) | |||
8034 | VDPrivate->setInvalidDecl(); | |||
8035 | else | |||
8036 | VDPrivate->setInit(Result.getAs<Expr>()); | |||
8037 | // Remove temp variable declaration. | |||
8038 | Context.Deallocate(VDInitTemp); | |||
8039 | } else { | |||
8040 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, | |||
8041 | ".firstprivate.temp"); | |||
8042 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), | |||
8043 | RefExpr->getExprLoc()); | |||
8044 | AddInitializerToDecl(VDPrivate, | |||
8045 | DefaultLvalueConversion(VDInitRefExpr).get(), | |||
8046 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); | |||
8047 | } | |||
8048 | if (VDPrivate->isInvalidDecl()) { | |||
8049 | if (IsImplicitClause) { | |||
8050 | Diag(RefExpr->getExprLoc(), | |||
8051 | diag::note_omp_task_predetermined_firstprivate_here); | |||
8052 | } | |||
8053 | continue; | |||
8054 | } | |||
8055 | CurContext->addDecl(VDPrivate); | |||
8056 | auto VDPrivateRefExpr = buildDeclRefExpr( | |||
8057 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), | |||
8058 | RefExpr->getExprLoc()); | |||
8059 | DeclRefExpr *Ref = nullptr; | |||
8060 | if (!VD) { | |||
8061 | if (TopDVar.CKind == OMPC_lastprivate) | |||
8062 | Ref = TopDVar.PrivateCopy; | |||
8063 | else { | |||
8064 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); | |||
8065 | if (!IsOpenMPCapturedDecl(D)) | |||
8066 | ExprCaptures.push_back(Ref->getDecl()); | |||
8067 | } | |||
8068 | } | |||
8069 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); | |||
8070 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); | |||
8071 | PrivateCopies.push_back(VDPrivateRefExpr); | |||
8072 | Inits.push_back(VDInitRefExpr); | |||
8073 | } | |||
8074 | ||||
8075 | if (Vars.empty()) | |||
8076 | return nullptr; | |||
8077 | ||||
8078 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, | |||
8079 | Vars, PrivateCopies, Inits, | |||
8080 | buildPreInits(Context, ExprCaptures)); | |||
8081 | } | |||
8082 | ||||
8083 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, | |||
8084 | SourceLocation StartLoc, | |||
8085 | SourceLocation LParenLoc, | |||
8086 | SourceLocation EndLoc) { | |||
8087 | SmallVector<Expr *, 8> Vars; | |||
8088 | SmallVector<Expr *, 8> SrcExprs; | |||
8089 | SmallVector<Expr *, 8> DstExprs; | |||
8090 | SmallVector<Expr *, 8> AssignmentOps; | |||
8091 | SmallVector<Decl *, 4> ExprCaptures; | |||
8092 | SmallVector<Expr *, 4> ExprPostUpdates; | |||
8093 | for (auto &RefExpr : VarList) { | |||
8094 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause.")((RefExpr && "NULL expr in OpenMP lastprivate clause." ) ? static_cast<void> (0) : __assert_fail ("RefExpr && \"NULL expr in OpenMP lastprivate clause.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 8094, __PRETTY_FUNCTION__)); | |||
8095 | SourceLocation ELoc; | |||
8096 | SourceRange ERange; | |||
8097 | Expr *SimpleRefExpr = RefExpr; | |||
8098 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); | |||
8099 | if (Res.second) { | |||
8100 | // It will be analyzed later. | |||
8101 | Vars.push_back(RefExpr); | |||
8102 | SrcExprs.push_back(nullptr); | |||
8103 | DstExprs.push_back(nullptr); | |||
8104 | AssignmentOps.push_back(nullptr); | |||
8105 | } | |||
8106 | ValueDecl *D = Res.first; | |||
8107 | if (!D) | |||
8108 | continue; | |||
8109 | ||||
8110 | QualType Type = D->getType(); | |||
8111 | auto *VD = dyn_cast<VarDecl>(D); | |||
8112 | ||||
8113 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] | |||
8114 | // A variable that appears in a lastprivate clause must not have an | |||
8115 | // incomplete type or a reference type. | |||
8116 | if (RequireCompleteType(ELoc, Type, | |||
8117 | diag::err_omp_lastprivate_incomplete_type)) | |||
8118 | continue; | |||
8119 | Type = Type.getNonReferenceType(); | |||
8120 | ||||
8121 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
8122 | // in a Construct] | |||
8123 | // Variables with the predetermined data-sharing attributes may not be | |||
8124 | // listed in data-sharing attributes clauses, except for the cases | |||
8125 | // listed below. | |||
8126 | DSAStackTy::DSAVarData DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, false); | |||
8127 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && | |||
8128 | DVar.CKind != OMPC_firstprivate && | |||
8129 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { | |||
8130 | Diag(ELoc, diag::err_omp_wrong_dsa) | |||
8131 | << getOpenMPClauseName(DVar.CKind) | |||
8132 | << getOpenMPClauseName(OMPC_lastprivate); | |||
8133 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
8134 | continue; | |||
8135 | } | |||
8136 | ||||
8137 | OpenMPDirectiveKind CurrDir = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective(); | |||
8138 | // OpenMP [2.14.3.5, Restrictions, p.2] | |||
8139 | // A list item that is private within a parallel region, or that appears in | |||
8140 | // the reduction clause of a parallel construct, must not appear in a | |||
8141 | // lastprivate clause on a worksharing construct if any of the corresponding | |||
8142 | // worksharing regions ever binds to any of the corresponding parallel | |||
8143 | // regions. | |||
8144 | DSAStackTy::DSAVarData TopDVar = DVar; | |||
8145 | if (isOpenMPWorksharingDirective(CurrDir) && | |||
8146 | !isOpenMPParallelDirective(CurrDir)) { | |||
8147 | DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getImplicitDSA(D, true); | |||
8148 | if (DVar.CKind != OMPC_shared) { | |||
8149 | Diag(ELoc, diag::err_omp_required_access) | |||
8150 | << getOpenMPClauseName(OMPC_lastprivate) | |||
8151 | << getOpenMPClauseName(OMPC_shared); | |||
8152 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
8153 | continue; | |||
8154 | } | |||
8155 | } | |||
8156 | ||||
8157 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] | |||
8158 | // A list item may appear in a firstprivate or lastprivate clause but not | |||
8159 | // both. | |||
8160 | if (CurrDir == OMPD_distribute) { | |||
8161 | DSAStackTy::DSAVarData DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, false); | |||
8162 | if (DVar.CKind == OMPC_firstprivate) { | |||
8163 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); | |||
8164 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
8165 | continue; | |||
8166 | } | |||
8167 | } | |||
8168 | ||||
8169 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] | |||
8170 | // A variable of class type (or array thereof) that appears in a | |||
8171 | // lastprivate clause requires an accessible, unambiguous default | |||
8172 | // constructor for the class type, unless the list item is also specified | |||
8173 | // in a firstprivate clause. | |||
8174 | // A variable of class type (or array thereof) that appears in a | |||
8175 | // lastprivate clause requires an accessible, unambiguous copy assignment | |||
8176 | // operator for the class type. | |||
8177 | Type = Context.getBaseElementType(Type).getNonReferenceType(); | |||
8178 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), | |||
8179 | Type.getUnqualifiedType(), ".lastprivate.src", | |||
8180 | D->hasAttrs() ? &D->getAttrs() : nullptr); | |||
8181 | auto *PseudoSrcExpr = | |||
8182 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); | |||
8183 | auto *DstVD = | |||
8184 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", | |||
8185 | D->hasAttrs() ? &D->getAttrs() : nullptr); | |||
8186 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); | |||
8187 | // For arrays generate assignment operation for single element and replace | |||
8188 | // it by the original array element in CodeGen. | |||
8189 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, | |||
8190 | PseudoDstExpr, PseudoSrcExpr); | |||
8191 | if (AssignmentOp.isInvalid()) | |||
8192 | continue; | |||
8193 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, | |||
8194 | /*DiscardedValue=*/true); | |||
8195 | if (AssignmentOp.isInvalid()) | |||
8196 | continue; | |||
8197 | ||||
8198 | DeclRefExpr *Ref = nullptr; | |||
8199 | if (!VD) { | |||
8200 | if (TopDVar.CKind == OMPC_firstprivate) | |||
8201 | Ref = TopDVar.PrivateCopy; | |||
8202 | else { | |||
8203 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); | |||
8204 | if (!IsOpenMPCapturedDecl(D)) | |||
8205 | ExprCaptures.push_back(Ref->getDecl()); | |||
8206 | } | |||
8207 | if (TopDVar.CKind == OMPC_firstprivate || | |||
8208 | (!IsOpenMPCapturedDecl(D) && | |||
8209 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { | |||
8210 | ExprResult RefRes = DefaultLvalueConversion(Ref); | |||
8211 | if (!RefRes.isUsable()) | |||
8212 | continue; | |||
8213 | ExprResult PostUpdateRes = | |||
8214 | BuildBinOp(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, | |||
8215 | RefRes.get()); | |||
8216 | if (!PostUpdateRes.isUsable()) | |||
8217 | continue; | |||
8218 | ExprPostUpdates.push_back( | |||
8219 | IgnoredValueConversions(PostUpdateRes.get()).get()); | |||
8220 | } | |||
8221 | } | |||
8222 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); | |||
8223 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); | |||
8224 | SrcExprs.push_back(PseudoSrcExpr); | |||
8225 | DstExprs.push_back(PseudoDstExpr); | |||
8226 | AssignmentOps.push_back(AssignmentOp.get()); | |||
8227 | } | |||
8228 | ||||
8229 | if (Vars.empty()) | |||
8230 | return nullptr; | |||
8231 | ||||
8232 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, | |||
8233 | Vars, SrcExprs, DstExprs, AssignmentOps, | |||
8234 | buildPreInits(Context, ExprCaptures), | |||
8235 | buildPostUpdate(*this, ExprPostUpdates)); | |||
8236 | } | |||
8237 | ||||
8238 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, | |||
8239 | SourceLocation StartLoc, | |||
8240 | SourceLocation LParenLoc, | |||
8241 | SourceLocation EndLoc) { | |||
8242 | SmallVector<Expr *, 8> Vars; | |||
8243 | for (auto &RefExpr : VarList) { | |||
| ||||
8244 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause.")((RefExpr && "NULL expr in OpenMP lastprivate clause." ) ? static_cast<void> (0) : __assert_fail ("RefExpr && \"NULL expr in OpenMP lastprivate clause.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 8244, __PRETTY_FUNCTION__)); | |||
8245 | SourceLocation ELoc; | |||
8246 | SourceRange ERange; | |||
8247 | Expr *SimpleRefExpr = RefExpr; | |||
8248 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); | |||
8249 | if (Res.second) { | |||
8250 | // It will be analyzed later. | |||
8251 | Vars.push_back(RefExpr); | |||
8252 | } | |||
8253 | ValueDecl *D = Res.first; | |||
8254 | if (!D) | |||
8255 | continue; | |||
8256 | ||||
8257 | auto *VD = dyn_cast<VarDecl>(D); | |||
8258 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
8259 | // in a Construct] | |||
8260 | // Variables with the predetermined data-sharing attributes may not be | |||
8261 | // listed in data-sharing attributes clauses, except for the cases | |||
8262 | // listed below. For these exceptions only, listing a predetermined | |||
8263 | // variable in a data-sharing attribute clause is allowed and overrides | |||
8264 | // the variable's predetermined data-sharing attributes. | |||
8265 | DSAStackTy::DSAVarData DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, false); | |||
8266 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && | |||
8267 | DVar.RefExpr) { | |||
8268 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) | |||
8269 | << getOpenMPClauseName(OMPC_shared); | |||
8270 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
8271 | continue; | |||
8272 | } | |||
8273 | ||||
8274 | DeclRefExpr *Ref = nullptr; | |||
8275 | if (!VD && IsOpenMPCapturedDecl(D)) | |||
8276 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); | |||
8277 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); | |||
8278 | Vars.push_back((VD || !Ref) ? RefExpr->IgnoreParens() : Ref); | |||
8279 | } | |||
8280 | ||||
8281 | if (Vars.empty()) | |||
8282 | return nullptr; | |||
8283 | ||||
8284 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); | |||
8285 | } | |||
8286 | ||||
8287 | namespace { | |||
8288 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { | |||
8289 | DSAStackTy *Stack; | |||
8290 | ||||
8291 | public: | |||
8292 | bool VisitDeclRefExpr(DeclRefExpr *E) { | |||
8293 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { | |||
8294 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); | |||
8295 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) | |||
8296 | return false; | |||
8297 | if (DVar.CKind != OMPC_unknown) | |||
8298 | return true; | |||
8299 | DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA( | |||
8300 | VD, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, | |||
8301 | false); | |||
8302 | if (DVarPrivate.CKind != OMPC_unknown) | |||
8303 | return true; | |||
8304 | return false; | |||
8305 | } | |||
8306 | return false; | |||
8307 | } | |||
8308 | bool VisitStmt(Stmt *S) { | |||
8309 | for (auto Child : S->children()) { | |||
8310 | if (Child && Visit(Child)) | |||
8311 | return true; | |||
8312 | } | |||
8313 | return false; | |||
8314 | } | |||
8315 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} | |||
8316 | }; | |||
8317 | } // namespace | |||
8318 | ||||
8319 | namespace { | |||
8320 | // Transform MemberExpression for specified FieldDecl of current class to | |||
8321 | // DeclRefExpr to specified OMPCapturedExprDecl. | |||
8322 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { | |||
8323 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; | |||
8324 | ValueDecl *Field; | |||
8325 | DeclRefExpr *CapturedExpr; | |||
8326 | ||||
8327 | public: | |||
8328 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) | |||
8329 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} | |||
8330 | ||||
8331 | ExprResult TransformMemberExpr(MemberExpr *E) { | |||
8332 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && | |||
8333 | E->getMemberDecl() == Field) { | |||
8334 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); | |||
8335 | return CapturedExpr; | |||
8336 | } | |||
8337 | return BaseTransform::TransformMemberExpr(E); | |||
8338 | } | |||
8339 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } | |||
8340 | }; | |||
8341 | } // namespace | |||
8342 | ||||
8343 | template <typename T> | |||
8344 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, | |||
8345 | const llvm::function_ref<T(ValueDecl *)> &Gen) { | |||
8346 | for (auto &Set : Lookups) { | |||
8347 | for (auto *D : Set) { | |||
8348 | if (auto Res = Gen(cast<ValueDecl>(D))) | |||
8349 | return Res; | |||
8350 | } | |||
8351 | } | |||
8352 | return T(); | |||
8353 | } | |||
8354 | ||||
8355 | static ExprResult | |||
8356 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, | |||
8357 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, | |||
8358 | const DeclarationNameInfo &ReductionId, QualType Ty, | |||
8359 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { | |||
8360 | if (ReductionIdScopeSpec.isInvalid()) | |||
8361 | return ExprError(); | |||
8362 | SmallVector<UnresolvedSet<8>, 4> Lookups; | |||
8363 | if (S) { | |||
8364 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); | |||
8365 | Lookup.suppressDiagnostics(); | |||
8366 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { | |||
8367 | auto *D = Lookup.getRepresentativeDecl(); | |||
8368 | do { | |||
8369 | S = S->getParent(); | |||
8370 | } while (S && !S->isDeclScope(D)); | |||
8371 | if (S) | |||
8372 | S = S->getParent(); | |||
8373 | Lookups.push_back(UnresolvedSet<8>()); | |||
8374 | Lookups.back().append(Lookup.begin(), Lookup.end()); | |||
8375 | Lookup.clear(); | |||
8376 | } | |||
8377 | } else if (auto *ULE = | |||
8378 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { | |||
8379 | Lookups.push_back(UnresolvedSet<8>()); | |||
8380 | Decl *PrevD = nullptr; | |||
8381 | for(auto *D : ULE->decls()) { | |||
8382 | if (D == PrevD) | |||
8383 | Lookups.push_back(UnresolvedSet<8>()); | |||
8384 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) | |||
8385 | Lookups.back().addDecl(DRD); | |||
8386 | PrevD = D; | |||
8387 | } | |||
8388 | } | |||
8389 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || | |||
8390 | Ty->containsUnexpandedParameterPack() || | |||
8391 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { | |||
8392 | return !D->isInvalidDecl() && | |||
8393 | (D->getType()->isDependentType() || | |||
8394 | D->getType()->isInstantiationDependentType() || | |||
8395 | D->getType()->containsUnexpandedParameterPack()); | |||
8396 | })) { | |||
8397 | UnresolvedSet<8> ResSet; | |||
8398 | for (auto &Set : Lookups) { | |||
8399 | ResSet.append(Set.begin(), Set.end()); | |||
8400 | // The last item marks the end of all declarations at the specified scope. | |||
8401 | ResSet.addDecl(Set[Set.size() - 1]); | |||
8402 | } | |||
8403 | return UnresolvedLookupExpr::Create( | |||
8404 | SemaRef.Context, /*NamingClass=*/nullptr, | |||
8405 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, | |||
8406 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); | |||
8407 | } | |||
8408 | if (auto *VD = filterLookupForUDR<ValueDecl *>( | |||
8409 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { | |||
8410 | if (!D->isInvalidDecl() && | |||
8411 | SemaRef.Context.hasSameType(D->getType(), Ty)) | |||
8412 | return D; | |||
8413 | return nullptr; | |||
8414 | })) | |||
8415 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); | |||
8416 | if (auto *VD = filterLookupForUDR<ValueDecl *>( | |||
8417 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { | |||
8418 | if (!D->isInvalidDecl() && | |||
8419 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && | |||
8420 | !Ty.isMoreQualifiedThan(D->getType())) | |||
8421 | return D; | |||
8422 | return nullptr; | |||
8423 | })) { | |||
8424 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, | |||
8425 | /*DetectVirtual=*/false); | |||
8426 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { | |||
8427 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( | |||
8428 | VD->getType().getUnqualifiedType()))) { | |||
8429 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), | |||
8430 | /*DiagID=*/0) != | |||
8431 | Sema::AR_inaccessible) { | |||
8432 | SemaRef.BuildBasePathArray(Paths, BasePath); | |||
8433 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); | |||
8434 | } | |||
8435 | } | |||
8436 | } | |||
8437 | } | |||
8438 | if (ReductionIdScopeSpec.isSet()) { | |||
8439 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; | |||
8440 | return ExprError(); | |||
8441 | } | |||
8442 | return ExprEmpty(); | |||
8443 | } | |||
8444 | ||||
8445 | OMPClause *Sema::ActOnOpenMPReductionClause( | |||
8446 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, | |||
8447 | SourceLocation ColonLoc, SourceLocation EndLoc, | |||
8448 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, | |||
8449 | ArrayRef<Expr *> UnresolvedReductions) { | |||
8450 | auto DN = ReductionId.getName(); | |||
8451 | auto OOK = DN.getCXXOverloadedOperator(); | |||
8452 | BinaryOperatorKind BOK = BO_Comma; | |||
8453 | ||||
8454 | // OpenMP [2.14.3.6, reduction clause] | |||
8455 | // C | |||
8456 | // reduction-identifier is either an identifier or one of the following | |||
8457 | // operators: +, -, *, &, |, ^, && and || | |||
8458 | // C++ | |||
8459 | // reduction-identifier is either an id-expression or one of the following | |||
8460 | // operators: +, -, *, &, |, ^, && and || | |||
8461 | // FIXME: Only 'min' and 'max' identifiers are supported for now. | |||
8462 | switch (OOK) { | |||
8463 | case OO_Plus: | |||
8464 | case OO_Minus: | |||
8465 | BOK = BO_Add; | |||
8466 | break; | |||
8467 | case OO_Star: | |||
8468 | BOK = BO_Mul; | |||
8469 | break; | |||
8470 | case OO_Amp: | |||
8471 | BOK = BO_And; | |||
8472 | break; | |||
8473 | case OO_Pipe: | |||
8474 | BOK = BO_Or; | |||
8475 | break; | |||
8476 | case OO_Caret: | |||
8477 | BOK = BO_Xor; | |||
8478 | break; | |||
8479 | case OO_AmpAmp: | |||
8480 | BOK = BO_LAnd; | |||
8481 | break; | |||
8482 | case OO_PipePipe: | |||
8483 | BOK = BO_LOr; | |||
8484 | break; | |||
8485 | case OO_New: | |||
8486 | case OO_Delete: | |||
8487 | case OO_Array_New: | |||
8488 | case OO_Array_Delete: | |||
8489 | case OO_Slash: | |||
8490 | case OO_Percent: | |||
8491 | case OO_Tilde: | |||
8492 | case OO_Exclaim: | |||
8493 | case OO_Equal: | |||
8494 | case OO_Less: | |||
8495 | case OO_Greater: | |||
8496 | case OO_LessEqual: | |||
8497 | case OO_GreaterEqual: | |||
8498 | case OO_PlusEqual: | |||
8499 | case OO_MinusEqual: | |||
8500 | case OO_StarEqual: | |||
8501 | case OO_SlashEqual: | |||
8502 | case OO_PercentEqual: | |||
8503 | case OO_CaretEqual: | |||
8504 | case OO_AmpEqual: | |||
8505 | case OO_PipeEqual: | |||
8506 | case OO_LessLess: | |||
8507 | case OO_GreaterGreater: | |||
8508 | case OO_LessLessEqual: | |||
8509 | case OO_GreaterGreaterEqual: | |||
8510 | case OO_EqualEqual: | |||
8511 | case OO_ExclaimEqual: | |||
8512 | case OO_PlusPlus: | |||
8513 | case OO_MinusMinus: | |||
8514 | case OO_Comma: | |||
8515 | case OO_ArrowStar: | |||
8516 | case OO_Arrow: | |||
8517 | case OO_Call: | |||
8518 | case OO_Subscript: | |||
8519 | case OO_Conditional: | |||
8520 | case OO_Coawait: | |||
8521 | case NUM_OVERLOADED_OPERATORS: | |||
8522 | llvm_unreachable("Unexpected reduction identifier")::llvm::llvm_unreachable_internal("Unexpected reduction identifier" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 8522); | |||
8523 | case OO_None: | |||
8524 | if (auto II = DN.getAsIdentifierInfo()) { | |||
8525 | if (II->isStr("max")) | |||
8526 | BOK = BO_GT; | |||
8527 | else if (II->isStr("min")) | |||
8528 | BOK = BO_LT; | |||
8529 | } | |||
8530 | break; | |||
8531 | } | |||
8532 | SourceRange ReductionIdRange; | |||
8533 | if (ReductionIdScopeSpec.isValid()) | |||
8534 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); | |||
8535 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); | |||
8536 | ||||
8537 | SmallVector<Expr *, 8> Vars; | |||
8538 | SmallVector<Expr *, 8> Privates; | |||
8539 | SmallVector<Expr *, 8> LHSs; | |||
8540 | SmallVector<Expr *, 8> RHSs; | |||
8541 | SmallVector<Expr *, 8> ReductionOps; | |||
8542 | SmallVector<Decl *, 4> ExprCaptures; | |||
8543 | SmallVector<Expr *, 4> ExprPostUpdates; | |||
8544 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); | |||
8545 | bool FirstIter = true; | |||
8546 | for (auto RefExpr : VarList) { | |||
8547 | assert(RefExpr && "nullptr expr in OpenMP reduction clause.")((RefExpr && "nullptr expr in OpenMP reduction clause." ) ? static_cast<void> (0) : __assert_fail ("RefExpr && \"nullptr expr in OpenMP reduction clause.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 8547, __PRETTY_FUNCTION__)); | |||
8548 | // OpenMP [2.1, C/C++] | |||
8549 | // A list item is a variable or array section, subject to the restrictions | |||
8550 | // specified in Section 2.4 on page 42 and in each of the sections | |||
8551 | // describing clauses and directives for which a list appears. | |||
8552 | // OpenMP [2.14.3.3, Restrictions, p.1] | |||
8553 | // A variable that is part of another variable (as an array or | |||
8554 | // structure element) cannot appear in a private clause. | |||
8555 | if (!FirstIter && IR != ER) | |||
8556 | ++IR; | |||
8557 | FirstIter = false; | |||
8558 | SourceLocation ELoc; | |||
8559 | SourceRange ERange; | |||
8560 | Expr *SimpleRefExpr = RefExpr; | |||
8561 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, | |||
8562 | /*AllowArraySection=*/true); | |||
8563 | if (Res.second) { | |||
8564 | // It will be analyzed later. | |||
8565 | Vars.push_back(RefExpr); | |||
8566 | Privates.push_back(nullptr); | |||
8567 | LHSs.push_back(nullptr); | |||
8568 | RHSs.push_back(nullptr); | |||
8569 | // Try to find 'declare reduction' corresponding construct before using | |||
8570 | // builtin/overloaded operators. | |||
8571 | QualType Type = Context.DependentTy; | |||
8572 | CXXCastPath BasePath; | |||
8573 | ExprResult DeclareReductionRef = buildDeclareReductionRef( | |||
8574 | *this, ELoc, ERange, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurScope(), ReductionIdScopeSpec, | |||
8575 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); | |||
8576 | if (CurContext->isDependentContext() && | |||
8577 | (DeclareReductionRef.isUnset() || | |||
8578 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) | |||
8579 | ReductionOps.push_back(DeclareReductionRef.get()); | |||
8580 | else | |||
8581 | ReductionOps.push_back(nullptr); | |||
8582 | } | |||
8583 | ValueDecl *D = Res.first; | |||
8584 | if (!D) | |||
8585 | continue; | |||
8586 | ||||
8587 | QualType Type; | |||
8588 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); | |||
8589 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); | |||
8590 | if (ASE) | |||
8591 | Type = ASE->getType().getNonReferenceType(); | |||
8592 | else if (OASE) { | |||
8593 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); | |||
8594 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) | |||
8595 | Type = ATy->getElementType(); | |||
8596 | else | |||
8597 | Type = BaseType->getPointeeType(); | |||
8598 | Type = Type.getNonReferenceType(); | |||
8599 | } else | |||
8600 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); | |||
8601 | auto *VD = dyn_cast<VarDecl>(D); | |||
8602 | ||||
8603 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] | |||
8604 | // A variable that appears in a private clause must not have an incomplete | |||
8605 | // type or a reference type. | |||
8606 | if (RequireCompleteType(ELoc, Type, | |||
8607 | diag::err_omp_reduction_incomplete_type)) | |||
8608 | continue; | |||
8609 | // OpenMP [2.14.3.6, reduction clause, Restrictions] | |||
8610 | // A list item that appears in a reduction clause must not be | |||
8611 | // const-qualified. | |||
8612 | if (Type.getNonReferenceType().isConstant(Context)) { | |||
8613 | Diag(ELoc, diag::err_omp_const_reduction_list_item) | |||
8614 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; | |||
8615 | if (!ASE && !OASE) { | |||
8616 | bool IsDecl = !VD || | |||
8617 | VD->isThisDeclarationADefinition(Context) == | |||
8618 | VarDecl::DeclarationOnly; | |||
8619 | Diag(D->getLocation(), | |||
8620 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
8621 | << D; | |||
8622 | } | |||
8623 | continue; | |||
8624 | } | |||
8625 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] | |||
8626 | // If a list-item is a reference type then it must bind to the same object | |||
8627 | // for all threads of the team. | |||
8628 | if (!ASE && !OASE && VD) { | |||
8629 | VarDecl *VDDef = VD->getDefinition(); | |||
8630 | if (VD->getType()->isReferenceType() && VDDef) { | |||
8631 | DSARefChecker Check(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )); | |||
8632 | if (Check.Visit(VDDef->getInit())) { | |||
8633 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; | |||
8634 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; | |||
8635 | continue; | |||
8636 | } | |||
8637 | } | |||
8638 | } | |||
8639 | ||||
8640 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced | |||
8641 | // in a Construct] | |||
8642 | // Variables with the predetermined data-sharing attributes may not be | |||
8643 | // listed in data-sharing attributes clauses, except for the cases | |||
8644 | // listed below. For these exceptions only, listing a predetermined | |||
8645 | // variable in a data-sharing attribute clause is allowed and overrides | |||
8646 | // the variable's predetermined data-sharing attributes. | |||
8647 | // OpenMP [2.14.3.6, Restrictions, p.3] | |||
8648 | // Any number of reduction clauses can be specified on the directive, | |||
8649 | // but a list item can appear only once in the reduction clauses for that | |||
8650 | // directive. | |||
8651 | DSAStackTy::DSAVarData DVar; | |||
8652 | DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, false); | |||
8653 | if (DVar.CKind == OMPC_reduction) { | |||
8654 | Diag(ELoc, diag::err_omp_once_referenced) | |||
8655 | << getOpenMPClauseName(OMPC_reduction); | |||
8656 | if (DVar.RefExpr) | |||
8657 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); | |||
8658 | } else if (DVar.CKind != OMPC_unknown) { | |||
8659 | Diag(ELoc, diag::err_omp_wrong_dsa) | |||
8660 | << getOpenMPClauseName(DVar.CKind) | |||
8661 | << getOpenMPClauseName(OMPC_reduction); | |||
8662 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
8663 | continue; | |||
8664 | } | |||
8665 | ||||
8666 | // OpenMP [2.14.3.6, Restrictions, p.1] | |||
8667 | // A list item that appears in a reduction clause of a worksharing | |||
8668 | // construct must be shared in the parallel regions to which any of the | |||
8669 | // worksharing regions arising from the worksharing construct bind. | |||
8670 | OpenMPDirectiveKind CurrDir = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective(); | |||
8671 | if (isOpenMPWorksharingDirective(CurrDir) && | |||
8672 | !isOpenMPParallelDirective(CurrDir)) { | |||
8673 | DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getImplicitDSA(D, true); | |||
8674 | if (DVar.CKind != OMPC_shared) { | |||
8675 | Diag(ELoc, diag::err_omp_required_access) | |||
8676 | << getOpenMPClauseName(OMPC_reduction) | |||
8677 | << getOpenMPClauseName(OMPC_shared); | |||
8678 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
8679 | continue; | |||
8680 | } | |||
8681 | } | |||
8682 | ||||
8683 | // Try to find 'declare reduction' corresponding construct before using | |||
8684 | // builtin/overloaded operators. | |||
8685 | CXXCastPath BasePath; | |||
8686 | ExprResult DeclareReductionRef = buildDeclareReductionRef( | |||
8687 | *this, ELoc, ERange, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurScope(), ReductionIdScopeSpec, | |||
8688 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); | |||
8689 | if (DeclareReductionRef.isInvalid()) | |||
8690 | continue; | |||
8691 | if (CurContext->isDependentContext() && | |||
8692 | (DeclareReductionRef.isUnset() || | |||
8693 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { | |||
8694 | Vars.push_back(RefExpr); | |||
8695 | Privates.push_back(nullptr); | |||
8696 | LHSs.push_back(nullptr); | |||
8697 | RHSs.push_back(nullptr); | |||
8698 | ReductionOps.push_back(DeclareReductionRef.get()); | |||
8699 | continue; | |||
8700 | } | |||
8701 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { | |||
8702 | // Not allowed reduction identifier is found. | |||
8703 | Diag(ReductionId.getLocStart(), | |||
8704 | diag::err_omp_unknown_reduction_identifier) | |||
8705 | << Type << ReductionIdRange; | |||
8706 | continue; | |||
8707 | } | |||
8708 | ||||
8709 | // OpenMP [2.14.3.6, reduction clause, Restrictions] | |||
8710 | // The type of a list item that appears in a reduction clause must be valid | |||
8711 | // for the reduction-identifier. For a max or min reduction in C, the type | |||
8712 | // of the list item must be an allowed arithmetic data type: char, int, | |||
8713 | // float, double, or _Bool, possibly modified with long, short, signed, or | |||
8714 | // unsigned. For a max or min reduction in C++, the type of the list item | |||
8715 | // must be an allowed arithmetic data type: char, wchar_t, int, float, | |||
8716 | // double, or bool, possibly modified with long, short, signed, or unsigned. | |||
8717 | if (DeclareReductionRef.isUnset()) { | |||
8718 | if ((BOK == BO_GT || BOK == BO_LT) && | |||
8719 | !(Type->isScalarType() || | |||
8720 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { | |||
8721 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) | |||
8722 | << getLangOpts().CPlusPlus; | |||
8723 | if (!ASE && !OASE) { | |||
8724 | bool IsDecl = !VD || | |||
8725 | VD->isThisDeclarationADefinition(Context) == | |||
8726 | VarDecl::DeclarationOnly; | |||
8727 | Diag(D->getLocation(), | |||
8728 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
8729 | << D; | |||
8730 | } | |||
8731 | continue; | |||
8732 | } | |||
8733 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && | |||
8734 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { | |||
8735 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); | |||
8736 | if (!ASE && !OASE) { | |||
8737 | bool IsDecl = !VD || | |||
8738 | VD->isThisDeclarationADefinition(Context) == | |||
8739 | VarDecl::DeclarationOnly; | |||
8740 | Diag(D->getLocation(), | |||
8741 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
8742 | << D; | |||
8743 | } | |||
8744 | continue; | |||
8745 | } | |||
8746 | } | |||
8747 | ||||
8748 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); | |||
8749 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", | |||
8750 | D->hasAttrs() ? &D->getAttrs() : nullptr); | |||
8751 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), | |||
8752 | D->hasAttrs() ? &D->getAttrs() : nullptr); | |||
8753 | auto PrivateTy = Type; | |||
8754 | if (OASE || | |||
8755 | (!ASE && | |||
8756 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { | |||
8757 | // For arays/array sections only: | |||
8758 | // Create pseudo array type for private copy. The size for this array will | |||
8759 | // be generated during codegen. | |||
8760 | // For array subscripts or single variables Private Ty is the same as Type | |||
8761 | // (type of the variable or single array element). | |||
8762 | PrivateTy = Context.getVariableArrayType( | |||
8763 | Type, new (Context) OpaqueValueExpr(SourceLocation(), | |||
8764 | Context.getSizeType(), VK_RValue), | |||
8765 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); | |||
8766 | } else if (!ASE && !OASE && | |||
8767 | Context.getAsArrayType(D->getType().getNonReferenceType())) | |||
8768 | PrivateTy = D->getType().getNonReferenceType(); | |||
8769 | // Private copy. | |||
8770 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), | |||
8771 | D->hasAttrs() ? &D->getAttrs() : nullptr); | |||
8772 | // Add initializer for private variable. | |||
8773 | Expr *Init = nullptr; | |||
8774 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); | |||
8775 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); | |||
8776 | if (DeclareReductionRef.isUsable()) { | |||
8777 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); | |||
8778 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); | |||
8779 | if (DRD->getInitializer()) { | |||
8780 | Init = DRDRef; | |||
8781 | RHSVD->setInit(DRDRef); | |||
8782 | RHSVD->setInitStyle(VarDecl::CallInit); | |||
8783 | } | |||
8784 | } else { | |||
8785 | switch (BOK) { | |||
8786 | case BO_Add: | |||
8787 | case BO_Xor: | |||
8788 | case BO_Or: | |||
8789 | case BO_LOr: | |||
8790 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. | |||
8791 | if (Type->isScalarType() || Type->isAnyComplexType()) | |||
8792 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); | |||
8793 | break; | |||
8794 | case BO_Mul: | |||
8795 | case BO_LAnd: | |||
8796 | if (Type->isScalarType() || Type->isAnyComplexType()) { | |||
8797 | // '*' and '&&' reduction ops - initializer is '1'. | |||
8798 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); | |||
8799 | } | |||
8800 | break; | |||
8801 | case BO_And: { | |||
8802 | // '&' reduction op - initializer is '~0'. | |||
8803 | QualType OrigType = Type; | |||
8804 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) | |||
8805 | Type = ComplexTy->getElementType(); | |||
8806 | if (Type->isRealFloatingType()) { | |||
8807 | llvm::APFloat InitValue = | |||
8808 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), | |||
8809 | /*isIEEE=*/true); | |||
8810 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, | |||
8811 | Type, ELoc); | |||
8812 | } else if (Type->isScalarType()) { | |||
8813 | auto Size = Context.getTypeSize(Type); | |||
8814 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); | |||
8815 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); | |||
8816 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); | |||
8817 | } | |||
8818 | if (Init && OrigType->isAnyComplexType()) { | |||
8819 | // Init = 0xFFFF + 0xFFFFi; | |||
8820 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); | |||
8821 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); | |||
8822 | } | |||
8823 | Type = OrigType; | |||
8824 | break; | |||
8825 | } | |||
8826 | case BO_LT: | |||
8827 | case BO_GT: { | |||
8828 | // 'min' reduction op - initializer is 'Largest representable number in | |||
8829 | // the reduction list item type'. | |||
8830 | // 'max' reduction op - initializer is 'Least representable number in | |||
8831 | // the reduction list item type'. | |||
8832 | if (Type->isIntegerType() || Type->isPointerType()) { | |||
8833 | bool IsSigned = Type->hasSignedIntegerRepresentation(); | |||
8834 | auto Size = Context.getTypeSize(Type); | |||
8835 | QualType IntTy = | |||
8836 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); | |||
8837 | llvm::APInt InitValue = | |||
8838 | (BOK != BO_LT) | |||
8839 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) | |||
8840 | : llvm::APInt::getMinValue(Size) | |||
8841 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) | |||
8842 | : llvm::APInt::getMaxValue(Size); | |||
8843 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); | |||
8844 | if (Type->isPointerType()) { | |||
8845 | // Cast to pointer type. | |||
8846 | auto CastExpr = BuildCStyleCastExpr( | |||
8847 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), | |||
8848 | SourceLocation(), Init); | |||
8849 | if (CastExpr.isInvalid()) | |||
8850 | continue; | |||
8851 | Init = CastExpr.get(); | |||
8852 | } | |||
8853 | } else if (Type->isRealFloatingType()) { | |||
8854 | llvm::APFloat InitValue = llvm::APFloat::getLargest( | |||
8855 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); | |||
8856 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, | |||
8857 | Type, ELoc); | |||
8858 | } | |||
8859 | break; | |||
8860 | } | |||
8861 | case BO_PtrMemD: | |||
8862 | case BO_PtrMemI: | |||
8863 | case BO_MulAssign: | |||
8864 | case BO_Div: | |||
8865 | case BO_Rem: | |||
8866 | case BO_Sub: | |||
8867 | case BO_Shl: | |||
8868 | case BO_Shr: | |||
8869 | case BO_LE: | |||
8870 | case BO_GE: | |||
8871 | case BO_EQ: | |||
8872 | case BO_NE: | |||
8873 | case BO_AndAssign: | |||
8874 | case BO_XorAssign: | |||
8875 | case BO_OrAssign: | |||
8876 | case BO_Assign: | |||
8877 | case BO_AddAssign: | |||
8878 | case BO_SubAssign: | |||
8879 | case BO_DivAssign: | |||
8880 | case BO_RemAssign: | |||
8881 | case BO_ShlAssign: | |||
8882 | case BO_ShrAssign: | |||
8883 | case BO_Comma: | |||
8884 | llvm_unreachable("Unexpected reduction operation")::llvm::llvm_unreachable_internal("Unexpected reduction operation" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 8884); | |||
8885 | } | |||
8886 | } | |||
8887 | if (Init && DeclareReductionRef.isUnset()) { | |||
8888 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, | |||
8889 | /*TypeMayContainAuto=*/false); | |||
8890 | } else if (!Init) | |||
8891 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); | |||
8892 | if (RHSVD->isInvalidDecl()) | |||
8893 | continue; | |||
8894 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { | |||
8895 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type | |||
8896 | << ReductionIdRange; | |||
8897 | bool IsDecl = | |||
8898 | !VD || | |||
8899 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
8900 | Diag(D->getLocation(), | |||
8901 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
8902 | << D; | |||
8903 | continue; | |||
8904 | } | |||
8905 | // Store initializer for single element in private copy. Will be used during | |||
8906 | // codegen. | |||
8907 | PrivateVD->setInit(RHSVD->getInit()); | |||
8908 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); | |||
8909 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); | |||
8910 | ExprResult ReductionOp; | |||
8911 | if (DeclareReductionRef.isUsable()) { | |||
8912 | QualType RedTy = DeclareReductionRef.get()->getType(); | |||
8913 | QualType PtrRedTy = Context.getPointerType(RedTy); | |||
8914 | ExprResult LHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); | |||
8915 | ExprResult RHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); | |||
8916 | if (!BasePath.empty()) { | |||
8917 | LHS = DefaultLvalueConversion(LHS.get()); | |||
8918 | RHS = DefaultLvalueConversion(RHS.get()); | |||
8919 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, | |||
8920 | CK_UncheckedDerivedToBase, LHS.get(), | |||
8921 | &BasePath, LHS.get()->getValueKind()); | |||
8922 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, | |||
8923 | CK_UncheckedDerivedToBase, RHS.get(), | |||
8924 | &BasePath, RHS.get()->getValueKind()); | |||
8925 | } | |||
8926 | FunctionProtoType::ExtProtoInfo EPI; | |||
8927 | QualType Params[] = {PtrRedTy, PtrRedTy}; | |||
8928 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); | |||
8929 | auto *OVE = new (Context) OpaqueValueExpr( | |||
8930 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, | |||
8931 | DefaultLvalueConversion(DeclareReductionRef.get()).get()); | |||
8932 | Expr *Args[] = {LHS.get(), RHS.get()}; | |||
8933 | ReductionOp = new (Context) | |||
8934 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); | |||
8935 | } else { | |||
8936 | ReductionOp = BuildBinOp(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurScope(), | |||
8937 | ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); | |||
8938 | if (ReductionOp.isUsable()) { | |||
8939 | if (BOK != BO_LT && BOK != BO_GT) { | |||
8940 | ReductionOp = | |||
8941 | BuildBinOp(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurScope(), ReductionId.getLocStart(), | |||
8942 | BO_Assign, LHSDRE, ReductionOp.get()); | |||
8943 | } else { | |||
8944 | auto *ConditionalOp = new (Context) ConditionalOperator( | |||
8945 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), | |||
8946 | RHSDRE, Type, VK_LValue, OK_Ordinary); | |||
8947 | ReductionOp = | |||
8948 | BuildBinOp(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurScope(), ReductionId.getLocStart(), | |||
8949 | BO_Assign, LHSDRE, ConditionalOp); | |||
8950 | } | |||
8951 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); | |||
8952 | } | |||
8953 | if (ReductionOp.isInvalid()) | |||
8954 | continue; | |||
8955 | } | |||
8956 | ||||
8957 | DeclRefExpr *Ref = nullptr; | |||
8958 | Expr *VarsExpr = RefExpr->IgnoreParens(); | |||
8959 | if (!VD) { | |||
8960 | if (ASE || OASE) { | |||
8961 | TransformExprToCaptures RebuildToCapture(*this, D); | |||
8962 | VarsExpr = | |||
8963 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); | |||
8964 | Ref = RebuildToCapture.getCapturedExpr(); | |||
8965 | } else { | |||
8966 | VarsExpr = Ref = | |||
8967 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); | |||
8968 | } | |||
8969 | if (!IsOpenMPCapturedDecl(D)) { | |||
8970 | ExprCaptures.push_back(Ref->getDecl()); | |||
8971 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { | |||
8972 | ExprResult RefRes = DefaultLvalueConversion(Ref); | |||
8973 | if (!RefRes.isUsable()) | |||
8974 | continue; | |||
8975 | ExprResult PostUpdateRes = | |||
8976 | BuildBinOp(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurScope(), ELoc, BO_Assign, | |||
8977 | SimpleRefExpr, RefRes.get()); | |||
8978 | if (!PostUpdateRes.isUsable()) | |||
8979 | continue; | |||
8980 | ExprPostUpdates.push_back( | |||
8981 | IgnoredValueConversions(PostUpdateRes.get()).get()); | |||
8982 | } | |||
8983 | } | |||
8984 | } | |||
8985 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); | |||
8986 | Vars.push_back(VarsExpr); | |||
8987 | Privates.push_back(PrivateDRE); | |||
8988 | LHSs.push_back(LHSDRE); | |||
8989 | RHSs.push_back(RHSDRE); | |||
8990 | ReductionOps.push_back(ReductionOp.get()); | |||
8991 | } | |||
8992 | ||||
8993 | if (Vars.empty()) | |||
8994 | return nullptr; | |||
8995 | ||||
8996 | return OMPReductionClause::Create( | |||
8997 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, | |||
8998 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, | |||
8999 | LHSs, RHSs, ReductionOps, buildPreInits(Context, ExprCaptures), | |||
9000 | buildPostUpdate(*this, ExprPostUpdates)); | |||
9001 | } | |||
9002 | ||||
9003 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, | |||
9004 | SourceLocation LinLoc) { | |||
9005 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || | |||
9006 | LinKind == OMPC_LINEAR_unknown) { | |||
9007 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; | |||
9008 | return true; | |||
9009 | } | |||
9010 | return false; | |||
9011 | } | |||
9012 | ||||
9013 | bool Sema::CheckOpenMPLinearDecl(ValueDecl *D, SourceLocation ELoc, | |||
9014 | OpenMPLinearClauseKind LinKind, | |||
9015 | QualType Type) { | |||
9016 | auto *VD = dyn_cast_or_null<VarDecl>(D); | |||
9017 | // A variable must not have an incomplete type or a reference type. | |||
9018 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) | |||
9019 | return true; | |||
9020 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && | |||
9021 | !Type->isReferenceType()) { | |||
9022 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) | |||
9023 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); | |||
9024 | return true; | |||
9025 | } | |||
9026 | Type = Type.getNonReferenceType(); | |||
9027 | ||||
9028 | // A list item must not be const-qualified. | |||
9029 | if (Type.isConstant(Context)) { | |||
9030 | Diag(ELoc, diag::err_omp_const_variable) | |||
9031 | << getOpenMPClauseName(OMPC_linear); | |||
9032 | if (D) { | |||
9033 | bool IsDecl = | |||
9034 | !VD || | |||
9035 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
9036 | Diag(D->getLocation(), | |||
9037 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
9038 | << D; | |||
9039 | } | |||
9040 | return true; | |||
9041 | } | |||
9042 | ||||
9043 | // A list item must be of integral or pointer type. | |||
9044 | Type = Type.getUnqualifiedType().getCanonicalType(); | |||
9045 | const auto *Ty = Type.getTypePtrOrNull(); | |||
9046 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && | |||
9047 | !Ty->isPointerType())) { | |||
9048 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; | |||
9049 | if (D) { | |||
9050 | bool IsDecl = | |||
9051 | !VD || | |||
9052 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
9053 | Diag(D->getLocation(), | |||
9054 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
9055 | << D; | |||
9056 | } | |||
9057 | return true; | |||
9058 | } | |||
9059 | return false; | |||
9060 | } | |||
9061 | ||||
9062 | OMPClause *Sema::ActOnOpenMPLinearClause( | |||
9063 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, | |||
9064 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, | |||
9065 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { | |||
9066 | SmallVector<Expr *, 8> Vars; | |||
9067 | SmallVector<Expr *, 8> Privates; | |||
9068 | SmallVector<Expr *, 8> Inits; | |||
9069 | SmallVector<Decl *, 4> ExprCaptures; | |||
9070 | SmallVector<Expr *, 4> ExprPostUpdates; | |||
9071 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) | |||
9072 | LinKind = OMPC_LINEAR_val; | |||
9073 | for (auto &RefExpr : VarList) { | |||
9074 | assert(RefExpr && "NULL expr in OpenMP linear clause.")((RefExpr && "NULL expr in OpenMP linear clause.") ? static_cast <void> (0) : __assert_fail ("RefExpr && \"NULL expr in OpenMP linear clause.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 9074, __PRETTY_FUNCTION__)); | |||
9075 | SourceLocation ELoc; | |||
9076 | SourceRange ERange; | |||
9077 | Expr *SimpleRefExpr = RefExpr; | |||
9078 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, | |||
9079 | /*AllowArraySection=*/false); | |||
9080 | if (Res.second) { | |||
9081 | // It will be analyzed later. | |||
9082 | Vars.push_back(RefExpr); | |||
9083 | Privates.push_back(nullptr); | |||
9084 | Inits.push_back(nullptr); | |||
9085 | } | |||
9086 | ValueDecl *D = Res.first; | |||
9087 | if (!D) | |||
9088 | continue; | |||
9089 | ||||
9090 | QualType Type = D->getType(); | |||
9091 | auto *VD = dyn_cast<VarDecl>(D); | |||
9092 | ||||
9093 | // OpenMP [2.14.3.7, linear clause] | |||
9094 | // A list-item cannot appear in more than one linear clause. | |||
9095 | // A list-item that appears in a linear clause cannot appear in any | |||
9096 | // other data-sharing attribute clause. | |||
9097 | DSAStackTy::DSAVarData DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, false); | |||
9098 | if (DVar.RefExpr) { | |||
9099 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) | |||
9100 | << getOpenMPClauseName(OMPC_linear); | |||
9101 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
9102 | continue; | |||
9103 | } | |||
9104 | ||||
9105 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) | |||
9106 | continue; | |||
9107 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); | |||
9108 | ||||
9109 | // Build private copy of original var. | |||
9110 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), | |||
9111 | D->hasAttrs() ? &D->getAttrs() : nullptr); | |||
9112 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); | |||
9113 | // Build var to save initial value. | |||
9114 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); | |||
9115 | Expr *InitExpr; | |||
9116 | DeclRefExpr *Ref = nullptr; | |||
9117 | if (!VD) { | |||
9118 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); | |||
9119 | if (!IsOpenMPCapturedDecl(D)) { | |||
9120 | ExprCaptures.push_back(Ref->getDecl()); | |||
9121 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { | |||
9122 | ExprResult RefRes = DefaultLvalueConversion(Ref); | |||
9123 | if (!RefRes.isUsable()) | |||
9124 | continue; | |||
9125 | ExprResult PostUpdateRes = | |||
9126 | BuildBinOp(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurScope(), ELoc, BO_Assign, | |||
9127 | SimpleRefExpr, RefRes.get()); | |||
9128 | if (!PostUpdateRes.isUsable()) | |||
9129 | continue; | |||
9130 | ExprPostUpdates.push_back( | |||
9131 | IgnoredValueConversions(PostUpdateRes.get()).get()); | |||
9132 | } | |||
9133 | } | |||
9134 | } | |||
9135 | if (LinKind == OMPC_LINEAR_uval) | |||
9136 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; | |||
9137 | else | |||
9138 | InitExpr = VD ? SimpleRefExpr : Ref; | |||
9139 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), | |||
9140 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); | |||
9141 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); | |||
9142 | ||||
9143 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); | |||
9144 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); | |||
9145 | Privates.push_back(PrivateRef); | |||
9146 | Inits.push_back(InitRef); | |||
9147 | } | |||
9148 | ||||
9149 | if (Vars.empty()) | |||
9150 | return nullptr; | |||
9151 | ||||
9152 | Expr *StepExpr = Step; | |||
9153 | Expr *CalcStepExpr = nullptr; | |||
9154 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && | |||
9155 | !Step->isInstantiationDependent() && | |||
9156 | !Step->containsUnexpandedParameterPack()) { | |||
9157 | SourceLocation StepLoc = Step->getLocStart(); | |||
9158 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); | |||
9159 | if (Val.isInvalid()) | |||
9160 | return nullptr; | |||
9161 | StepExpr = Val.get(); | |||
9162 | ||||
9163 | // Build var to save the step value. | |||
9164 | VarDecl *SaveVar = | |||
9165 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); | |||
9166 | ExprResult SaveRef = | |||
9167 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); | |||
9168 | ExprResult CalcStep = | |||
9169 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); | |||
9170 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); | |||
9171 | ||||
9172 | // Warn about zero linear step (it would be probably better specified as | |||
9173 | // making corresponding variables 'const'). | |||
9174 | llvm::APSInt Result; | |||
9175 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); | |||
9176 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) | |||
9177 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] | |||
9178 | << (Vars.size() > 1); | |||
9179 | if (!IsConstant && CalcStep.isUsable()) { | |||
9180 | // Calculate the step beforehand instead of doing this on each iteration. | |||
9181 | // (This is not used if the number of iterations may be kfold-ed). | |||
9182 | CalcStepExpr = CalcStep.get(); | |||
9183 | } | |||
9184 | } | |||
9185 | ||||
9186 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, | |||
9187 | ColonLoc, EndLoc, Vars, Privates, Inits, | |||
9188 | StepExpr, CalcStepExpr, | |||
9189 | buildPreInits(Context, ExprCaptures), | |||
9190 | buildPostUpdate(*this, ExprPostUpdates)); | |||
9191 | } | |||
9192 | ||||
9193 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, | |||
9194 | Expr *NumIterations, Sema &SemaRef, | |||
9195 | Scope *S, DSAStackTy *Stack) { | |||
9196 | // Walk the vars and build update/final expressions for the CodeGen. | |||
9197 | SmallVector<Expr *, 8> Updates; | |||
9198 | SmallVector<Expr *, 8> Finals; | |||
9199 | Expr *Step = Clause.getStep(); | |||
9200 | Expr *CalcStep = Clause.getCalcStep(); | |||
9201 | // OpenMP [2.14.3.7, linear clause] | |||
9202 | // If linear-step is not specified it is assumed to be 1. | |||
9203 | if (Step == nullptr) | |||
9204 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); | |||
9205 | else if (CalcStep) { | |||
9206 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); | |||
9207 | } | |||
9208 | bool HasErrors = false; | |||
9209 | auto CurInit = Clause.inits().begin(); | |||
9210 | auto CurPrivate = Clause.privates().begin(); | |||
9211 | auto LinKind = Clause.getModifier(); | |||
9212 | for (auto &RefExpr : Clause.varlists()) { | |||
9213 | SourceLocation ELoc; | |||
9214 | SourceRange ERange; | |||
9215 | Expr *SimpleRefExpr = RefExpr; | |||
9216 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange, | |||
9217 | /*AllowArraySection=*/false); | |||
9218 | ValueDecl *D = Res.first; | |||
9219 | if (Res.second || !D) { | |||
9220 | Updates.push_back(nullptr); | |||
9221 | Finals.push_back(nullptr); | |||
9222 | HasErrors = true; | |||
9223 | continue; | |||
9224 | } | |||
9225 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) { | |||
9226 | D = cast<MemberExpr>(CED->getInit()->IgnoreParenImpCasts()) | |||
9227 | ->getMemberDecl(); | |||
9228 | } | |||
9229 | auto &&Info = Stack->isLoopControlVariable(D); | |||
9230 | Expr *InitExpr = *CurInit; | |||
9231 | ||||
9232 | // Build privatized reference to the current linear var. | |||
9233 | auto DE = cast<DeclRefExpr>(SimpleRefExpr); | |||
9234 | Expr *CapturedRef; | |||
9235 | if (LinKind == OMPC_LINEAR_uval) | |||
9236 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); | |||
9237 | else | |||
9238 | CapturedRef = | |||
9239 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), | |||
9240 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), | |||
9241 | /*RefersToCapture=*/true); | |||
9242 | ||||
9243 | // Build update: Var = InitExpr + IV * Step | |||
9244 | ExprResult Update; | |||
9245 | if (!Info.first) { | |||
9246 | Update = | |||
9247 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, | |||
9248 | InitExpr, IV, Step, /* Subtract */ false); | |||
9249 | } else | |||
9250 | Update = *CurPrivate; | |||
9251 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), | |||
9252 | /*DiscardedValue=*/true); | |||
9253 | ||||
9254 | // Build final: Var = InitExpr + NumIterations * Step | |||
9255 | ExprResult Final; | |||
9256 | if (!Info.first) { | |||
9257 | Final = BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, | |||
9258 | InitExpr, NumIterations, Step, | |||
9259 | /* Subtract */ false); | |||
9260 | } else | |||
9261 | Final = *CurPrivate; | |||
9262 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), | |||
9263 | /*DiscardedValue=*/true); | |||
9264 | ||||
9265 | if (!Update.isUsable() || !Final.isUsable()) { | |||
9266 | Updates.push_back(nullptr); | |||
9267 | Finals.push_back(nullptr); | |||
9268 | HasErrors = true; | |||
9269 | } else { | |||
9270 | Updates.push_back(Update.get()); | |||
9271 | Finals.push_back(Final.get()); | |||
9272 | } | |||
9273 | ++CurInit; | |||
9274 | ++CurPrivate; | |||
9275 | } | |||
9276 | Clause.setUpdates(Updates); | |||
9277 | Clause.setFinals(Finals); | |||
9278 | return HasErrors; | |||
9279 | } | |||
9280 | ||||
9281 | OMPClause *Sema::ActOnOpenMPAlignedClause( | |||
9282 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, | |||
9283 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { | |||
9284 | ||||
9285 | SmallVector<Expr *, 8> Vars; | |||
9286 | for (auto &RefExpr : VarList) { | |||
9287 | assert(RefExpr && "NULL expr in OpenMP linear clause.")((RefExpr && "NULL expr in OpenMP linear clause.") ? static_cast <void> (0) : __assert_fail ("RefExpr && \"NULL expr in OpenMP linear clause.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 9287, __PRETTY_FUNCTION__)); | |||
9288 | SourceLocation ELoc; | |||
9289 | SourceRange ERange; | |||
9290 | Expr *SimpleRefExpr = RefExpr; | |||
9291 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, | |||
9292 | /*AllowArraySection=*/false); | |||
9293 | if (Res.second) { | |||
9294 | // It will be analyzed later. | |||
9295 | Vars.push_back(RefExpr); | |||
9296 | } | |||
9297 | ValueDecl *D = Res.first; | |||
9298 | if (!D) | |||
9299 | continue; | |||
9300 | ||||
9301 | QualType QType = D->getType(); | |||
9302 | auto *VD = dyn_cast<VarDecl>(D); | |||
9303 | ||||
9304 | // OpenMP [2.8.1, simd construct, Restrictions] | |||
9305 | // The type of list items appearing in the aligned clause must be | |||
9306 | // array, pointer, reference to array, or reference to pointer. | |||
9307 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); | |||
9308 | const Type *Ty = QType.getTypePtrOrNull(); | |||
9309 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { | |||
9310 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) | |||
9311 | << QType << getLangOpts().CPlusPlus << ERange; | |||
9312 | bool IsDecl = | |||
9313 | !VD || | |||
9314 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
9315 | Diag(D->getLocation(), | |||
9316 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
9317 | << D; | |||
9318 | continue; | |||
9319 | } | |||
9320 | ||||
9321 | // OpenMP [2.8.1, simd construct, Restrictions] | |||
9322 | // A list-item cannot appear in more than one aligned clause. | |||
9323 | if (Expr *PrevRef = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addUniqueAligned(D, SimpleRefExpr)) { | |||
9324 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; | |||
9325 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) | |||
9326 | << getOpenMPClauseName(OMPC_aligned); | |||
9327 | continue; | |||
9328 | } | |||
9329 | ||||
9330 | DeclRefExpr *Ref = nullptr; | |||
9331 | if (!VD && IsOpenMPCapturedDecl(D)) | |||
9332 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); | |||
9333 | Vars.push_back(DefaultFunctionArrayConversion( | |||
9334 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) | |||
9335 | .get()); | |||
9336 | } | |||
9337 | ||||
9338 | // OpenMP [2.8.1, simd construct, Description] | |||
9339 | // The parameter of the aligned clause, alignment, must be a constant | |||
9340 | // positive integer expression. | |||
9341 | // If no optional parameter is specified, implementation-defined default | |||
9342 | // alignments for SIMD instructions on the target platforms are assumed. | |||
9343 | if (Alignment != nullptr) { | |||
9344 | ExprResult AlignResult = | |||
9345 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); | |||
9346 | if (AlignResult.isInvalid()) | |||
9347 | return nullptr; | |||
9348 | Alignment = AlignResult.get(); | |||
9349 | } | |||
9350 | if (Vars.empty()) | |||
9351 | return nullptr; | |||
9352 | ||||
9353 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, | |||
9354 | EndLoc, Vars, Alignment); | |||
9355 | } | |||
9356 | ||||
9357 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, | |||
9358 | SourceLocation StartLoc, | |||
9359 | SourceLocation LParenLoc, | |||
9360 | SourceLocation EndLoc) { | |||
9361 | SmallVector<Expr *, 8> Vars; | |||
9362 | SmallVector<Expr *, 8> SrcExprs; | |||
9363 | SmallVector<Expr *, 8> DstExprs; | |||
9364 | SmallVector<Expr *, 8> AssignmentOps; | |||
9365 | for (auto &RefExpr : VarList) { | |||
9366 | assert(RefExpr && "NULL expr in OpenMP copyin clause.")((RefExpr && "NULL expr in OpenMP copyin clause.") ? static_cast <void> (0) : __assert_fail ("RefExpr && \"NULL expr in OpenMP copyin clause.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 9366, __PRETTY_FUNCTION__)); | |||
9367 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { | |||
9368 | // It will be analyzed later. | |||
9369 | Vars.push_back(RefExpr); | |||
9370 | SrcExprs.push_back(nullptr); | |||
9371 | DstExprs.push_back(nullptr); | |||
9372 | AssignmentOps.push_back(nullptr); | |||
9373 | continue; | |||
9374 | } | |||
9375 | ||||
9376 | SourceLocation ELoc = RefExpr->getExprLoc(); | |||
9377 | // OpenMP [2.1, C/C++] | |||
9378 | // A list item is a variable name. | |||
9379 | // OpenMP [2.14.4.1, Restrictions, p.1] | |||
9380 | // A list item that appears in a copyin clause must be threadprivate. | |||
9381 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); | |||
9382 | if (!DE || !isa<VarDecl>(DE->getDecl())) { | |||
9383 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) | |||
9384 | << 0 << RefExpr->getSourceRange(); | |||
9385 | continue; | |||
9386 | } | |||
9387 | ||||
9388 | Decl *D = DE->getDecl(); | |||
9389 | VarDecl *VD = cast<VarDecl>(D); | |||
9390 | ||||
9391 | QualType Type = VD->getType(); | |||
9392 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { | |||
9393 | // It will be analyzed later. | |||
9394 | Vars.push_back(DE); | |||
9395 | SrcExprs.push_back(nullptr); | |||
9396 | DstExprs.push_back(nullptr); | |||
9397 | AssignmentOps.push_back(nullptr); | |||
9398 | continue; | |||
9399 | } | |||
9400 | ||||
9401 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] | |||
9402 | // A list item that appears in a copyin clause must be threadprivate. | |||
9403 | if (!DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isThreadPrivate(VD)) { | |||
9404 | Diag(ELoc, diag::err_omp_required_access) | |||
9405 | << getOpenMPClauseName(OMPC_copyin) | |||
9406 | << getOpenMPDirectiveName(OMPD_threadprivate); | |||
9407 | continue; | |||
9408 | } | |||
9409 | ||||
9410 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] | |||
9411 | // A variable of class type (or array thereof) that appears in a | |||
9412 | // copyin clause requires an accessible, unambiguous copy assignment | |||
9413 | // operator for the class type. | |||
9414 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); | |||
9415 | auto *SrcVD = | |||
9416 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), | |||
9417 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); | |||
9418 | auto *PseudoSrcExpr = buildDeclRefExpr( | |||
9419 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); | |||
9420 | auto *DstVD = | |||
9421 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", | |||
9422 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); | |||
9423 | auto *PseudoDstExpr = | |||
9424 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); | |||
9425 | // For arrays generate assignment operation for single element and replace | |||
9426 | // it by the original array element in CodeGen. | |||
9427 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, | |||
9428 | PseudoDstExpr, PseudoSrcExpr); | |||
9429 | if (AssignmentOp.isInvalid()) | |||
9430 | continue; | |||
9431 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), | |||
9432 | /*DiscardedValue=*/true); | |||
9433 | if (AssignmentOp.isInvalid()) | |||
9434 | continue; | |||
9435 | ||||
9436 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addDSA(VD, DE, OMPC_copyin); | |||
9437 | Vars.push_back(DE); | |||
9438 | SrcExprs.push_back(PseudoSrcExpr); | |||
9439 | DstExprs.push_back(PseudoDstExpr); | |||
9440 | AssignmentOps.push_back(AssignmentOp.get()); | |||
9441 | } | |||
9442 | ||||
9443 | if (Vars.empty()) | |||
9444 | return nullptr; | |||
9445 | ||||
9446 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, | |||
9447 | SrcExprs, DstExprs, AssignmentOps); | |||
9448 | } | |||
9449 | ||||
9450 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, | |||
9451 | SourceLocation StartLoc, | |||
9452 | SourceLocation LParenLoc, | |||
9453 | SourceLocation EndLoc) { | |||
9454 | SmallVector<Expr *, 8> Vars; | |||
9455 | SmallVector<Expr *, 8> SrcExprs; | |||
9456 | SmallVector<Expr *, 8> DstExprs; | |||
9457 | SmallVector<Expr *, 8> AssignmentOps; | |||
9458 | for (auto &RefExpr : VarList) { | |||
9459 | assert(RefExpr && "NULL expr in OpenMP linear clause.")((RefExpr && "NULL expr in OpenMP linear clause.") ? static_cast <void> (0) : __assert_fail ("RefExpr && \"NULL expr in OpenMP linear clause.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 9459, __PRETTY_FUNCTION__)); | |||
9460 | SourceLocation ELoc; | |||
9461 | SourceRange ERange; | |||
9462 | Expr *SimpleRefExpr = RefExpr; | |||
9463 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, | |||
9464 | /*AllowArraySection=*/false); | |||
9465 | if (Res.second) { | |||
9466 | // It will be analyzed later. | |||
9467 | Vars.push_back(RefExpr); | |||
9468 | SrcExprs.push_back(nullptr); | |||
9469 | DstExprs.push_back(nullptr); | |||
9470 | AssignmentOps.push_back(nullptr); | |||
9471 | } | |||
9472 | ValueDecl *D = Res.first; | |||
9473 | if (!D) | |||
9474 | continue; | |||
9475 | ||||
9476 | QualType Type = D->getType(); | |||
9477 | auto *VD = dyn_cast<VarDecl>(D); | |||
9478 | ||||
9479 | // OpenMP [2.14.4.2, Restrictions, p.2] | |||
9480 | // A list item that appears in a copyprivate clause may not appear in a | |||
9481 | // private or firstprivate clause on the single construct. | |||
9482 | if (!VD || !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isThreadPrivate(VD)) { | |||
9483 | auto DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, false); | |||
9484 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && | |||
9485 | DVar.RefExpr) { | |||
9486 | Diag(ELoc, diag::err_omp_wrong_dsa) | |||
9487 | << getOpenMPClauseName(DVar.CKind) | |||
9488 | << getOpenMPClauseName(OMPC_copyprivate); | |||
9489 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
9490 | continue; | |||
9491 | } | |||
9492 | ||||
9493 | // OpenMP [2.11.4.2, Restrictions, p.1] | |||
9494 | // All list items that appear in a copyprivate clause must be either | |||
9495 | // threadprivate or private in the enclosing context. | |||
9496 | if (DVar.CKind == OMPC_unknown) { | |||
9497 | DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getImplicitDSA(D, false); | |||
9498 | if (DVar.CKind == OMPC_shared) { | |||
9499 | Diag(ELoc, diag::err_omp_required_access) | |||
9500 | << getOpenMPClauseName(OMPC_copyprivate) | |||
9501 | << "threadprivate or private in the enclosing context"; | |||
9502 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D, DVar); | |||
9503 | continue; | |||
9504 | } | |||
9505 | } | |||
9506 | } | |||
9507 | ||||
9508 | // Variably modified types are not supported. | |||
9509 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { | |||
9510 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) | |||
9511 | << getOpenMPClauseName(OMPC_copyprivate) << Type | |||
9512 | << getOpenMPDirectiveName(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()); | |||
9513 | bool IsDecl = | |||
9514 | !VD || | |||
9515 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; | |||
9516 | Diag(D->getLocation(), | |||
9517 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) | |||
9518 | << D; | |||
9519 | continue; | |||
9520 | } | |||
9521 | ||||
9522 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] | |||
9523 | // A variable of class type (or array thereof) that appears in a | |||
9524 | // copyin clause requires an accessible, unambiguous copy assignment | |||
9525 | // operator for the class type. | |||
9526 | Type = Context.getBaseElementType(Type.getNonReferenceType()) | |||
9527 | .getUnqualifiedType(); | |||
9528 | auto *SrcVD = | |||
9529 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", | |||
9530 | D->hasAttrs() ? &D->getAttrs() : nullptr); | |||
9531 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); | |||
9532 | auto *DstVD = | |||
9533 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", | |||
9534 | D->hasAttrs() ? &D->getAttrs() : nullptr); | |||
9535 | auto *PseudoDstExpr = | |||
9536 | buildDeclRefExpr(*this, DstVD, Type, ELoc); | |||
9537 | auto AssignmentOp = BuildBinOp(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurScope(), ELoc, BO_Assign, | |||
9538 | PseudoDstExpr, PseudoSrcExpr); | |||
9539 | if (AssignmentOp.isInvalid()) | |||
9540 | continue; | |||
9541 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, | |||
9542 | /*DiscardedValue=*/true); | |||
9543 | if (AssignmentOp.isInvalid()) | |||
9544 | continue; | |||
9545 | ||||
9546 | // No need to mark vars as copyprivate, they are already threadprivate or | |||
9547 | // implicitly private. | |||
9548 | assert(VD || IsOpenMPCapturedDecl(D))((VD || IsOpenMPCapturedDecl(D)) ? static_cast<void> (0 ) : __assert_fail ("VD || IsOpenMPCapturedDecl(D)", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 9548, __PRETTY_FUNCTION__)); | |||
9549 | Vars.push_back( | |||
9550 | VD ? RefExpr->IgnoreParens() | |||
9551 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); | |||
9552 | SrcExprs.push_back(PseudoSrcExpr); | |||
9553 | DstExprs.push_back(PseudoDstExpr); | |||
9554 | AssignmentOps.push_back(AssignmentOp.get()); | |||
9555 | } | |||
9556 | ||||
9557 | if (Vars.empty()) | |||
9558 | return nullptr; | |||
9559 | ||||
9560 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, | |||
9561 | Vars, SrcExprs, DstExprs, AssignmentOps); | |||
9562 | } | |||
9563 | ||||
9564 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, | |||
9565 | SourceLocation StartLoc, | |||
9566 | SourceLocation LParenLoc, | |||
9567 | SourceLocation EndLoc) { | |||
9568 | if (VarList.empty()) | |||
9569 | return nullptr; | |||
9570 | ||||
9571 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); | |||
9572 | } | |||
9573 | ||||
9574 | OMPClause * | |||
9575 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, | |||
9576 | SourceLocation DepLoc, SourceLocation ColonLoc, | |||
9577 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, | |||
9578 | SourceLocation LParenLoc, SourceLocation EndLoc) { | |||
9579 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective() == OMPD_ordered && | |||
9580 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { | |||
9581 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) | |||
9582 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); | |||
9583 | return nullptr; | |||
9584 | } | |||
9585 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective() != OMPD_ordered && | |||
9586 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || | |||
9587 | DepKind == OMPC_DEPEND_sink)) { | |||
9588 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; | |||
9589 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) | |||
9590 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, | |||
9591 | /*Last=*/OMPC_DEPEND_unknown, Except) | |||
9592 | << getOpenMPClauseName(OMPC_depend); | |||
9593 | return nullptr; | |||
9594 | } | |||
9595 | SmallVector<Expr *, 8> Vars; | |||
9596 | DSAStackTy::OperatorOffsetTy OpsOffs; | |||
9597 | llvm::APSInt DepCounter(/*BitWidth=*/32); | |||
9598 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); | |||
9599 | if (DepKind == OMPC_DEPEND_sink) { | |||
9600 | if (auto *OrderedCountExpr = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getParentOrderedRegionParam()) { | |||
9601 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); | |||
9602 | TotalDepCount.setIsUnsigned(/*Val=*/true); | |||
9603 | } | |||
9604 | } | |||
9605 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || | |||
9606 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getParentOrderedRegionParam()) { | |||
9607 | for (auto &RefExpr : VarList) { | |||
9608 | assert(RefExpr && "NULL expr in OpenMP shared clause.")((RefExpr && "NULL expr in OpenMP shared clause.") ? static_cast <void> (0) : __assert_fail ("RefExpr && \"NULL expr in OpenMP shared clause.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 9608, __PRETTY_FUNCTION__)); | |||
9609 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { | |||
9610 | // It will be analyzed later. | |||
9611 | Vars.push_back(RefExpr); | |||
9612 | continue; | |||
9613 | } | |||
9614 | ||||
9615 | SourceLocation ELoc = RefExpr->getExprLoc(); | |||
9616 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); | |||
9617 | if (DepKind == OMPC_DEPEND_sink) { | |||
9618 | if (DepCounter >= TotalDepCount) { | |||
9619 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); | |||
9620 | continue; | |||
9621 | } | |||
9622 | ++DepCounter; | |||
9623 | // OpenMP [2.13.9, Summary] | |||
9624 | // depend(dependence-type : vec), where dependence-type is: | |||
9625 | // 'sink' and where vec is the iteration vector, which has the form: | |||
9626 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] | |||
9627 | // where n is the value specified by the ordered clause in the loop | |||
9628 | // directive, xi denotes the loop iteration variable of the i-th nested | |||
9629 | // loop associated with the loop directive, and di is a constant | |||
9630 | // non-negative integer. | |||
9631 | if (CurContext->isDependentContext()) { | |||
9632 | // It will be analyzed later. | |||
9633 | Vars.push_back(RefExpr); | |||
9634 | continue; | |||
9635 | } | |||
9636 | SimpleExpr = SimpleExpr->IgnoreImplicit(); | |||
9637 | OverloadedOperatorKind OOK = OO_None; | |||
9638 | SourceLocation OOLoc; | |||
9639 | Expr *LHS = SimpleExpr; | |||
9640 | Expr *RHS = nullptr; | |||
9641 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { | |||
9642 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); | |||
9643 | OOLoc = BO->getOperatorLoc(); | |||
9644 | LHS = BO->getLHS()->IgnoreParenImpCasts(); | |||
9645 | RHS = BO->getRHS()->IgnoreParenImpCasts(); | |||
9646 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { | |||
9647 | OOK = OCE->getOperator(); | |||
9648 | OOLoc = OCE->getOperatorLoc(); | |||
9649 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); | |||
9650 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); | |||
9651 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { | |||
9652 | OOK = MCE->getMethodDecl() | |||
9653 | ->getNameInfo() | |||
9654 | .getName() | |||
9655 | .getCXXOverloadedOperator(); | |||
9656 | OOLoc = MCE->getCallee()->getExprLoc(); | |||
9657 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); | |||
9658 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); | |||
9659 | } | |||
9660 | SourceLocation ELoc; | |||
9661 | SourceRange ERange; | |||
9662 | auto Res = getPrivateItem(*this, LHS, ELoc, ERange, | |||
9663 | /*AllowArraySection=*/false); | |||
9664 | if (Res.second) { | |||
9665 | // It will be analyzed later. | |||
9666 | Vars.push_back(RefExpr); | |||
9667 | } | |||
9668 | ValueDecl *D = Res.first; | |||
9669 | if (!D) | |||
9670 | continue; | |||
9671 | ||||
9672 | if (OOK != OO_Plus && OOK != OO_Minus && (RHS || OOK != OO_None)) { | |||
9673 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); | |||
9674 | continue; | |||
9675 | } | |||
9676 | if (RHS) { | |||
9677 | ExprResult RHSRes = VerifyPositiveIntegerConstantInClause( | |||
9678 | RHS, OMPC_depend, /*StrictlyPositive=*/false); | |||
9679 | if (RHSRes.isInvalid()) | |||
9680 | continue; | |||
9681 | } | |||
9682 | if (!CurContext->isDependentContext() && | |||
9683 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getParentOrderedRegionParam() && | |||
9684 | DepCounter != DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isParentLoopControlVariable(D).first) { | |||
9685 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) | |||
9686 | << DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getParentLoopControlVariable( | |||
9687 | DepCounter.getZExtValue()); | |||
9688 | continue; | |||
9689 | } | |||
9690 | OpsOffs.push_back({RHS, OOK}); | |||
9691 | } else { | |||
9692 | // OpenMP [2.11.1.1, Restrictions, p.3] | |||
9693 | // A variable that is part of another variable (such as a field of a | |||
9694 | // structure) but is not an array element or an array section cannot | |||
9695 | // appear in a depend clause. | |||
9696 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); | |||
9697 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); | |||
9698 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); | |||
9699 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || | |||
9700 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || | |||
9701 | (ASE && | |||
9702 | !ASE->getBase() | |||
9703 | ->getType() | |||
9704 | .getNonReferenceType() | |||
9705 | ->isPointerType() && | |||
9706 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { | |||
9707 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) | |||
9708 | << 0 << RefExpr->getSourceRange(); | |||
9709 | continue; | |||
9710 | } | |||
9711 | } | |||
9712 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); | |||
9713 | } | |||
9714 | ||||
9715 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && | |||
9716 | TotalDepCount > VarList.size() && | |||
9717 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getParentOrderedRegionParam()) { | |||
9718 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) | |||
9719 | << DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getParentLoopControlVariable(VarList.size() + 1); | |||
9720 | } | |||
9721 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && | |||
9722 | Vars.empty()) | |||
9723 | return nullptr; | |||
9724 | } | |||
9725 | auto *C = OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, | |||
9726 | DepKind, DepLoc, ColonLoc, Vars); | |||
9727 | if (DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) | |||
9728 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addDoacrossDependClause(C, OpsOffs); | |||
9729 | return C; | |||
9730 | } | |||
9731 | ||||
9732 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, | |||
9733 | SourceLocation LParenLoc, | |||
9734 | SourceLocation EndLoc) { | |||
9735 | Expr *ValExpr = Device; | |||
9736 | ||||
9737 | // OpenMP [2.9.1, Restrictions] | |||
9738 | // The device expression must evaluate to a non-negative integer value. | |||
9739 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, | |||
9740 | /*StrictlyPositive=*/false)) | |||
9741 | return nullptr; | |||
9742 | ||||
9743 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); | |||
9744 | } | |||
9745 | ||||
9746 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, | |||
9747 | DSAStackTy *Stack, CXXRecordDecl *RD) { | |||
9748 | if (!RD || RD->isInvalidDecl()) | |||
9749 | return true; | |||
9750 | ||||
9751 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) | |||
9752 | if (auto *CTD = CTSD->getSpecializedTemplate()) | |||
9753 | RD = CTD->getTemplatedDecl(); | |||
9754 | auto QTy = SemaRef.Context.getRecordType(RD); | |||
9755 | if (RD->isDynamicClass()) { | |||
9756 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; | |||
9757 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); | |||
9758 | return false; | |||
9759 | } | |||
9760 | auto *DC = RD; | |||
9761 | bool IsCorrect = true; | |||
9762 | for (auto *I : DC->decls()) { | |||
9763 | if (I) { | |||
9764 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { | |||
9765 | if (MD->isStatic()) { | |||
9766 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; | |||
9767 | SemaRef.Diag(MD->getLocation(), | |||
9768 | diag::note_omp_static_member_in_target); | |||
9769 | IsCorrect = false; | |||
9770 | } | |||
9771 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { | |||
9772 | if (VD->isStaticDataMember()) { | |||
9773 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; | |||
9774 | SemaRef.Diag(VD->getLocation(), | |||
9775 | diag::note_omp_static_member_in_target); | |||
9776 | IsCorrect = false; | |||
9777 | } | |||
9778 | } | |||
9779 | } | |||
9780 | } | |||
9781 | ||||
9782 | for (auto &I : RD->bases()) { | |||
9783 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, | |||
9784 | I.getType()->getAsCXXRecordDecl())) | |||
9785 | IsCorrect = false; | |||
9786 | } | |||
9787 | return IsCorrect; | |||
9788 | } | |||
9789 | ||||
9790 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, | |||
9791 | DSAStackTy *Stack, QualType QTy) { | |||
9792 | NamedDecl *ND; | |||
9793 | if (QTy->isIncompleteType(&ND)) { | |||
9794 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; | |||
9795 | return false; | |||
9796 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { | |||
9797 | if (!RD->isInvalidDecl() && | |||
9798 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) | |||
9799 | return false; | |||
9800 | } | |||
9801 | return true; | |||
9802 | } | |||
9803 | ||||
9804 | /// \brief Return true if it can be proven that the provided array expression | |||
9805 | /// (array section or array subscript) does NOT specify the whole size of the | |||
9806 | /// array whose base type is \a BaseQTy. | |||
9807 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, | |||
9808 | const Expr *E, | |||
9809 | QualType BaseQTy) { | |||
9810 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); | |||
9811 | ||||
9812 | // If this is an array subscript, it refers to the whole size if the size of | |||
9813 | // the dimension is constant and equals 1. Also, an array section assumes the | |||
9814 | // format of an array subscript if no colon is used. | |||
9815 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { | |||
9816 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) | |||
9817 | return ATy->getSize().getSExtValue() != 1; | |||
9818 | // Size can't be evaluated statically. | |||
9819 | return false; | |||
9820 | } | |||
9821 | ||||
9822 | assert(OASE && "Expecting array section if not an array subscript.")((OASE && "Expecting array section if not an array subscript." ) ? static_cast<void> (0) : __assert_fail ("OASE && \"Expecting array section if not an array subscript.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 9822, __PRETTY_FUNCTION__)); | |||
9823 | auto *LowerBound = OASE->getLowerBound(); | |||
9824 | auto *Length = OASE->getLength(); | |||
9825 | ||||
9826 | // If there is a lower bound that does not evaluates to zero, we are not | |||
9827 | // convering the whole dimension. | |||
9828 | if (LowerBound) { | |||
9829 | llvm::APSInt ConstLowerBound; | |||
9830 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) | |||
9831 | return false; // Can't get the integer value as a constant. | |||
9832 | if (ConstLowerBound.getSExtValue()) | |||
9833 | return true; | |||
9834 | } | |||
9835 | ||||
9836 | // If we don't have a length we covering the whole dimension. | |||
9837 | if (!Length) | |||
9838 | return false; | |||
9839 | ||||
9840 | // If the base is a pointer, we don't have a way to get the size of the | |||
9841 | // pointee. | |||
9842 | if (BaseQTy->isPointerType()) | |||
9843 | return false; | |||
9844 | ||||
9845 | // We can only check if the length is the same as the size of the dimension | |||
9846 | // if we have a constant array. | |||
9847 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); | |||
9848 | if (!CATy) | |||
9849 | return false; | |||
9850 | ||||
9851 | llvm::APSInt ConstLength; | |||
9852 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) | |||
9853 | return false; // Can't get the integer value as a constant. | |||
9854 | ||||
9855 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); | |||
9856 | } | |||
9857 | ||||
9858 | // Return true if it can be proven that the provided array expression (array | |||
9859 | // section or array subscript) does NOT specify a single element of the array | |||
9860 | // whose base type is \a BaseQTy. | |||
9861 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, | |||
9862 | const Expr *E, | |||
9863 | QualType BaseQTy) { | |||
9864 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); | |||
9865 | ||||
9866 | // An array subscript always refer to a single element. Also, an array section | |||
9867 | // assumes the format of an array subscript if no colon is used. | |||
9868 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) | |||
9869 | return false; | |||
9870 | ||||
9871 | assert(OASE && "Expecting array section if not an array subscript.")((OASE && "Expecting array section if not an array subscript." ) ? static_cast<void> (0) : __assert_fail ("OASE && \"Expecting array section if not an array subscript.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 9871, __PRETTY_FUNCTION__)); | |||
9872 | auto *Length = OASE->getLength(); | |||
9873 | ||||
9874 | // If we don't have a length we have to check if the array has unitary size | |||
9875 | // for this dimension. Also, we should always expect a length if the base type | |||
9876 | // is pointer. | |||
9877 | if (!Length) { | |||
9878 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) | |||
9879 | return ATy->getSize().getSExtValue() != 1; | |||
9880 | // We cannot assume anything. | |||
9881 | return false; | |||
9882 | } | |||
9883 | ||||
9884 | // Check if the length evaluates to 1. | |||
9885 | llvm::APSInt ConstLength; | |||
9886 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) | |||
9887 | return false; // Can't get the integer value as a constant. | |||
9888 | ||||
9889 | return ConstLength.getSExtValue() != 1; | |||
9890 | } | |||
9891 | ||||
9892 | // Return the expression of the base of the mappable expression or null if it | |||
9893 | // cannot be determined and do all the necessary checks to see if the expression | |||
9894 | // is valid as a standalone mappable expression. In the process, record all the | |||
9895 | // components of the expression. | |||
9896 | static Expr *CheckMapClauseExpressionBase( | |||
9897 | Sema &SemaRef, Expr *E, | |||
9898 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, | |||
9899 | OpenMPClauseKind CKind) { | |||
9900 | SourceLocation ELoc = E->getExprLoc(); | |||
9901 | SourceRange ERange = E->getSourceRange(); | |||
9902 | ||||
9903 | // The base of elements of list in a map clause have to be either: | |||
9904 | // - a reference to variable or field. | |||
9905 | // - a member expression. | |||
9906 | // - an array expression. | |||
9907 | // | |||
9908 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the | |||
9909 | // reference to 'r'. | |||
9910 | // | |||
9911 | // If we have: | |||
9912 | // | |||
9913 | // struct SS { | |||
9914 | // Bla S; | |||
9915 | // foo() { | |||
9916 | // #pragma omp target map (S.Arr[:12]); | |||
9917 | // } | |||
9918 | // } | |||
9919 | // | |||
9920 | // We want to retrieve the member expression 'this->S'; | |||
9921 | ||||
9922 | Expr *RelevantExpr = nullptr; | |||
9923 | ||||
9924 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] | |||
9925 | // If a list item is an array section, it must specify contiguous storage. | |||
9926 | // | |||
9927 | // For this restriction it is sufficient that we make sure only references | |||
9928 | // to variables or fields and array expressions, and that no array sections | |||
9929 | // exist except in the rightmost expression (unless they cover the whole | |||
9930 | // dimension of the array). E.g. these would be invalid: | |||
9931 | // | |||
9932 | // r.ArrS[3:5].Arr[6:7] | |||
9933 | // | |||
9934 | // r.ArrS[3:5].x | |||
9935 | // | |||
9936 | // but these would be valid: | |||
9937 | // r.ArrS[3].Arr[6:7] | |||
9938 | // | |||
9939 | // r.ArrS[3].x | |||
9940 | ||||
9941 | bool AllowUnitySizeArraySection = true; | |||
9942 | bool AllowWholeSizeArraySection = true; | |||
9943 | ||||
9944 | while (!RelevantExpr) { | |||
9945 | E = E->IgnoreParenImpCasts(); | |||
9946 | ||||
9947 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { | |||
9948 | if (!isa<VarDecl>(CurE->getDecl())) | |||
9949 | break; | |||
9950 | ||||
9951 | RelevantExpr = CurE; | |||
9952 | ||||
9953 | // If we got a reference to a declaration, we should not expect any array | |||
9954 | // section before that. | |||
9955 | AllowUnitySizeArraySection = false; | |||
9956 | AllowWholeSizeArraySection = false; | |||
9957 | ||||
9958 | // Record the component. | |||
9959 | CurComponents.push_back(OMPClauseMappableExprCommon::MappableComponent( | |||
9960 | CurE, CurE->getDecl())); | |||
9961 | continue; | |||
9962 | } | |||
9963 | ||||
9964 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { | |||
9965 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); | |||
9966 | ||||
9967 | if (isa<CXXThisExpr>(BaseE)) | |||
9968 | // We found a base expression: this->Val. | |||
9969 | RelevantExpr = CurE; | |||
9970 | else | |||
9971 | E = BaseE; | |||
9972 | ||||
9973 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { | |||
9974 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) | |||
9975 | << CurE->getSourceRange(); | |||
9976 | break; | |||
9977 | } | |||
9978 | ||||
9979 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); | |||
9980 | ||||
9981 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] | |||
9982 | // A bit-field cannot appear in a map clause. | |||
9983 | // | |||
9984 | if (FD->isBitField()) { | |||
9985 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause) | |||
9986 | << CurE->getSourceRange() << getOpenMPClauseName(CKind); | |||
9987 | break; | |||
9988 | } | |||
9989 | ||||
9990 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] | |||
9991 | // If the type of a list item is a reference to a type T then the type | |||
9992 | // will be considered to be T for all purposes of this clause. | |||
9993 | QualType CurType = BaseE->getType().getNonReferenceType(); | |||
9994 | ||||
9995 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] | |||
9996 | // A list item cannot be a variable that is a member of a structure with | |||
9997 | // a union type. | |||
9998 | // | |||
9999 | if (auto *RT = CurType->getAs<RecordType>()) | |||
10000 | if (RT->isUnionType()) { | |||
10001 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) | |||
10002 | << CurE->getSourceRange(); | |||
10003 | break; | |||
10004 | } | |||
10005 | ||||
10006 | // If we got a member expression, we should not expect any array section | |||
10007 | // before that: | |||
10008 | // | |||
10009 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] | |||
10010 | // If a list item is an element of a structure, only the rightmost symbol | |||
10011 | // of the variable reference can be an array section. | |||
10012 | // | |||
10013 | AllowUnitySizeArraySection = false; | |||
10014 | AllowWholeSizeArraySection = false; | |||
10015 | ||||
10016 | // Record the component. | |||
10017 | CurComponents.push_back( | |||
10018 | OMPClauseMappableExprCommon::MappableComponent(CurE, FD)); | |||
10019 | continue; | |||
10020 | } | |||
10021 | ||||
10022 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { | |||
10023 | E = CurE->getBase()->IgnoreParenImpCasts(); | |||
10024 | ||||
10025 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { | |||
10026 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) | |||
10027 | << 0 << CurE->getSourceRange(); | |||
10028 | break; | |||
10029 | } | |||
10030 | ||||
10031 | // If we got an array subscript that express the whole dimension we | |||
10032 | // can have any array expressions before. If it only expressing part of | |||
10033 | // the dimension, we can only have unitary-size array expressions. | |||
10034 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, | |||
10035 | E->getType())) | |||
10036 | AllowWholeSizeArraySection = false; | |||
10037 | ||||
10038 | // Record the component - we don't have any declaration associated. | |||
10039 | CurComponents.push_back( | |||
10040 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); | |||
10041 | continue; | |||
10042 | } | |||
10043 | ||||
10044 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { | |||
10045 | E = CurE->getBase()->IgnoreParenImpCasts(); | |||
10046 | ||||
10047 | auto CurType = | |||
10048 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); | |||
10049 | ||||
10050 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] | |||
10051 | // If the type of a list item is a reference to a type T then the type | |||
10052 | // will be considered to be T for all purposes of this clause. | |||
10053 | if (CurType->isReferenceType()) | |||
10054 | CurType = CurType->getPointeeType(); | |||
10055 | ||||
10056 | bool IsPointer = CurType->isAnyPointerType(); | |||
10057 | ||||
10058 | if (!IsPointer && !CurType->isArrayType()) { | |||
10059 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) | |||
10060 | << 0 << CurE->getSourceRange(); | |||
10061 | break; | |||
10062 | } | |||
10063 | ||||
10064 | bool NotWhole = | |||
10065 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); | |||
10066 | bool NotUnity = | |||
10067 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); | |||
10068 | ||||
10069 | if (AllowWholeSizeArraySection && AllowUnitySizeArraySection) { | |||
10070 | // Any array section is currently allowed. | |||
10071 | // | |||
10072 | // If this array section refers to the whole dimension we can still | |||
10073 | // accept other array sections before this one, except if the base is a | |||
10074 | // pointer. Otherwise, only unitary sections are accepted. | |||
10075 | if (NotWhole || IsPointer) | |||
10076 | AllowWholeSizeArraySection = false; | |||
10077 | } else if ((AllowUnitySizeArraySection && NotUnity) || | |||
10078 | (AllowWholeSizeArraySection && NotWhole)) { | |||
10079 | // A unity or whole array section is not allowed and that is not | |||
10080 | // compatible with the properties of the current array section. | |||
10081 | SemaRef.Diag( | |||
10082 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) | |||
10083 | << CurE->getSourceRange(); | |||
10084 | break; | |||
10085 | } | |||
10086 | ||||
10087 | // Record the component - we don't have any declaration associated. | |||
10088 | CurComponents.push_back( | |||
10089 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); | |||
10090 | continue; | |||
10091 | } | |||
10092 | ||||
10093 | // If nothing else worked, this is not a valid map clause expression. | |||
10094 | SemaRef.Diag(ELoc, | |||
10095 | diag::err_omp_expected_named_var_member_or_array_expression) | |||
10096 | << ERange; | |||
10097 | break; | |||
10098 | } | |||
10099 | ||||
10100 | return RelevantExpr; | |||
10101 | } | |||
10102 | ||||
10103 | // Return true if expression E associated with value VD has conflicts with other | |||
10104 | // map information. | |||
10105 | static bool CheckMapConflicts( | |||
10106 | Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, Expr *E, | |||
10107 | bool CurrentRegionOnly, | |||
10108 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents, | |||
10109 | OpenMPClauseKind CKind) { | |||
10110 | assert(VD && E)((VD && E) ? static_cast<void> (0) : __assert_fail ("VD && E", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10110, __PRETTY_FUNCTION__)); | |||
10111 | SourceLocation ELoc = E->getExprLoc(); | |||
10112 | SourceRange ERange = E->getSourceRange(); | |||
10113 | ||||
10114 | // In order to easily check the conflicts we need to match each component of | |||
10115 | // the expression under test with the components of the expressions that are | |||
10116 | // already in the stack. | |||
10117 | ||||
10118 | assert(!CurComponents.empty() && "Map clause expression with no components!")((!CurComponents.empty() && "Map clause expression with no components!" ) ? static_cast<void> (0) : __assert_fail ("!CurComponents.empty() && \"Map clause expression with no components!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10118, __PRETTY_FUNCTION__)); | |||
10119 | assert(CurComponents.back().getAssociatedDeclaration() == VD &&((CurComponents.back().getAssociatedDeclaration() == VD && "Map clause expression with unexpected base!") ? static_cast <void> (0) : __assert_fail ("CurComponents.back().getAssociatedDeclaration() == VD && \"Map clause expression with unexpected base!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10120, __PRETTY_FUNCTION__)) | |||
10120 | "Map clause expression with unexpected base!")((CurComponents.back().getAssociatedDeclaration() == VD && "Map clause expression with unexpected base!") ? static_cast <void> (0) : __assert_fail ("CurComponents.back().getAssociatedDeclaration() == VD && \"Map clause expression with unexpected base!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10120, __PRETTY_FUNCTION__)); | |||
10121 | ||||
10122 | // Variables to help detecting enclosing problems in data environment nests. | |||
10123 | bool IsEnclosedByDataEnvironmentExpr = false; | |||
10124 | const Expr *EnclosingExpr = nullptr; | |||
10125 | ||||
10126 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( | |||
10127 | VD, CurrentRegionOnly, | |||
10128 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef | |||
10129 | StackComponents) -> bool { | |||
10130 | ||||
10131 | assert(!StackComponents.empty() &&((!StackComponents.empty() && "Map clause expression with no components!" ) ? static_cast<void> (0) : __assert_fail ("!StackComponents.empty() && \"Map clause expression with no components!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10132, __PRETTY_FUNCTION__)) | |||
10132 | "Map clause expression with no components!")((!StackComponents.empty() && "Map clause expression with no components!" ) ? static_cast<void> (0) : __assert_fail ("!StackComponents.empty() && \"Map clause expression with no components!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10132, __PRETTY_FUNCTION__)); | |||
10133 | assert(StackComponents.back().getAssociatedDeclaration() == VD &&((StackComponents.back().getAssociatedDeclaration() == VD && "Map clause expression with unexpected base!") ? static_cast <void> (0) : __assert_fail ("StackComponents.back().getAssociatedDeclaration() == VD && \"Map clause expression with unexpected base!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10134, __PRETTY_FUNCTION__)) | |||
10134 | "Map clause expression with unexpected base!")((StackComponents.back().getAssociatedDeclaration() == VD && "Map clause expression with unexpected base!") ? static_cast <void> (0) : __assert_fail ("StackComponents.back().getAssociatedDeclaration() == VD && \"Map clause expression with unexpected base!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10134, __PRETTY_FUNCTION__)); | |||
10135 | ||||
10136 | // The whole expression in the stack. | |||
10137 | auto *RE = StackComponents.front().getAssociatedExpression(); | |||
10138 | ||||
10139 | // Expressions must start from the same base. Here we detect at which | |||
10140 | // point both expressions diverge from each other and see if we can | |||
10141 | // detect if the memory referred to both expressions is contiguous and | |||
10142 | // do not overlap. | |||
10143 | auto CI = CurComponents.rbegin(); | |||
10144 | auto CE = CurComponents.rend(); | |||
10145 | auto SI = StackComponents.rbegin(); | |||
10146 | auto SE = StackComponents.rend(); | |||
10147 | for (; CI != CE && SI != SE; ++CI, ++SI) { | |||
10148 | ||||
10149 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] | |||
10150 | // At most one list item can be an array item derived from a given | |||
10151 | // variable in map clauses of the same construct. | |||
10152 | if (CurrentRegionOnly && | |||
10153 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || | |||
10154 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && | |||
10155 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || | |||
10156 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { | |||
10157 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), | |||
10158 | diag::err_omp_multiple_array_items_in_map_clause) | |||
10159 | << CI->getAssociatedExpression()->getSourceRange(); | |||
10160 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), | |||
10161 | diag::note_used_here) | |||
10162 | << SI->getAssociatedExpression()->getSourceRange(); | |||
10163 | return true; | |||
10164 | } | |||
10165 | ||||
10166 | // Do both expressions have the same kind? | |||
10167 | if (CI->getAssociatedExpression()->getStmtClass() != | |||
10168 | SI->getAssociatedExpression()->getStmtClass()) | |||
10169 | break; | |||
10170 | ||||
10171 | // Are we dealing with different variables/fields? | |||
10172 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) | |||
10173 | break; | |||
10174 | } | |||
10175 | ||||
10176 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] | |||
10177 | // List items of map clauses in the same construct must not share | |||
10178 | // original storage. | |||
10179 | // | |||
10180 | // If the expressions are exactly the same or one is a subset of the | |||
10181 | // other, it means they are sharing storage. | |||
10182 | if (CI == CE && SI == SE) { | |||
10183 | if (CurrentRegionOnly) { | |||
10184 | if (CKind == OMPC_map) | |||
10185 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; | |||
10186 | else { | |||
10187 | assert(CKind == OMPC_to || CKind == OMPC_from)((CKind == OMPC_to || CKind == OMPC_from) ? static_cast<void > (0) : __assert_fail ("CKind == OMPC_to || CKind == OMPC_from" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10187, __PRETTY_FUNCTION__)); | |||
10188 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) | |||
10189 | << ERange; | |||
10190 | } | |||
10191 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) | |||
10192 | << RE->getSourceRange(); | |||
10193 | return true; | |||
10194 | } else { | |||
10195 | // If we find the same expression in the enclosing data environment, | |||
10196 | // that is legal. | |||
10197 | IsEnclosedByDataEnvironmentExpr = true; | |||
10198 | return false; | |||
10199 | } | |||
10200 | } | |||
10201 | ||||
10202 | QualType DerivedType = | |||
10203 | std::prev(CI)->getAssociatedDeclaration()->getType(); | |||
10204 | SourceLocation DerivedLoc = | |||
10205 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); | |||
10206 | ||||
10207 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] | |||
10208 | // If the type of a list item is a reference to a type T then the type | |||
10209 | // will be considered to be T for all purposes of this clause. | |||
10210 | DerivedType = DerivedType.getNonReferenceType(); | |||
10211 | ||||
10212 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] | |||
10213 | // A variable for which the type is pointer and an array section | |||
10214 | // derived from that variable must not appear as list items of map | |||
10215 | // clauses of the same construct. | |||
10216 | // | |||
10217 | // Also, cover one of the cases in: | |||
10218 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] | |||
10219 | // If any part of the original storage of a list item has corresponding | |||
10220 | // storage in the device data environment, all of the original storage | |||
10221 | // must have corresponding storage in the device data environment. | |||
10222 | // | |||
10223 | if (DerivedType->isAnyPointerType()) { | |||
10224 | if (CI == CE || SI == SE) { | |||
10225 | SemaRef.Diag( | |||
10226 | DerivedLoc, | |||
10227 | diag::err_omp_pointer_mapped_along_with_derived_section) | |||
10228 | << DerivedLoc; | |||
10229 | } else { | |||
10230 | assert(CI != CE && SI != SE)((CI != CE && SI != SE) ? static_cast<void> (0) : __assert_fail ("CI != CE && SI != SE", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10230, __PRETTY_FUNCTION__)); | |||
10231 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) | |||
10232 | << DerivedLoc; | |||
10233 | } | |||
10234 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) | |||
10235 | << RE->getSourceRange(); | |||
10236 | return true; | |||
10237 | } | |||
10238 | ||||
10239 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] | |||
10240 | // List items of map clauses in the same construct must not share | |||
10241 | // original storage. | |||
10242 | // | |||
10243 | // An expression is a subset of the other. | |||
10244 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { | |||
10245 | if (CKind == OMPC_map) | |||
10246 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; | |||
10247 | else { | |||
10248 | assert(CKind == OMPC_to || CKind == OMPC_from)((CKind == OMPC_to || CKind == OMPC_from) ? static_cast<void > (0) : __assert_fail ("CKind == OMPC_to || CKind == OMPC_from" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10248, __PRETTY_FUNCTION__)); | |||
10249 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) | |||
10250 | << ERange; | |||
10251 | } | |||
10252 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) | |||
10253 | << RE->getSourceRange(); | |||
10254 | return true; | |||
10255 | } | |||
10256 | ||||
10257 | // The current expression uses the same base as other expression in the | |||
10258 | // data environment but does not contain it completely. | |||
10259 | if (!CurrentRegionOnly && SI != SE) | |||
10260 | EnclosingExpr = RE; | |||
10261 | ||||
10262 | // The current expression is a subset of the expression in the data | |||
10263 | // environment. | |||
10264 | IsEnclosedByDataEnvironmentExpr |= | |||
10265 | (!CurrentRegionOnly && CI != CE && SI == SE); | |||
10266 | ||||
10267 | return false; | |||
10268 | }); | |||
10269 | ||||
10270 | if (CurrentRegionOnly) | |||
10271 | return FoundError; | |||
10272 | ||||
10273 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] | |||
10274 | // If any part of the original storage of a list item has corresponding | |||
10275 | // storage in the device data environment, all of the original storage must | |||
10276 | // have corresponding storage in the device data environment. | |||
10277 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] | |||
10278 | // If a list item is an element of a structure, and a different element of | |||
10279 | // the structure has a corresponding list item in the device data environment | |||
10280 | // prior to a task encountering the construct associated with the map clause, | |||
10281 | // then the list item must also have a corresponding list item in the device | |||
10282 | // data environment prior to the task encountering the construct. | |||
10283 | // | |||
10284 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { | |||
10285 | SemaRef.Diag(ELoc, | |||
10286 | diag::err_omp_original_storage_is_shared_and_does_not_contain) | |||
10287 | << ERange; | |||
10288 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) | |||
10289 | << EnclosingExpr->getSourceRange(); | |||
10290 | return true; | |||
10291 | } | |||
10292 | ||||
10293 | return FoundError; | |||
10294 | } | |||
10295 | ||||
10296 | namespace { | |||
10297 | // Utility struct that gathers all the related lists associated with a mappable | |||
10298 | // expression. | |||
10299 | struct MappableVarListInfo final { | |||
10300 | // The list of expressions. | |||
10301 | ArrayRef<Expr *> VarList; | |||
10302 | // The list of processed expressions. | |||
10303 | SmallVector<Expr *, 16> ProcessedVarList; | |||
10304 | // The mappble components for each expression. | |||
10305 | OMPClauseMappableExprCommon::MappableExprComponentLists VarComponents; | |||
10306 | // The base declaration of the variable. | |||
10307 | SmallVector<ValueDecl *, 16> VarBaseDeclarations; | |||
10308 | ||||
10309 | MappableVarListInfo(ArrayRef<Expr *> VarList) : VarList(VarList) { | |||
10310 | // We have a list of components and base declarations for each entry in the | |||
10311 | // variable list. | |||
10312 | VarComponents.reserve(VarList.size()); | |||
10313 | VarBaseDeclarations.reserve(VarList.size()); | |||
10314 | } | |||
10315 | }; | |||
10316 | } | |||
10317 | ||||
10318 | // Check the validity of the provided variable list for the provided clause kind | |||
10319 | // \a CKind. In the check process the valid expressions, and mappable expression | |||
10320 | // components and variables are extracted and used to fill \a Vars, | |||
10321 | // \a ClauseComponents, and \a ClauseBaseDeclarations. \a MapType and | |||
10322 | // \a IsMapTypeImplicit are expected to be valid if the clause kind is 'map'. | |||
10323 | static void | |||
10324 | checkMappableExpressionList(Sema &SemaRef, DSAStackTy *DSAS, | |||
10325 | OpenMPClauseKind CKind, MappableVarListInfo &MVLI, | |||
10326 | SourceLocation StartLoc, | |||
10327 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown, | |||
10328 | bool IsMapTypeImplicit = false) { | |||
10329 | // We only expect mappable expressions in 'to', 'from', and 'map' clauses. | |||
10330 | assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) &&(((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from ) && "Unexpected clause kind with mappable expressions!" ) ? static_cast<void> (0) : __assert_fail ("(CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && \"Unexpected clause kind with mappable expressions!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10331, __PRETTY_FUNCTION__)) | |||
10331 | "Unexpected clause kind with mappable expressions!")(((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from ) && "Unexpected clause kind with mappable expressions!" ) ? static_cast<void> (0) : __assert_fail ("(CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && \"Unexpected clause kind with mappable expressions!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10331, __PRETTY_FUNCTION__)); | |||
10332 | ||||
10333 | // Keep track of the mappable components and base declarations in this clause. | |||
10334 | // Each entry in the list is going to have a list of components associated. We | |||
10335 | // record each set of the components so that we can build the clause later on. | |||
10336 | // In the end we should have the same amount of declarations and component | |||
10337 | // lists. | |||
10338 | ||||
10339 | for (auto &RE : MVLI.VarList) { | |||
10340 | assert(RE && "Null expr in omp to/from/map clause")((RE && "Null expr in omp to/from/map clause") ? static_cast <void> (0) : __assert_fail ("RE && \"Null expr in omp to/from/map clause\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10340, __PRETTY_FUNCTION__)); | |||
10341 | SourceLocation ELoc = RE->getExprLoc(); | |||
10342 | ||||
10343 | auto *VE = RE->IgnoreParenLValueCasts(); | |||
10344 | ||||
10345 | if (VE->isValueDependent() || VE->isTypeDependent() || | |||
10346 | VE->isInstantiationDependent() || | |||
10347 | VE->containsUnexpandedParameterPack()) { | |||
10348 | // We can only analyze this information once the missing information is | |||
10349 | // resolved. | |||
10350 | MVLI.ProcessedVarList.push_back(RE); | |||
10351 | continue; | |||
10352 | } | |||
10353 | ||||
10354 | auto *SimpleExpr = RE->IgnoreParenCasts(); | |||
10355 | ||||
10356 | if (!RE->IgnoreParenImpCasts()->isLValue()) { | |||
10357 | SemaRef.Diag(ELoc, | |||
10358 | diag::err_omp_expected_named_var_member_or_array_expression) | |||
10359 | << RE->getSourceRange(); | |||
10360 | continue; | |||
10361 | } | |||
10362 | ||||
10363 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; | |||
10364 | ValueDecl *CurDeclaration = nullptr; | |||
10365 | ||||
10366 | // Obtain the array or member expression bases if required. Also, fill the | |||
10367 | // components array with all the components identified in the process. | |||
10368 | auto *BE = | |||
10369 | CheckMapClauseExpressionBase(SemaRef, SimpleExpr, CurComponents, CKind); | |||
10370 | if (!BE) | |||
10371 | continue; | |||
10372 | ||||
10373 | assert(!CurComponents.empty() &&((!CurComponents.empty() && "Invalid mappable expression information." ) ? static_cast<void> (0) : __assert_fail ("!CurComponents.empty() && \"Invalid mappable expression information.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10374, __PRETTY_FUNCTION__)) | |||
10374 | "Invalid mappable expression information.")((!CurComponents.empty() && "Invalid mappable expression information." ) ? static_cast<void> (0) : __assert_fail ("!CurComponents.empty() && \"Invalid mappable expression information.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10374, __PRETTY_FUNCTION__)); | |||
10375 | ||||
10376 | // For the following checks, we rely on the base declaration which is | |||
10377 | // expected to be associated with the last component. The declaration is | |||
10378 | // expected to be a variable or a field (if 'this' is being mapped). | |||
10379 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); | |||
10380 | assert(CurDeclaration && "Null decl on map clause.")((CurDeclaration && "Null decl on map clause.") ? static_cast <void> (0) : __assert_fail ("CurDeclaration && \"Null decl on map clause.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10380, __PRETTY_FUNCTION__)); | |||
10381 | assert(((CurDeclaration->isCanonicalDecl() && "Expecting components to have associated only canonical declarations." ) ? static_cast<void> (0) : __assert_fail ("CurDeclaration->isCanonicalDecl() && \"Expecting components to have associated only canonical declarations.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10383, __PRETTY_FUNCTION__)) | |||
10382 | CurDeclaration->isCanonicalDecl() &&((CurDeclaration->isCanonicalDecl() && "Expecting components to have associated only canonical declarations." ) ? static_cast<void> (0) : __assert_fail ("CurDeclaration->isCanonicalDecl() && \"Expecting components to have associated only canonical declarations.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10383, __PRETTY_FUNCTION__)) | |||
10383 | "Expecting components to have associated only canonical declarations.")((CurDeclaration->isCanonicalDecl() && "Expecting components to have associated only canonical declarations." ) ? static_cast<void> (0) : __assert_fail ("CurDeclaration->isCanonicalDecl() && \"Expecting components to have associated only canonical declarations.\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10383, __PRETTY_FUNCTION__)); | |||
10384 | ||||
10385 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); | |||
10386 | auto *FD = dyn_cast<FieldDecl>(CurDeclaration); | |||
10387 | ||||
10388 | assert((VD || FD) && "Only variables or fields are expected here!")(((VD || FD) && "Only variables or fields are expected here!" ) ? static_cast<void> (0) : __assert_fail ("(VD || FD) && \"Only variables or fields are expected here!\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10388, __PRETTY_FUNCTION__)); | |||
10389 | (void)FD; | |||
10390 | ||||
10391 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] | |||
10392 | // threadprivate variables cannot appear in a map clause. | |||
10393 | // OpenMP 4.5 [2.10.5, target update Construct] | |||
10394 | // threadprivate variables cannot appear in a from clause. | |||
10395 | if (VD && DSAS->isThreadPrivate(VD)) { | |||
10396 | auto DVar = DSAS->getTopDSA(VD, false); | |||
10397 | SemaRef.Diag(ELoc, diag::err_omp_threadprivate_in_clause) | |||
10398 | << getOpenMPClauseName(CKind); | |||
10399 | ReportOriginalDSA(SemaRef, DSAS, VD, DVar); | |||
10400 | continue; | |||
10401 | } | |||
10402 | ||||
10403 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] | |||
10404 | // A list item cannot appear in both a map clause and a data-sharing | |||
10405 | // attribute clause on the same construct. | |||
10406 | ||||
10407 | // Check conflicts with other map clause expressions. We check the conflicts | |||
10408 | // with the current construct separately from the enclosing data | |||
10409 | // environment, because the restrictions are different. We only have to | |||
10410 | // check conflicts across regions for the map clauses. | |||
10411 | if (CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, | |||
10412 | /*CurrentRegionOnly=*/true, CurComponents, CKind)) | |||
10413 | break; | |||
10414 | if (CKind == OMPC_map && | |||
10415 | CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, | |||
10416 | /*CurrentRegionOnly=*/false, CurComponents, CKind)) | |||
10417 | break; | |||
10418 | ||||
10419 | // OpenMP 4.5 [2.10.5, target update Construct] | |||
10420 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] | |||
10421 | // If the type of a list item is a reference to a type T then the type will | |||
10422 | // be considered to be T for all purposes of this clause. | |||
10423 | QualType Type = CurDeclaration->getType().getNonReferenceType(); | |||
10424 | ||||
10425 | // OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4] | |||
10426 | // A list item in a to or from clause must have a mappable type. | |||
10427 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] | |||
10428 | // A list item must have a mappable type. | |||
10429 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef, | |||
10430 | DSAS, Type)) | |||
10431 | continue; | |||
10432 | ||||
10433 | if (CKind == OMPC_map) { | |||
10434 | // target enter data | |||
10435 | // OpenMP [2.10.2, Restrictions, p. 99] | |||
10436 | // A map-type must be specified in all map clauses and must be either | |||
10437 | // to or alloc. | |||
10438 | OpenMPDirectiveKind DKind = DSAS->getCurrentDirective(); | |||
10439 | if (DKind == OMPD_target_enter_data && | |||
10440 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { | |||
10441 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) | |||
10442 | << (IsMapTypeImplicit ? 1 : 0) | |||
10443 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) | |||
10444 | << getOpenMPDirectiveName(DKind); | |||
10445 | continue; | |||
10446 | } | |||
10447 | ||||
10448 | // target exit_data | |||
10449 | // OpenMP [2.10.3, Restrictions, p. 102] | |||
10450 | // A map-type must be specified in all map clauses and must be either | |||
10451 | // from, release, or delete. | |||
10452 | if (DKind == OMPD_target_exit_data && | |||
10453 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || | |||
10454 | MapType == OMPC_MAP_delete)) { | |||
10455 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) | |||
10456 | << (IsMapTypeImplicit ? 1 : 0) | |||
10457 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) | |||
10458 | << getOpenMPDirectiveName(DKind); | |||
10459 | continue; | |||
10460 | } | |||
10461 | ||||
10462 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] | |||
10463 | // A list item cannot appear in both a map clause and a data-sharing | |||
10464 | // attribute clause on the same construct | |||
10465 | if (DKind == OMPD_target && VD) { | |||
10466 | auto DVar = DSAS->getTopDSA(VD, false); | |||
10467 | if (isOpenMPPrivate(DVar.CKind)) { | |||
10468 | SemaRef.Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) | |||
10469 | << getOpenMPClauseName(DVar.CKind) | |||
10470 | << getOpenMPDirectiveName(DSAS->getCurrentDirective()); | |||
10471 | ReportOriginalDSA(SemaRef, DSAS, CurDeclaration, DVar); | |||
10472 | continue; | |||
10473 | } | |||
10474 | } | |||
10475 | } | |||
10476 | ||||
10477 | // Save the current expression. | |||
10478 | MVLI.ProcessedVarList.push_back(RE); | |||
10479 | ||||
10480 | // Store the components in the stack so that they can be used to check | |||
10481 | // against other clauses later on. | |||
10482 | DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents); | |||
10483 | ||||
10484 | // Save the components and declaration to create the clause. For purposes of | |||
10485 | // the clause creation, any component list that has has base 'this' uses | |||
10486 | // null as base declaration. | |||
10487 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); | |||
10488 | MVLI.VarComponents.back().append(CurComponents.begin(), | |||
10489 | CurComponents.end()); | |||
10490 | MVLI.VarBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr | |||
10491 | : CurDeclaration); | |||
10492 | } | |||
10493 | } | |||
10494 | ||||
10495 | OMPClause * | |||
10496 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, | |||
10497 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, | |||
10498 | SourceLocation MapLoc, SourceLocation ColonLoc, | |||
10499 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, | |||
10500 | SourceLocation LParenLoc, SourceLocation EndLoc) { | |||
10501 | MappableVarListInfo MVLI(VarList); | |||
10502 | checkMappableExpressionList(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), OMPC_map, MVLI, StartLoc, | |||
10503 | MapType, IsMapTypeImplicit); | |||
10504 | ||||
10505 | // We need to produce a map clause even if we don't have variables so that | |||
10506 | // other diagnostics related with non-existing map clauses are accurate. | |||
10507 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, | |||
10508 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, | |||
10509 | MVLI.VarComponents, MapTypeModifier, MapType, | |||
10510 | IsMapTypeImplicit, MapLoc); | |||
10511 | } | |||
10512 | ||||
10513 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, | |||
10514 | TypeResult ParsedType) { | |||
10515 | assert(ParsedType.isUsable())((ParsedType.isUsable()) ? static_cast<void> (0) : __assert_fail ("ParsedType.isUsable()", "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10515, __PRETTY_FUNCTION__)); | |||
10516 | ||||
10517 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); | |||
10518 | if (ReductionType.isNull()) | |||
10519 | return QualType(); | |||
10520 | ||||
10521 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ | |||
10522 | // A type name in a declare reduction directive cannot be a function type, an | |||
10523 | // array type, a reference type, or a type qualified with const, volatile or | |||
10524 | // restrict. | |||
10525 | if (ReductionType.hasQualifiers()) { | |||
10526 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; | |||
10527 | return QualType(); | |||
10528 | } | |||
10529 | ||||
10530 | if (ReductionType->isFunctionType()) { | |||
10531 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; | |||
10532 | return QualType(); | |||
10533 | } | |||
10534 | if (ReductionType->isReferenceType()) { | |||
10535 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; | |||
10536 | return QualType(); | |||
10537 | } | |||
10538 | if (ReductionType->isArrayType()) { | |||
10539 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; | |||
10540 | return QualType(); | |||
10541 | } | |||
10542 | return ReductionType; | |||
10543 | } | |||
10544 | ||||
10545 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( | |||
10546 | Scope *S, DeclContext *DC, DeclarationName Name, | |||
10547 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, | |||
10548 | AccessSpecifier AS, Decl *PrevDeclInScope) { | |||
10549 | SmallVector<Decl *, 8> Decls; | |||
10550 | Decls.reserve(ReductionTypes.size()); | |||
10551 | ||||
10552 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, | |||
10553 | ForRedeclaration); | |||
10554 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions | |||
10555 | // A reduction-identifier may not be re-declared in the current scope for the | |||
10556 | // same type or for a type that is compatible according to the base language | |||
10557 | // rules. | |||
10558 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; | |||
10559 | OMPDeclareReductionDecl *PrevDRD = nullptr; | |||
10560 | bool InCompoundScope = true; | |||
10561 | if (S != nullptr) { | |||
10562 | // Find previous declaration with the same name not referenced in other | |||
10563 | // declarations. | |||
10564 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); | |||
10565 | InCompoundScope = | |||
10566 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); | |||
10567 | LookupName(Lookup, S); | |||
10568 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, | |||
10569 | /*AllowInlineNamespace=*/false); | |||
10570 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; | |||
10571 | auto Filter = Lookup.makeFilter(); | |||
10572 | while (Filter.hasNext()) { | |||
10573 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); | |||
10574 | if (InCompoundScope) { | |||
10575 | auto I = UsedAsPrevious.find(PrevDecl); | |||
10576 | if (I == UsedAsPrevious.end()) | |||
10577 | UsedAsPrevious[PrevDecl] = false; | |||
10578 | if (auto *D = PrevDecl->getPrevDeclInScope()) | |||
10579 | UsedAsPrevious[D] = true; | |||
10580 | } | |||
10581 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = | |||
10582 | PrevDecl->getLocation(); | |||
10583 | } | |||
10584 | Filter.done(); | |||
10585 | if (InCompoundScope) { | |||
10586 | for (auto &PrevData : UsedAsPrevious) { | |||
10587 | if (!PrevData.second) { | |||
10588 | PrevDRD = PrevData.first; | |||
10589 | break; | |||
10590 | } | |||
10591 | } | |||
10592 | } | |||
10593 | } else if (PrevDeclInScope != nullptr) { | |||
10594 | auto *PrevDRDInScope = PrevDRD = | |||
10595 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); | |||
10596 | do { | |||
10597 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = | |||
10598 | PrevDRDInScope->getLocation(); | |||
10599 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); | |||
10600 | } while (PrevDRDInScope != nullptr); | |||
10601 | } | |||
10602 | for (auto &TyData : ReductionTypes) { | |||
10603 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); | |||
10604 | bool Invalid = false; | |||
10605 | if (I != PreviousRedeclTypes.end()) { | |||
10606 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) | |||
10607 | << TyData.first; | |||
10608 | Diag(I->second, diag::note_previous_definition); | |||
10609 | Invalid = true; | |||
10610 | } | |||
10611 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; | |||
10612 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, | |||
10613 | Name, TyData.first, PrevDRD); | |||
10614 | DC->addDecl(DRD); | |||
10615 | DRD->setAccess(AS); | |||
10616 | Decls.push_back(DRD); | |||
10617 | if (Invalid) | |||
10618 | DRD->setInvalidDecl(); | |||
10619 | else | |||
10620 | PrevDRD = DRD; | |||
10621 | } | |||
10622 | ||||
10623 | return DeclGroupPtrTy::make( | |||
10624 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); | |||
10625 | } | |||
10626 | ||||
10627 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { | |||
10628 | auto *DRD = cast<OMPDeclareReductionDecl>(D); | |||
10629 | ||||
10630 | // Enter new function scope. | |||
10631 | PushFunctionScope(); | |||
10632 | getCurFunction()->setHasBranchProtectedScope(); | |||
10633 | getCurFunction()->setHasOMPDeclareReductionCombiner(); | |||
10634 | ||||
10635 | if (S != nullptr) | |||
10636 | PushDeclContext(S, DRD); | |||
10637 | else | |||
10638 | CurContext = DRD; | |||
10639 | ||||
10640 | PushExpressionEvaluationContext(PotentiallyEvaluated); | |||
10641 | ||||
10642 | QualType ReductionType = DRD->getType(); | |||
10643 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will | |||
10644 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' | |||
10645 | // uses semantics of argument handles by value, but it should be passed by | |||
10646 | // reference. C lang does not support references, so pass all parameters as | |||
10647 | // pointers. | |||
10648 | // Create 'T omp_in;' variable. | |||
10649 | auto *OmpInParm = | |||
10650 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); | |||
10651 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will | |||
10652 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' | |||
10653 | // uses semantics of argument handles by value, but it should be passed by | |||
10654 | // reference. C lang does not support references, so pass all parameters as | |||
10655 | // pointers. | |||
10656 | // Create 'T omp_out;' variable. | |||
10657 | auto *OmpOutParm = | |||
10658 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); | |||
10659 | if (S != nullptr) { | |||
10660 | PushOnScopeChains(OmpInParm, S); | |||
10661 | PushOnScopeChains(OmpOutParm, S); | |||
10662 | } else { | |||
10663 | DRD->addDecl(OmpInParm); | |||
10664 | DRD->addDecl(OmpOutParm); | |||
10665 | } | |||
10666 | } | |||
10667 | ||||
10668 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { | |||
10669 | auto *DRD = cast<OMPDeclareReductionDecl>(D); | |||
10670 | DiscardCleanupsInEvaluationContext(); | |||
10671 | PopExpressionEvaluationContext(); | |||
10672 | ||||
10673 | PopDeclContext(); | |||
10674 | PopFunctionScopeInfo(); | |||
10675 | ||||
10676 | if (Combiner != nullptr) | |||
10677 | DRD->setCombiner(Combiner); | |||
10678 | else | |||
10679 | DRD->setInvalidDecl(); | |||
10680 | } | |||
10681 | ||||
10682 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { | |||
10683 | auto *DRD = cast<OMPDeclareReductionDecl>(D); | |||
10684 | ||||
10685 | // Enter new function scope. | |||
10686 | PushFunctionScope(); | |||
10687 | getCurFunction()->setHasBranchProtectedScope(); | |||
10688 | ||||
10689 | if (S != nullptr) | |||
10690 | PushDeclContext(S, DRD); | |||
10691 | else | |||
10692 | CurContext = DRD; | |||
10693 | ||||
10694 | PushExpressionEvaluationContext(PotentiallyEvaluated); | |||
10695 | ||||
10696 | QualType ReductionType = DRD->getType(); | |||
10697 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will | |||
10698 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' | |||
10699 | // uses semantics of argument handles by value, but it should be passed by | |||
10700 | // reference. C lang does not support references, so pass all parameters as | |||
10701 | // pointers. | |||
10702 | // Create 'T omp_priv;' variable. | |||
10703 | auto *OmpPrivParm = | |||
10704 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); | |||
10705 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will | |||
10706 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' | |||
10707 | // uses semantics of argument handles by value, but it should be passed by | |||
10708 | // reference. C lang does not support references, so pass all parameters as | |||
10709 | // pointers. | |||
10710 | // Create 'T omp_orig;' variable. | |||
10711 | auto *OmpOrigParm = | |||
10712 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); | |||
10713 | if (S != nullptr) { | |||
10714 | PushOnScopeChains(OmpPrivParm, S); | |||
10715 | PushOnScopeChains(OmpOrigParm, S); | |||
10716 | } else { | |||
10717 | DRD->addDecl(OmpPrivParm); | |||
10718 | DRD->addDecl(OmpOrigParm); | |||
10719 | } | |||
10720 | } | |||
10721 | ||||
10722 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, | |||
10723 | Expr *Initializer) { | |||
10724 | auto *DRD = cast<OMPDeclareReductionDecl>(D); | |||
10725 | DiscardCleanupsInEvaluationContext(); | |||
10726 | PopExpressionEvaluationContext(); | |||
10727 | ||||
10728 | PopDeclContext(); | |||
10729 | PopFunctionScopeInfo(); | |||
10730 | ||||
10731 | if (Initializer != nullptr) | |||
10732 | DRD->setInitializer(Initializer); | |||
10733 | else | |||
10734 | DRD->setInvalidDecl(); | |||
10735 | } | |||
10736 | ||||
10737 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( | |||
10738 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { | |||
10739 | for (auto *D : DeclReductions.get()) { | |||
10740 | if (IsValid) { | |||
10741 | auto *DRD = cast<OMPDeclareReductionDecl>(D); | |||
10742 | if (S != nullptr) | |||
10743 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); | |||
10744 | } else | |||
10745 | D->setInvalidDecl(); | |||
10746 | } | |||
10747 | return DeclReductions; | |||
10748 | } | |||
10749 | ||||
10750 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, | |||
10751 | SourceLocation StartLoc, | |||
10752 | SourceLocation LParenLoc, | |||
10753 | SourceLocation EndLoc) { | |||
10754 | Expr *ValExpr = NumTeams; | |||
10755 | ||||
10756 | // OpenMP [teams Constrcut, Restrictions] | |||
10757 | // The num_teams expression must evaluate to a positive integer value. | |||
10758 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, | |||
10759 | /*StrictlyPositive=*/true)) | |||
10760 | return nullptr; | |||
10761 | ||||
10762 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); | |||
10763 | } | |||
10764 | ||||
10765 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, | |||
10766 | SourceLocation StartLoc, | |||
10767 | SourceLocation LParenLoc, | |||
10768 | SourceLocation EndLoc) { | |||
10769 | Expr *ValExpr = ThreadLimit; | |||
10770 | ||||
10771 | // OpenMP [teams Constrcut, Restrictions] | |||
10772 | // The thread_limit expression must evaluate to a positive integer value. | |||
10773 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, | |||
10774 | /*StrictlyPositive=*/true)) | |||
10775 | return nullptr; | |||
10776 | ||||
10777 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, | |||
10778 | EndLoc); | |||
10779 | } | |||
10780 | ||||
10781 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, | |||
10782 | SourceLocation StartLoc, | |||
10783 | SourceLocation LParenLoc, | |||
10784 | SourceLocation EndLoc) { | |||
10785 | Expr *ValExpr = Priority; | |||
10786 | ||||
10787 | // OpenMP [2.9.1, task Constrcut] | |||
10788 | // The priority-value is a non-negative numerical scalar expression. | |||
10789 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, | |||
10790 | /*StrictlyPositive=*/false)) | |||
10791 | return nullptr; | |||
10792 | ||||
10793 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); | |||
10794 | } | |||
10795 | ||||
10796 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, | |||
10797 | SourceLocation StartLoc, | |||
10798 | SourceLocation LParenLoc, | |||
10799 | SourceLocation EndLoc) { | |||
10800 | Expr *ValExpr = Grainsize; | |||
10801 | ||||
10802 | // OpenMP [2.9.2, taskloop Constrcut] | |||
10803 | // The parameter of the grainsize clause must be a positive integer | |||
10804 | // expression. | |||
10805 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, | |||
10806 | /*StrictlyPositive=*/true)) | |||
10807 | return nullptr; | |||
10808 | ||||
10809 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); | |||
10810 | } | |||
10811 | ||||
10812 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, | |||
10813 | SourceLocation StartLoc, | |||
10814 | SourceLocation LParenLoc, | |||
10815 | SourceLocation EndLoc) { | |||
10816 | Expr *ValExpr = NumTasks; | |||
10817 | ||||
10818 | // OpenMP [2.9.2, taskloop Constrcut] | |||
10819 | // The parameter of the num_tasks clause must be a positive integer | |||
10820 | // expression. | |||
10821 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, | |||
10822 | /*StrictlyPositive=*/true)) | |||
10823 | return nullptr; | |||
10824 | ||||
10825 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); | |||
10826 | } | |||
10827 | ||||
10828 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, | |||
10829 | SourceLocation LParenLoc, | |||
10830 | SourceLocation EndLoc) { | |||
10831 | // OpenMP [2.13.2, critical construct, Description] | |||
10832 | // ... where hint-expression is an integer constant expression that evaluates | |||
10833 | // to a valid lock hint. | |||
10834 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); | |||
10835 | if (HintExpr.isInvalid()) | |||
10836 | return nullptr; | |||
10837 | return new (Context) | |||
10838 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); | |||
10839 | } | |||
10840 | ||||
10841 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( | |||
10842 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, | |||
10843 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, | |||
10844 | SourceLocation EndLoc) { | |||
10845 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { | |||
10846 | std::string Values; | |||
10847 | Values += "'"; | |||
10848 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); | |||
10849 | Values += "'"; | |||
10850 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) | |||
10851 | << Values << getOpenMPClauseName(OMPC_dist_schedule); | |||
10852 | return nullptr; | |||
10853 | } | |||
10854 | Expr *ValExpr = ChunkSize; | |||
10855 | Stmt *HelperValStmt = nullptr; | |||
10856 | if (ChunkSize) { | |||
10857 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && | |||
10858 | !ChunkSize->isInstantiationDependent() && | |||
10859 | !ChunkSize->containsUnexpandedParameterPack()) { | |||
10860 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); | |||
10861 | ExprResult Val = | |||
10862 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); | |||
10863 | if (Val.isInvalid()) | |||
10864 | return nullptr; | |||
10865 | ||||
10866 | ValExpr = Val.get(); | |||
10867 | ||||
10868 | // OpenMP [2.7.1, Restrictions] | |||
10869 | // chunk_size must be a loop invariant integer expression with a positive | |||
10870 | // value. | |||
10871 | llvm::APSInt Result; | |||
10872 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { | |||
10873 | if (Result.isSigned() && !Result.isStrictlyPositive()) { | |||
10874 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) | |||
10875 | << "dist_schedule" << ChunkSize->getSourceRange(); | |||
10876 | return nullptr; | |||
10877 | } | |||
10878 | } else if (isParallelOrTaskRegion(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) { | |||
10879 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; | |||
10880 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); | |||
10881 | HelperValStmt = buildPreInits(Context, Captures); | |||
10882 | } | |||
10883 | } | |||
10884 | } | |||
10885 | ||||
10886 | return new (Context) | |||
10887 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, | |||
10888 | Kind, ValExpr, HelperValStmt); | |||
10889 | } | |||
10890 | ||||
10891 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( | |||
10892 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, | |||
10893 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, | |||
10894 | SourceLocation KindLoc, SourceLocation EndLoc) { | |||
10895 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' | |||
10896 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || | |||
10897 | Kind != OMPC_DEFAULTMAP_scalar) { | |||
10898 | std::string Value; | |||
10899 | SourceLocation Loc; | |||
10900 | Value += "'"; | |||
10901 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { | |||
10902 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, | |||
10903 | OMPC_DEFAULTMAP_MODIFIER_tofrom); | |||
10904 | Loc = MLoc; | |||
10905 | } else { | |||
10906 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, | |||
10907 | OMPC_DEFAULTMAP_scalar); | |||
10908 | Loc = KindLoc; | |||
10909 | } | |||
10910 | Value += "'"; | |||
10911 | Diag(Loc, diag::err_omp_unexpected_clause_value) | |||
10912 | << Value << getOpenMPClauseName(OMPC_defaultmap); | |||
10913 | return nullptr; | |||
10914 | } | |||
10915 | ||||
10916 | return new (Context) | |||
10917 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); | |||
10918 | } | |||
10919 | ||||
10920 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { | |||
10921 | DeclContext *CurLexicalContext = getCurLexicalContext(); | |||
10922 | if (!CurLexicalContext->isFileContext() && | |||
10923 | !CurLexicalContext->isExternCContext() && | |||
10924 | !CurLexicalContext->isExternCXXContext()) { | |||
10925 | Diag(Loc, diag::err_omp_region_not_file_context); | |||
10926 | return false; | |||
10927 | } | |||
10928 | if (IsInOpenMPDeclareTargetContext) { | |||
10929 | Diag(Loc, diag::err_omp_enclosed_declare_target); | |||
10930 | return false; | |||
10931 | } | |||
10932 | ||||
10933 | IsInOpenMPDeclareTargetContext = true; | |||
10934 | return true; | |||
10935 | } | |||
10936 | ||||
10937 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { | |||
10938 | assert(IsInOpenMPDeclareTargetContext &&((IsInOpenMPDeclareTargetContext && "Unexpected ActOnFinishOpenMPDeclareTargetDirective" ) ? static_cast<void> (0) : __assert_fail ("IsInOpenMPDeclareTargetContext && \"Unexpected ActOnFinishOpenMPDeclareTargetDirective\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10939, __PRETTY_FUNCTION__)) | |||
10939 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective")((IsInOpenMPDeclareTargetContext && "Unexpected ActOnFinishOpenMPDeclareTargetDirective" ) ? static_cast<void> (0) : __assert_fail ("IsInOpenMPDeclareTargetContext && \"Unexpected ActOnFinishOpenMPDeclareTargetDirective\"" , "/tmp/buildd/llvm-toolchain-snapshot-3.9~svn270899/tools/clang/lib/Sema/SemaOpenMP.cpp" , 10939, __PRETTY_FUNCTION__)); | |||
10940 | ||||
10941 | IsInOpenMPDeclareTargetContext = false; | |||
10942 | } | |||
10943 | ||||
10944 | void | |||
10945 | Sema::ActOnOpenMPDeclareTargetName(Scope *CurScope, CXXScopeSpec &ScopeSpec, | |||
10946 | const DeclarationNameInfo &Id, | |||
10947 | OMPDeclareTargetDeclAttr::MapTypeTy MT, | |||
10948 | NamedDeclSetType &SameDirectiveDecls) { | |||
10949 | LookupResult Lookup(*this, Id, LookupOrdinaryName); | |||
10950 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); | |||
10951 | ||||
10952 | if (Lookup.isAmbiguous()) | |||
10953 | return; | |||
10954 | Lookup.suppressDiagnostics(); | |||
10955 | ||||
10956 | if (!Lookup.isSingleResult()) { | |||
10957 | if (TypoCorrection Corrected = | |||
10958 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, | |||
10959 | llvm::make_unique<VarOrFuncDeclFilterCCC>(*this), | |||
10960 | CTK_ErrorRecovery)) { | |||
10961 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) | |||
10962 | << Id.getName()); | |||
10963 | checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl()); | |||
10964 | return; | |||
10965 | } | |||
10966 | ||||
10967 | Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName(); | |||
10968 | return; | |||
10969 | } | |||
10970 | ||||
10971 | NamedDecl *ND = Lookup.getAsSingle<NamedDecl>(); | |||
10972 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { | |||
10973 | if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl()))) | |||
10974 | Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName(); | |||
10975 | ||||
10976 | if (!ND->hasAttr<OMPDeclareTargetDeclAttr>()) { | |||
10977 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT); | |||
10978 | ND->addAttr(A); | |||
10979 | if (ASTMutationListener *ML = Context.getASTMutationListener()) | |||
10980 | ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); | |||
10981 | checkDeclIsAllowedInOpenMPTarget(nullptr, ND); | |||
10982 | } else if (ND->getAttr<OMPDeclareTargetDeclAttr>()->getMapType() != MT) { | |||
10983 | Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link) | |||
10984 | << Id.getName(); | |||
10985 | } | |||
10986 | } else | |||
10987 | Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName(); | |||
10988 | } | |||
10989 | ||||
10990 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, | |||
10991 | Sema &SemaRef, Decl *D) { | |||
10992 | if (!D) | |||
10993 | return; | |||
10994 | Decl *LD = nullptr; | |||
10995 | if (isa<TagDecl>(D)) { | |||
10996 | LD = cast<TagDecl>(D)->getDefinition(); | |||
10997 | } else if (isa<VarDecl>(D)) { | |||
10998 | LD = cast<VarDecl>(D)->getDefinition(); | |||
10999 | ||||
11000 | // If this is an implicit variable that is legal and we do not need to do | |||
11001 | // anything. | |||
11002 | if (cast<VarDecl>(D)->isImplicit()) { | |||
11003 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( | |||
11004 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); | |||
11005 | D->addAttr(A); | |||
11006 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) | |||
11007 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); | |||
11008 | return; | |||
11009 | } | |||
11010 | ||||
11011 | } else if (isa<FunctionDecl>(D)) { | |||
11012 | const FunctionDecl *FD = nullptr; | |||
11013 | if (cast<FunctionDecl>(D)->hasBody(FD)) | |||
11014 | LD = const_cast<FunctionDecl *>(FD); | |||
11015 | ||||
11016 | // If the definition is associated with the current declaration in the | |||
11017 | // target region (it can be e.g. a lambda) that is legal and we do not need | |||
11018 | // to do anything else. | |||
11019 | if (LD == D) { | |||
11020 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( | |||
11021 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); | |||
11022 | D->addAttr(A); | |||
11023 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) | |||
11024 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); | |||
11025 | return; | |||
11026 | } | |||
11027 | } | |||
11028 | if (!LD) | |||
11029 | LD = D; | |||
11030 | if (LD && !LD->hasAttr<OMPDeclareTargetDeclAttr>() && | |||
11031 | (isa<VarDecl>(LD) || isa<FunctionDecl>(LD))) { | |||
11032 | // Outlined declaration is not declared target. | |||
11033 | if (LD->isOutOfLine()) { | |||
11034 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); | |||
11035 | SemaRef.Diag(SL, diag::note_used_here) << SR; | |||
11036 | } else { | |||
11037 | DeclContext *DC = LD->getDeclContext(); | |||
11038 | while (DC) { | |||
11039 | if (isa<FunctionDecl>(DC) && | |||
11040 | cast<FunctionDecl>(DC)->hasAttr<OMPDeclareTargetDeclAttr>()) | |||
11041 | break; | |||
11042 | DC = DC->getParent(); | |||
11043 | } | |||
11044 | if (DC) | |||
11045 | return; | |||
11046 | ||||
11047 | // Is not declared in target context. | |||
11048 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); | |||
11049 | SemaRef.Diag(SL, diag::note_used_here) << SR; | |||
11050 | } | |||
11051 | // Mark decl as declared target to prevent further diagnostic. | |||
11052 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( | |||
11053 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); | |||
11054 | D->addAttr(A); | |||
11055 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) | |||
11056 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); | |||
11057 | } | |||
11058 | } | |||
11059 | ||||
11060 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, | |||
11061 | Sema &SemaRef, DSAStackTy *Stack, | |||
11062 | ValueDecl *VD) { | |||
11063 | if (VD->hasAttr<OMPDeclareTargetDeclAttr>()) | |||
11064 | return true; | |||
11065 | if (!CheckTypeMappable(SL, SR, SemaRef, Stack, VD->getType())) | |||
11066 | return false; | |||
11067 | return true; | |||
11068 | } | |||
11069 | ||||
11070 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D) { | |||
11071 | if (!D || D->isInvalidDecl()) | |||
11072 | return; | |||
11073 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); | |||
11074 | SourceLocation SL = E ? E->getLocStart() : D->getLocation(); | |||
11075 | // 2.10.6: threadprivate variable cannot appear in a declare target directive. | |||
11076 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) { | |||
11077 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isThreadPrivate(VD)) { | |||
11078 | Diag(SL, diag::err_omp_threadprivate_in_target); | |||
11079 | ReportOriginalDSA(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), VD, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(VD, false)); | |||
11080 | return; | |||
11081 | } | |||
11082 | } | |||
11083 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { | |||
11084 | // Problem if any with var declared with incomplete type will be reported | |||
11085 | // as normal, so no need to check it here. | |||
11086 | if ((E || !VD->getType()->isIncompleteType()) && | |||
11087 | !checkValueDeclInTarget(SL, SR, *this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), VD)) { | |||
11088 | // Mark decl as declared target to prevent further diagnostic. | |||
11089 | if (isa<VarDecl>(VD) || isa<FunctionDecl>(VD)) { | |||
11090 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( | |||
11091 | Context, OMPDeclareTargetDeclAttr::MT_To); | |||
11092 | VD->addAttr(A); | |||
11093 | if (ASTMutationListener *ML = Context.getASTMutationListener()) | |||
11094 | ML->DeclarationMarkedOpenMPDeclareTarget(VD, A); | |||
11095 | } | |||
11096 | return; | |||
11097 | } | |||
11098 | } | |||
11099 | if (!E) { | |||
11100 | // Checking declaration inside declare target region. | |||
11101 | if (!D->hasAttr<OMPDeclareTargetDeclAttr>() && | |||
11102 | (isa<VarDecl>(D) || isa<FunctionDecl>(D))) { | |||
11103 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( | |||
11104 | Context, OMPDeclareTargetDeclAttr::MT_To); | |||
11105 | D->addAttr(A); | |||
11106 | if (ASTMutationListener *ML = Context.getASTMutationListener()) | |||
11107 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); | |||
11108 | } | |||
11109 | return; | |||
11110 | } | |||
11111 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); | |||
11112 | } | |||
11113 | ||||
11114 | OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList, | |||
11115 | SourceLocation StartLoc, | |||
11116 | SourceLocation LParenLoc, | |||
11117 | SourceLocation EndLoc) { | |||
11118 | MappableVarListInfo MVLI(VarList); | |||
11119 | checkMappableExpressionList(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), OMPC_to, MVLI, StartLoc); | |||
11120 | if (MVLI.ProcessedVarList.empty()) | |||
11121 | return nullptr; | |||
11122 | ||||
11123 | return OMPToClause::Create(Context, StartLoc, LParenLoc, EndLoc, | |||
11124 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, | |||
11125 | MVLI.VarComponents); | |||
11126 | } | |||
11127 | ||||
11128 | OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList, | |||
11129 | SourceLocation StartLoc, | |||
11130 | SourceLocation LParenLoc, | |||
11131 | SourceLocation EndLoc) { | |||
11132 | MappableVarListInfo MVLI(VarList); | |||
11133 | checkMappableExpressionList(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), OMPC_from, MVLI, StartLoc); | |||
11134 | if (MVLI.ProcessedVarList.empty()) | |||
11135 | return nullptr; | |||
11136 | ||||
11137 | return OMPFromClause::Create(Context, StartLoc, LParenLoc, EndLoc, | |||
11138 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, | |||
11139 | MVLI.VarComponents); | |||
11140 | } |