FLANG
check-omp-structure.h
1//===-- lib/Semantics/check-omp-structure.h ---------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// OpenMP structure validity check list
10// 1. invalid clauses on directive
11// 2. invalid repeated clauses on directive
12// 3. TODO: invalid nesting of regions
13
14#ifndef FORTRAN_SEMANTICS_CHECK_OMP_STRUCTURE_H_
15#define FORTRAN_SEMANTICS_CHECK_OMP_STRUCTURE_H_
16
17#include "check-directive-structure.h"
18#include "flang/Common/enum-set.h"
19#include "flang/Parser/parse-tree.h"
20#include "flang/Semantics/openmp-directive-sets.h"
21#include "flang/Semantics/semantics.h"
22#include "llvm/ADT/iterator_range.h"
23
24using OmpClauseSet =
26
27#define GEN_FLANG_DIRECTIVE_CLAUSE_SETS
28#include "llvm/Frontend/OpenMP/OMP.inc"
29
30namespace llvm {
31namespace omp {
32static OmpClauseSet privateSet{
33 Clause::OMPC_private, Clause::OMPC_firstprivate, Clause::OMPC_lastprivate};
34static OmpClauseSet privateReductionSet{
35 OmpClauseSet{Clause::OMPC_reduction} | privateSet};
36} // namespace omp
37} // namespace llvm
38
39namespace Fortran::semantics {
40struct AnalyzedCondStmt;
41
42namespace omp {
43struct LoopSequence;
44}
45
46// Mapping from 'Symbol' to 'Source' to keep track of the variables
47// used in multiple clauses
48using SymbolSourceMap = std::multimap<const Symbol *, parser::CharBlock>;
49// Multimap to check the triple <current_dir, enclosing_dir, enclosing_clause>
50using DirectivesClauseTriple = std::multimap<llvm::omp::Directive,
51 std::pair<llvm::omp::Directive, const OmpClauseSet>>;
52
53using OmpStructureCheckerBase = DirectiveStructureChecker<llvm::omp::Directive,
54 llvm::omp::Clause, parser::OmpClause, llvm::omp::Clause_enumSize>;
55
56class OmpStructureChecker : public OmpStructureCheckerBase {
57public:
58 using Base = OmpStructureCheckerBase;
59
60 OmpStructureChecker(SemanticsContext &context);
61
62 void Enter(const parser::ProgramUnit &);
63 void Enter(const parser::MainProgram &);
64 void Leave(const parser::MainProgram &);
65 void Enter(const parser::BlockData &);
66 void Leave(const parser::BlockData &);
67 void Enter(const parser::Module &);
68 void Leave(const parser::Module &);
69 void Enter(const parser::Submodule &);
70 void Leave(const parser::Submodule &);
71 void Enter(const parser::SubroutineStmt &);
72 void Enter(const parser::EndSubroutineStmt &);
73 void Enter(const parser::FunctionStmt &);
74 void Enter(const parser::EndFunctionStmt &);
75 void Enter(const parser::MpSubprogramStmt &);
76 void Enter(const parser::EndMpSubprogramStmt &);
77 void Enter(const parser::BlockConstruct &);
78 void Leave(const parser::BlockConstruct &);
79 void Enter(const parser::InternalSubprogram &);
80 void Enter(const parser::ModuleSubprogram &);
81
82 void Enter(const parser::SpecificationPart &);
83 void Leave(const parser::SpecificationPart &);
84 void Enter(const parser::ExecutionPart &);
85 void Leave(const parser::ExecutionPart &);
86
87 void Enter(const parser::OpenMPConstruct &);
88 void Leave(const parser::OpenMPConstruct &);
89 void Enter(const parser::OpenMPDeclarativeConstruct &);
90 void Leave(const parser::OpenMPDeclarativeConstruct &);
91
92 void Enter(const parser::OpenMPMisplacedEndDirective &);
93 void Leave(const parser::OpenMPMisplacedEndDirective &);
94 void Enter(const parser::OpenMPInvalidDirective &);
95 void Leave(const parser::OpenMPInvalidDirective &);
96
97 void Enter(const parser::OpenMPLoopConstruct &);
98 void Leave(const parser::OpenMPLoopConstruct &);
99
100 void Enter(const parser::OpenMPInteropConstruct &);
101 void Enter(const parser::OmpBlockConstruct &);
102 void Leave(const parser::OmpBlockConstruct &);
103 void Enter(const parser::OmpBeginDirective &);
104 void Leave(const parser::OmpBeginDirective &);
105
106 void Enter(const parser::OpenMPSectionsConstruct &);
107
108 void Enter(const parser::OmpDeclareVariantDirective &);
109 void Enter(const parser::OmpDeclareSimdDirective &);
110 void Enter(const parser::OmpAllocateDirective &);
111 void Leave(const parser::OmpAllocateDirective &);
112 void Enter(const parser::OmpDeclareMapperDirective &);
113 void Enter(const parser::OmpDeclareReductionDirective &);
114 void Enter(const parser::OmpDeclareTargetDirective &);
115 void Leave(const parser::OmpDeclareTargetDirective &);
116 void Enter(const parser::OpenMPDepobjConstruct &);
117 void Enter(const parser::OpenMPDispatchConstruct &);
118 void Enter(const parser::OpenMPAllocatorsConstruct &);
119 void Enter(const parser::OmpRequiresDirective &);
120 void Enter(const parser::OmpGroupprivateDirective &);
121 void Leave(const parser::OmpThreadprivateDirective &);
122
123 void Enter(const parser::OpenMPSimpleStandaloneConstruct &);
124 void Leave(const parser::OpenMPSimpleStandaloneConstruct &);
125 void Leave(const parser::OpenMPFlushConstruct &);
126 void Enter(const parser::OpenMPCancelConstruct &);
128 void Enter(const parser::OpenMPCriticalConstruct &);
129 void Enter(const parser::OpenMPAtomicConstruct &);
130
131 void Enter(const parser::OmpClauseList &);
132 void Leave(const parser::OmpClauseList &);
133 void Enter(const parser::OmpClause &);
134
135 void Enter(const parser::DoConstruct &);
136 void Leave(const parser::DoConstruct &);
137
138 void Enter(const parser::OmpDirectiveSpecification &);
139 void Leave(const parser::OmpDirectiveSpecification &);
140
141 void Enter(const parser::OmpMetadirectiveDirective &);
142 void Leave(const parser::OmpMetadirectiveDirective &);
143
144 void Enter(const parser::ExecutionPartConstruct &);
145 void Leave(const parser::OmpClause::When &);
146
147 void Enter(const parser::OmpContextSelector &);
148 void Leave(const parser::OmpContextSelector &);
149
150 void Enter(const parser::OmpLoopModifier &);
151
152 void Enter(const parser::OmpClause::Apply &);
153 void Leave(const parser::OmpClause::Apply &);
154
155 template <typename A> void Enter(const parser::Statement<A> &);
156 void Leave(const parser::GotoStmt &);
157 void Leave(const parser::ComputedGotoStmt &);
158 void Leave(const parser::ArithmeticIfStmt &);
159 void Leave(const parser::AssignedGotoStmt &);
160 void Leave(const parser::AltReturnSpec &);
161 void Leave(const parser::ErrLabel &);
162 void Leave(const parser::EndLabel &);
163 void Leave(const parser::EorLabel &);
164
165 void Enter(const parser::OmpClause::Affinity &x);
166 void Enter(const parser::OmpClause::Align &x);
167 void Enter(const parser::OmpClause::Aligned &x);
168 void Enter(const parser::OmpClause::Allocate &x);
169 void Enter(const parser::OmpClause::Allocator &x);
170 void Enter(const parser::OmpClause::At &x);
171 void Enter(const parser::OmpClause::AtomicDefaultMemOrder &x);
172 void Enter(const parser::OmpClause::CancellationConstructType &x);
173 void Enter(const parser::OmpClause::Collapse &x);
174 void Enter(const parser::OmpClause::Copyin &x);
175 void Enter(const parser::OmpClause::Copyprivate &x);
176 void Enter(const parser::OmpClause::Defaultmap &x);
177 void Enter(const parser::OmpClause::Depend &x);
178 void Enter(const parser::OmpClause::Depth &x);
179 void Enter(const parser::OmpClause::Destroy &x);
180 void Enter(const parser::OmpClause::Detach &x);
181 void Enter(const parser::OmpClause::DeviceSafesync &x);
182 void Enter(const parser::OmpClause::Device &x);
183 void Enter(const parser::OmpClause::Doacross &x);
184 void Enter(const parser::OmpClause::DynamicAllocators &x);
185 void Enter(const parser::OmpClause::DynGroupprivate &x);
186 void Enter(const parser::OmpClause::Enter &x);
187 void Enter(const parser::OmpClause::Firstprivate &x);
188 void Enter(const parser::OmpClause::From &x);
189 void Enter(const parser::OmpClause::HasDeviceAddr &x);
190 void Enter(const parser::OmpClause::Hint &x);
191 void Enter(const parser::OmpClause::If &x);
192 void Enter(const parser::OmpClause::InReduction &x);
193 void Enter(const parser::OmpClause::IsDevicePtr &x);
194 void Enter(const parser::OmpClause::Lastprivate &x);
195 void Enter(const parser::OmpClause::Linear &x);
196 void Enter(const parser::OmpClause::Looprange &x);
197 void Enter(const parser::OmpClause::Map &x);
198 void Enter(const parser::OmpClause::NumTeams &x);
199 void Enter(const parser::OmpClause::NumThreads &x);
200 void Enter(const parser::OmpClause::OmpxBare &x);
201 void Enter(const parser::OmpClause::OmpxDynCgroupMem &x);
202 void Enter(const parser::OmpClause::Ordered &x);
203 void Enter(const parser::OmpClause::Permutation &x);
204 void Enter(const parser::OmpClause::Priority &x);
205 void Enter(const parser::OmpClause::Private &x);
206 void Enter(const parser::OmpClause::Reduction &x);
207 void Enter(const parser::OmpClause::ReverseOffload &x);
208 void Enter(const parser::OmpClause::Safelen &x);
209 void Enter(const parser::OmpClause::Schedule &x);
210 void Enter(const parser::OmpClause::SelfMaps &x);
211 void Enter(const parser::OmpClause::Shared &x);
212 void Enter(const parser::OmpClause::Simdlen &x);
213 void Enter(const parser::OmpClause::Sizes &x);
214 void Enter(const parser::OmpClause::TaskReduction &x);
215 void Enter(const parser::OmpClause::ThreadLimit &x);
216 void Enter(const parser::OmpClause::To &x);
217 void Enter(const parser::OmpClause::UnifiedAddress &x);
218 void Enter(const parser::OmpClause::UnifiedSharedMemory &x);
219 void Enter(const parser::OmpClause::Update &x);
220 void Enter(const parser::OmpClause::UseDeviceAddr &x);
221 void Enter(const parser::OmpClause::UseDevicePtr &x);
222 void Enter(const parser::OmpClause::When &x);
223
224private:
225 using LoopOrConstruct = std::variant<const parser::DoConstruct *,
227
228 // Most of these functions are defined in check-omp-structure.cpp, but
229 // some groups have their own files.
230
231 // check-omp-atomic.cpp
232 void CheckStorageOverlap(const evaluate::Expr<evaluate::SomeType> &,
234 void ErrorShouldBeVariable(const MaybeExpr &expr, parser::CharBlock source);
235 void CheckAtomicType(SymbolRef sym, parser::CharBlock source,
236 std::string_view name, bool checkTypeOnPointer = true);
237 void CheckAtomicVariable(const evaluate::Expr<evaluate::SomeType> &,
238 parser::CharBlock, bool checkTypeOnPointer = true);
239 std::pair<const parser::ExecutionPartConstruct *,
241 CheckUpdateCapture(const parser::ExecutionPartConstruct *ec1,
243 void CheckAtomicCaptureAssignment(const evaluate::Assignment &capture,
244 const SomeExpr &atom, parser::CharBlock source);
245 void CheckAtomicReadAssignment(
246 const evaluate::Assignment &read, parser::CharBlock source);
247 void CheckAtomicWriteAssignment(
248 const evaluate::Assignment &write, parser::CharBlock source);
249 std::optional<evaluate::Assignment> CheckAtomicUpdateAssignment(
250 const evaluate::Assignment &update, parser::CharBlock source);
251 std::pair<bool, bool> CheckAtomicUpdateAssignmentRhs(const SomeExpr &atom,
252 const SomeExpr &rhs, parser::CharBlock source, bool suppressDiagnostics);
253 void CheckAtomicConditionalUpdateAssignment(const SomeExpr &cond,
254 parser::CharBlock condSource, const evaluate::Assignment &assign,
255 parser::CharBlock assignSource);
256 void CheckAtomicConditionalUpdateStmt(
257 const AnalyzedCondStmt &update, parser::CharBlock source);
258 void CheckAtomicUpdateOnly(const parser::OpenMPAtomicConstruct &x,
259 const parser::Block &body, parser::CharBlock source);
260 void CheckAtomicConditionalUpdate(const parser::OpenMPAtomicConstruct &x,
261 const parser::Block &body, parser::CharBlock source);
262 void CheckAtomicUpdateCapture(const parser::OpenMPAtomicConstruct &x,
263 const parser::Block &body, parser::CharBlock source);
264 void CheckAtomicConditionalUpdateCapture(
265 const parser::OpenMPAtomicConstruct &x, const parser::Block &body,
266 parser::CharBlock source);
267 void CheckAtomicRead(const parser::OpenMPAtomicConstruct &x);
268 void CheckAtomicWrite(const parser::OpenMPAtomicConstruct &x);
269 void CheckAtomicUpdate(const parser::OpenMPAtomicConstruct &x);
270
271 // check-omp-loop.cpp
272 void HasInvalidDistributeNesting(const parser::OpenMPLoopConstruct &x);
273 void HasInvalidLoopBinding(const parser::OpenMPLoopConstruct &x);
274 void CheckSIMDNest(const parser::OpenMPConstruct &x);
275 void CheckRectangularNest(const parser::OmpDirectiveSpecification &spec,
276 const omp::LoopSequence &nest);
277 void CheckNestedConstruct(const parser::OpenMPLoopConstruct &x);
278 const parser::Name GetLoopIndex(const parser::DoConstruct *x);
279 void CheckIterationVariables(const parser::OpenMPLoopConstruct &x);
280 std::int64_t GetOrdCollapseLevel(const parser::OpenMPLoopConstruct &x);
281 void CheckAssociatedLoopConstraints(const parser::OpenMPLoopConstruct &x);
282 void CheckScanModifier(const parser::OmpClause::Reduction &x);
283 void CheckDistLinear(const parser::OpenMPLoopConstruct &x);
284
285 // check-omp-variant.cpp
286 void CheckMetadirectiveVariantsWithoutLoop();
287 void CheckOmpDeclareVariantDirective(
289 void CheckDeclareVariantUserConditions(const parser::OmpContextSelector &);
290 const std::list<parser::OmpTraitProperty> &GetTraitPropertyList(
292 std::optional<llvm::omp::Clause> GetClauseFromProperty(
294
295 void CheckTraitSelectorList(const std::list<parser::OmpTraitSelector> &);
296 void CheckContextSelectorSpecification(const parser::OmpContextSelector &);
297 void CheckTraitSetSelector(const parser::OmpTraitSetSelector &);
298 void CheckTraitScore(const parser::OmpTraitScore &);
299 bool VerifyTraitPropertyLists(
301 void CheckTraitSelector(
303 void CheckTraitADMO(
305 void CheckTraitCondition(
307 void CheckTraitDeviceNum(
309 void CheckTraitRequires(
311 void CheckTraitSimd(
313
314 // check-omp-structure.cpp
315 using ClauseIterator =
316 decltype(std::declval<const parser::OmpClauseList>().v.begin());
317 bool IsAllowedClause(llvm::omp::Clause clauseId);
318 bool CheckAllowedClause(llvm::omp::Clause clauseId,
319 parser::CharBlock clauseSource, llvm::omp::Directive dirId);
320 void CheckArgumentObjectKind(const parser::OmpClause &x);
321 void CheckDirectiveSpelling(
322 parser::CharBlock spelling, llvm::omp::Directive id);
323 void CheckDirectiveDeprecation(const parser::OpenMPConstruct &x);
324 void CheckClauses(parser::OmpDirectiveName dirName,
325 llvm::iterator_range<ClauseIterator> beginClauses,
326 llvm::iterator_range<ClauseIterator> endClauses);
327 void AnalyzeObject(const parser::OmpObject &object);
328 std::pair<const parser::OmpClause *, const parser::OmpClause *>
329 FindMutuallyExclusiveClauses(OmpClauseSet exclusive,
330 const std::vector<const parser::OmpClause *> &clauses);
331
332 const parser::OpenMPConstruct *GetCurrentConstruct() const;
333 void CheckSourceLabel(const parser::Label &);
334 void CheckLabelContext(const parser::CharBlock, const parser::CharBlock,
336 void ClearLabels();
337 void CheckMultipleOccurrence(semantics::UnorderedSymbolSet &listVars,
338 const std::list<parser::Name> &nameList, const parser::CharBlock &item,
339 const std::string &clauseName);
340 void CheckMultListItems();
341 void CheckStructureComponent(
342 const parser::OmpObject &object, llvm::omp::Clause clauseId);
343 void CheckStructureComponent(
344 const parser::OmpObjectList &objects, llvm::omp::Clause clauseId);
345 bool HasInvalidWorksharingNesting(
346 const parser::OmpDirectiveName &name, const OmpDirectiveSet &);
347
348 bool IsCloselyNestedRegion(const OmpDirectiveSet &set);
349 bool IsNestedInDirective(llvm::omp::Directive directive);
350 bool IsCombinedParallelWorksharing(llvm::omp::Directive directive) const;
351 bool InTargetRegion();
352 void HasInvalidTeamsNesting(
353 const llvm::omp::Directive &dir, const parser::CharBlock &source);
354 bool HasRequires(llvm::omp::Clause req);
355 void CheckAllowedMapTypes(
356 parser::OmpMapType::Value, llvm::ArrayRef<parser::OmpMapType::Value>);
357
358 llvm::StringRef getClauseName(llvm::omp::Clause clause) override;
359 llvm::StringRef getDirectiveName(llvm::omp::Directive directive) override;
360
361 template < //
362 typename LessTy, typename RangeTy,
363 typename IterTy = decltype(std::declval<RangeTy>().begin())>
364 std::optional<IterTy> FindDuplicate(RangeTy &&);
365
366 void CheckDependList(const parser::DataRef &);
367 void CheckDoacross(const parser::OmpDoacross &doa);
368 void CheckDimsModifier(parser::CharBlock source, size_t numValues,
369 const parser::OmpDimsModifier &x);
370 void CheckTypeParamInquiry(const parser::CharBlock &source,
371 const parser::OmpObject &object, llvm::omp::Directive dirId);
372 void CheckTypeParamInquiry(const parser::CharBlock &source,
373 const parser::OmpObject &object, llvm::omp::Clause clauseId);
374 void CheckVarIsNotPartOfAnotherVar(const parser::CharBlock &source,
375 const parser::OmpObject &object, llvm::StringRef clause = "");
376 void CheckVarIsNotPartOfAnotherVar(const parser::CharBlock &source,
377 const parser::OmpObjectList &objList, llvm::StringRef clause = "");
378 void CheckThreadprivateOrDeclareTargetVar(const parser::Designator &);
379 void CheckThreadprivateOrDeclareTargetVar(const parser::Name &);
380 void CheckThreadprivateOrDeclareTargetVar(const parser::OmpObject &);
381 void CheckThreadprivateOrDeclareTargetVar(const parser::OmpObjectList &);
382 void CheckIntentInPointer(SymbolSourceMap &, const llvm::omp::Clause);
383 void CheckProcedurePointer(SymbolSourceMap &, const llvm::omp::Clause);
384 void CheckCrayPointee(const parser::OmpObjectList &objectList,
385 llvm::StringRef clause, bool suggestToUseCrayPointer = true);
386 void GetSymbolsInObjectList(const parser::OmpObjectList &, SymbolSourceMap &);
387 void CheckDefinableObjects(SymbolSourceMap &, const llvm::omp::Clause);
388 void CheckCopyingPolymorphicAllocatable(
389 SymbolSourceMap &, const llvm::omp::Clause);
390 void CheckPrivateSymbolsInOuterCxt(
391 SymbolSourceMap &, DirectivesClauseTriple &, const llvm::omp::Clause);
392 bool CheckTargetBlockOnlyTeams(const parser::Block &);
393 void CheckWorkshareBlockStmts(const parser::Block &, parser::CharBlock);
394 void CheckWorkdistributeBlockStmts(const parser::Block &, parser::CharBlock);
395 void CheckIndividualAllocateDirective(
396 const parser::OmpAllocateDirective &x, bool isExecutable);
397 void CheckExecutableAllocateDirective(const parser::OmpAllocateDirective &x);
398
399 void CheckIteratorRange(const parser::OmpIteratorSpecifier &x);
400 void CheckIteratorModifier(const parser::OmpIterator &x);
401
402 void CheckTargetNest(const parser::OpenMPConstruct &x);
403 void CheckTargetUpdate();
404 void CheckTaskgraph(const parser::OmpBlockConstruct &x);
405 void CheckDependenceType(const parser::OmpDependenceType::Value &x);
406 void CheckTaskDependenceType(const parser::OmpTaskDependenceType::Value &x);
407 std::optional<llvm::omp::Directive> GetCancelType(
408 llvm::omp::Directive cancelDir, const parser::CharBlock &cancelSource,
409 const std::optional<parser::OmpClauseList> &maybeClauses);
410 void CheckCancellationNest(
411 const parser::CharBlock &source, llvm::omp::Directive type);
412 void CheckReductionObjects(
413 const parser::OmpObjectList &objects, llvm::omp::Clause clauseId);
414 bool CheckReductionOperator(const parser::OmpReductionIdentifier &ident,
415 parser::CharBlock source, llvm::omp::Clause clauseId);
416 void CheckReductionObjectTypes(const parser::OmpObjectList &objects,
417 const parser::OmpReductionIdentifier &ident);
418 void CheckReductionModifier(const parser::OmpReductionModifier &);
419 void CheckLastprivateModifier(const parser::OmpLastprivateModifier &);
420 void CheckSingleConstruct(const parser::OmpBlockConstruct &x);
421 void CheckMasterNesting(const parser::OmpBlockConstruct &x);
422 void ChecksOnOrderedAsBlock();
423 void CheckBarrierNesting(const parser::OpenMPSimpleStandaloneConstruct &x);
424 void CheckScan(const parser::OpenMPSimpleStandaloneConstruct &x);
425 void ChecksOnOrderedAsStandalone();
426 void CheckOrderedDependClause(std::optional<std::int64_t> orderedValue);
427 void CheckReductionArraySection(
428 const parser::OmpObjectList &ompObjectList, llvm::omp::Clause clauseId);
429 void CheckArraySection(const parser::ArrayElement &arrayElement,
430 const parser::Name &name, const llvm::omp::Clause clause);
431 void CheckLastPartRefForArraySection(
432 const parser::Designator &designator, llvm::omp::Clause clauseId);
433 void CheckSharedBindingInOuterContext(
434 const parser::OmpObjectList &ompObjectList);
435 void CheckIfContiguous(const parser::OmpObject &object);
436 const parser::Name *GetObjectName(const parser::OmpObject &object);
437 void CheckInitOnDepobj(const parser::OpenMPDepobjConstruct &depobj,
438 const parser::OmpClause &initClause);
439 void CheckAllowedRequiresClause(llvm::omp::Clause clause);
440 void AddEndDirectiveClauses(const parser::OmpClauseList &clauses);
441 void CheckTempDescriptorMappings();
442
443 void EnterDirectiveNest(const int index) { directiveNest_[index]++; }
444 void ExitDirectiveNest(const int index) { directiveNest_[index]--; }
445 int GetDirectiveNest(const int index) { return directiveNest_[index]; }
446
447 bool deviceConstructFound_{false};
448 enum directiveNestType : int {
449 ApplyNest,
450 SIMDNest,
451 TargetBlockOnlyTeams,
452 TargetNest,
453 DeclarativeNest,
454 ContextSelectorNest,
455 MetadirectiveNest,
456 LastType = MetadirectiveNest,
457 };
458 int directiveNest_[LastType + 1] = {0};
459
460 std::set<std::pair<const Symbol *, const Symbol *>> declareVariantPairs_;
461
462 int allocateDirectiveLevel_{0};
463 parser::CharBlock visitedAtomicSource_;
464
465 // Mapping of directive-name-modifier constituents to the sources of the
466 // IF clauses that referenced them. If there was no modifier, the entire
467 // directive is assumed to be listed.
468 std::map<llvm::omp::Directive, parser::CharBlock> ifLeafs_;
469
470 // Track symbols with temporary stack descriptors mapped in TARGET ENTER DATA
471 // and symbols mapped in TARGET EXIT DATA within the current function scope.
472 // Used to warn about potential issues with mapping temporary descriptors.
473 std::multimap<const Symbol *, parser::CharBlock> tempDescriptorEnterMaps_;
474 std::set<const Symbol *> tempDescriptorExitMaps_;
475
476 // Stack of nested DO loops and OpenMP constructs.
477 // This is used to verify DO loop nest for DOACROSS, and branches into
478 // and out of OpenMP constructs.
479 std::vector<LoopOrConstruct> constructStack_;
480 // Scopes for scoping units.
481 std::vector<const Scope *> scopeStack_;
482 // Stack of directive specifications (except for SECTION).
483 // This is to allow visitor functions to see all specified clauses, since
484 // they are only recorded in DirectiveContext as they are processed.
485 std::vector<const parser::OmpDirectiveSpecification *> dirStack_;
486
487 enum class PartKind : int {
488 // There are also other "parts", such as internal-subprogram-part, etc,
489 // but we're keeping track of these two for now.
490 SpecificationPart,
491 ExecutionPart,
492 };
493 std::vector<PartKind> partStack_;
494
495 struct MetadirectiveLoopVariant {
498 };
499 std::vector<MetadirectiveLoopVariant> metadirectiveLoopVariants_;
500 const parser::traits::OmpContextSelectorSpecification *currentWhenSelector_{
501 nullptr};
502
503 std::multimap<const parser::Label,
504 std::pair<parser::CharBlock, const parser::OpenMPConstruct *>>
505 sourceLabels_;
506 std::map<const parser::Label,
507 std::pair<parser::CharBlock, const parser::OpenMPConstruct *>>
508 targetLabels_;
509 parser::CharBlock currentStatementSource_;
510};
511
512template <typename A>
513void OmpStructureChecker::Enter(const parser::Statement<A> &statement) {
514 currentStatementSource_ = statement.source;
515 // Keep track of the labels in all the labelled statements
516 if (statement.label) {
517 auto label{statement.label.value()};
518 // Get the context to check if the labelled statement is in an
519 // enclosing OpenMP construct
520 auto *thisConstruct{GetCurrentConstruct()};
521 targetLabels_.emplace(
522 label, std::make_pair(currentStatementSource_, thisConstruct));
523 // Check if a statement that causes a jump to the 'label'
524 // has already been encountered
525 auto range{sourceLabels_.equal_range(label)};
526 for (auto it{range.first}; it != range.second; ++it) {
527 // Check if both the statement with 'label' and the statement that
528 // causes a jump to the 'label' are in the same scope
529 CheckLabelContext(it->second.first, currentStatementSource_,
530 it->second.second, thisConstruct);
531 }
532 }
533}
534
537template <typename LessTy, typename RangeTy, typename IterTy>
538std::optional<IterTy> OmpStructureChecker::FindDuplicate(RangeTy &&range) {
539 // Deal with iterators, since the actual elements may be rvalues (i.e.
540 // have no addresses), for example with custom-constructed ranges that
541 // are not simple c.begin()..c.end().
542 std::set<IterTy, LessTy> uniq;
543 for (auto it{range.begin()}, end{range.end()}; it != end; ++it) {
544 if (!uniq.insert(it).second) {
545 return it;
546 }
547 }
548 return std::nullopt;
549}
550} // namespace Fortran::semantics
551#endif // FORTRAN_SEMANTICS_CHECK_OMP_STRUCTURE_H_
Definition enum-set.h:28
Definition expression.h:920
Definition common.h:215
Definition char-block.h:26
Definition check-directive-structure.h:208
Definition semantics.h:67
Definition FIRType.h:106
Definition parse-tree.h:3541
Definition parse-tree.h:1938
Definition parse-tree.h:3551
Definition parse-tree.h:2222
Definition parse-tree.h:3061
Definition parse-tree.h:2550
Definition parse-tree.h:1848
Definition parse-tree.h:1887
Definition parse-tree.h:2365
Definition parse-tree.h:558
Definition parse-tree.h:3181
Definition parse-tree.h:467
Definition parse-tree.h:2969
Definition parse-tree.h:2983
Definition parse-tree.h:3005
Definition parse-tree.h:591
Definition parse-tree.h:5397
Definition parse-tree.h:5186
Definition parse-tree.h:5196
Definition parse-tree.h:5155
Definition parse-tree.h:5139
Definition parse-tree.h:5324
Definition parse-tree.h:5341
Definition parse-tree.h:5316
Definition parse-tree.h:3577
Definition parse-tree.h:5162
Definition parse-tree.h:4586
Definition parse-tree.h:5350
Definition parse-tree.h:5209
Definition parse-tree.h:3632
Definition parse-tree.h:3620
Definition parse-tree.h:3676
Definition parse-tree.h:5357
Definition parse-tree.h:5363
Definition parse-tree.h:5423
Definition parse-tree.h:5428
Definition parse-tree.h:5465
Definition parse-tree.h:5549
Definition parse-tree.h:5413
Definition parse-tree.h:5476
Definition parse-tree.h:5490
Definition parse-tree.h:5506
Definition parse-tree.h:5514
Definition parse-tree.h:5567
Definition parse-tree.h:5535
Definition parse-tree.h:5281
Definition parse-tree.h:575
Definition parse-tree.h:455
Definition parse-tree.h:361
Definition parse-tree.h:3047
Definition parse-tree.h:3200
Definition parse-tree.h:4060
Definition parse-tree.h:4126
Definition parse-tree.h:4136
Definition parse-tree.h:4144
Definition parse-tree.h:4168
Definition parse-tree.h:4303
Definition parse-tree.h:3813
Definition parse-tree.h:3779
Definition parse-tree.h:3852
Definition parse-tree.h:3874
Definition check-omp-atomic.cpp:242
Definition openmp-utils.h:363