xref: /freebsd/contrib/llvm-project/clang/include/clang/Sema/SemaOpenMP.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===----- SemaOpenMP.h -- Semantic Analysis for OpenMP constructs -------===//
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 /// \file
9 /// This file declares semantic analysis for OpenMP constructs and
10 /// clauses.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_SEMA_SEMAOPENMP_H
15 #define LLVM_CLANG_SEMA_SEMAOPENMP_H
16 
17 #include "clang/AST/ASTFwd.h"
18 #include "clang/AST/Attr.h"
19 #include "clang/AST/DeclarationName.h"
20 #include "clang/AST/ExprOpenMP.h"
21 #include "clang/AST/OpenMPClause.h"
22 #include "clang/AST/StmtOpenMP.h"
23 #include "clang/Basic/IdentifierTable.h"
24 #include "clang/Basic/LLVM.h"
25 #include "clang/Basic/OpenMPKinds.h"
26 #include "clang/Basic/SourceLocation.h"
27 #include "clang/Basic/Specifiers.h"
28 #include "clang/Sema/DeclSpec.h"
29 #include "clang/Sema/Ownership.h"
30 #include "clang/Sema/SemaBase.h"
31 #include "llvm/ADT/DenseMap.h"
32 #include "llvm/Frontend/OpenMP/OMP.h.inc"
33 #include "llvm/Frontend/OpenMP/OMPConstants.h"
34 #include <optional>
35 #include <string>
36 #include <utility>
37 
38 namespace clang {
39 namespace sema {
40 class FunctionScopeInfo;
41 } // namespace sema
42 
43 class DeclContext;
44 class DeclGroupRef;
45 class ParsedAttr;
46 class Scope;
47 
48 class SemaOpenMP : public SemaBase {
49 public:
50   SemaOpenMP(Sema &S);
51 
52   friend class Parser;
53   friend class Sema;
54 
55   using DeclGroupPtrTy = OpaquePtr<DeclGroupRef>;
56   using CapturedParamNameType = std::pair<StringRef, QualType>;
57 
58   /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current
59   /// context is "used as device code".
60   ///
61   /// - If CurContext is a `declare target` function or it is known that the
62   /// function is emitted for the device, emits the diagnostics immediately.
63   /// - If CurContext is a non-`declare target` function and we are compiling
64   ///   for the device, creates a diagnostic which is emitted if and when we
65   ///   realize that the function will be codegen'ed.
66   ///
67   /// Example usage:
68   ///
69   ///  // Variable-length arrays are not allowed in NVPTX device code.
70   ///  if (diagIfOpenMPDeviceCode(Loc, diag::err_vla_unsupported))
71   ///    return ExprError();
72   ///  // Otherwise, continue parsing as normal.
73   SemaDiagnosticBuilder diagIfOpenMPDeviceCode(SourceLocation Loc,
74                                                unsigned DiagID,
75                                                const FunctionDecl *FD);
76 
77   /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current
78   /// context is "used as host code".
79   ///
80   /// - If CurContext is a `declare target` function or it is known that the
81   /// function is emitted for the host, emits the diagnostics immediately.
82   /// - If CurContext is a non-host function, just ignore it.
83   ///
84   /// Example usage:
85   ///
86   ///  // Variable-length arrays are not allowed in NVPTX device code.
87   ///  if (diagIfOpenMPHostode(Loc, diag::err_vla_unsupported))
88   ///    return ExprError();
89   ///  // Otherwise, continue parsing as normal.
90   SemaDiagnosticBuilder diagIfOpenMPHostCode(SourceLocation Loc,
91                                              unsigned DiagID,
92                                              const FunctionDecl *FD);
93 
94   /// The declarator \p D defines a function in the scope \p S which is nested
95   /// in an `omp begin/end declare variant` scope. In this method we create a
96   /// declaration for \p D and rename \p D according to the OpenMP context
97   /// selector of the surrounding scope. Return all base functions in \p Bases.
98   void ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
99       Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists,
100       SmallVectorImpl<FunctionDecl *> &Bases);
101 
102   /// Register \p D as specialization of all base functions in \p Bases in the
103   /// current `omp begin/end declare variant` scope.
104   void ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope(
105       Decl *D, SmallVectorImpl<FunctionDecl *> &Bases);
106 
107   /// Act on \p D, a function definition inside of an `omp [begin/end] assumes`.
108   void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D);
109 
110   /// Can we exit an OpenMP declare variant scope at the moment.
isInOpenMPDeclareVariantScope()111   bool isInOpenMPDeclareVariantScope() const {
112     return !OMPDeclareVariantScopes.empty();
113   }
114 
115   ExprResult
116   VerifyPositiveIntegerConstantInClause(Expr *Op, OpenMPClauseKind CKind,
117                                         bool StrictlyPositive = true,
118                                         bool SuppressExprDiags = false);
119 
120   /// Given the potential call expression \p Call, determine if there is a
121   /// specialization via the OpenMP declare variant mechanism available. If
122   /// there is, return the specialized call expression, otherwise return the
123   /// original \p Call.
124   ExprResult ActOnOpenMPCall(ExprResult Call, Scope *Scope,
125                              SourceLocation LParenLoc, MultiExprArg ArgExprs,
126                              SourceLocation RParenLoc, Expr *ExecConfig);
127 
128   /// Handle a `omp begin declare variant`.
129   void ActOnOpenMPBeginDeclareVariant(SourceLocation Loc, OMPTraitInfo &TI);
130 
131   /// Handle a `omp end declare variant`.
132   void ActOnOpenMPEndDeclareVariant();
133 
134   /// Function tries to capture lambda's captured variables in the OpenMP region
135   /// before the original lambda is captured.
136   void tryCaptureOpenMPLambdas(ValueDecl *V);
137 
138   /// Return true if the provided declaration \a VD should be captured by
139   /// reference.
140   /// \param Level Relative level of nested OpenMP construct for that the check
141   /// is performed.
142   /// \param OpenMPCaptureLevel Capture level within an OpenMP construct.
143   bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level,
144                              unsigned OpenMPCaptureLevel) const;
145 
146   /// Check if the specified variable is used in one of the private
147   /// clauses (private, firstprivate, lastprivate, reduction etc.) in OpenMP
148   /// constructs.
149   VarDecl *isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo = false,
150                                 unsigned StopAt = 0);
151 
152   /// The member expression(this->fd) needs to be rebuilt in the template
153   /// instantiation to generate private copy for OpenMP when default
154   /// clause is used. The function will return true if default
155   /// cluse is used.
156   bool isOpenMPRebuildMemberExpr(ValueDecl *D);
157 
158   ExprResult getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK,
159                                    ExprObjectKind OK, SourceLocation Loc);
160 
161   /// If the current region is a loop-based region, mark the start of the loop
162   /// construct.
163   void startOpenMPLoop();
164 
165   /// If the current region is a range loop-based region, mark the start of the
166   /// loop construct.
167   void startOpenMPCXXRangeFor();
168 
169   /// Check if the specified variable is used in 'private' clause.
170   /// \param Level Relative level of nested OpenMP construct for that the check
171   /// is performed.
172   OpenMPClauseKind isOpenMPPrivateDecl(ValueDecl *D, unsigned Level,
173                                        unsigned CapLevel) const;
174 
175   /// Sets OpenMP capture kind (OMPC_private, OMPC_firstprivate, OMPC_map etc.)
176   /// for \p FD based on DSA for the provided corresponding captured declaration
177   /// \p D.
178   void setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, unsigned Level);
179 
180   /// Check if the specified variable is captured  by 'target' directive.
181   /// \param Level Relative level of nested OpenMP construct for that the check
182   /// is performed.
183   bool isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level,
184                                   unsigned CaptureLevel) const;
185 
186   /// Check if the specified global variable must be captured  by outer capture
187   /// regions.
188   /// \param Level Relative level of nested OpenMP construct for that
189   /// the check is performed.
190   bool isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level,
191                                   unsigned CaptureLevel) const;
192 
193   ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc,
194                                                     Expr *Op);
195   /// Called on start of new data sharing attribute block.
196   void StartOpenMPDSABlock(OpenMPDirectiveKind K,
197                            const DeclarationNameInfo &DirName, Scope *CurScope,
198                            SourceLocation Loc);
199   /// Start analysis of clauses.
200   void StartOpenMPClause(OpenMPClauseKind K);
201   /// End analysis of clauses.
202   void EndOpenMPClause();
203   /// Called on end of data sharing attribute block.
204   void EndOpenMPDSABlock(Stmt *CurDirective);
205 
206   /// Check if the current region is an OpenMP loop region and if it is,
207   /// mark loop control variable, used in \p Init for loop initialization, as
208   /// private by default.
209   /// \param Init First part of the for loop.
210   void ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init);
211 
212   /// Called on well-formed '\#pragma omp metadirective' after parsing
213   /// of the  associated statement.
214   StmtResult ActOnOpenMPMetaDirective(ArrayRef<OMPClause *> Clauses,
215                                       Stmt *AStmt, SourceLocation StartLoc,
216                                       SourceLocation EndLoc);
217 
218   // OpenMP directives and clauses.
219   /// Called on correct id-expression from the '#pragma omp
220   /// threadprivate'.
221   ExprResult ActOnOpenMPIdExpression(Scope *CurScope, CXXScopeSpec &ScopeSpec,
222                                      const DeclarationNameInfo &Id,
223                                      OpenMPDirectiveKind Kind);
224   /// Called on well-formed '#pragma omp threadprivate'.
225   DeclGroupPtrTy ActOnOpenMPThreadprivateDirective(SourceLocation Loc,
226                                                    ArrayRef<Expr *> VarList);
227   /// Builds a new OpenMPThreadPrivateDecl and checks its correctness.
228   OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(SourceLocation Loc,
229                                                   ArrayRef<Expr *> VarList);
230   /// Called on well-formed '#pragma omp allocate'.
231   DeclGroupPtrTy ActOnOpenMPAllocateDirective(SourceLocation Loc,
232                                               ArrayRef<Expr *> VarList,
233                                               ArrayRef<OMPClause *> Clauses,
234                                               DeclContext *Owner = nullptr);
235 
236   /// Called on well-formed '#pragma omp [begin] assume[s]'.
237   void ActOnOpenMPAssumesDirective(SourceLocation Loc,
238                                    OpenMPDirectiveKind DKind,
239                                    ArrayRef<std::string> Assumptions,
240                                    bool SkippedClauses);
241 
242   /// Check if there is an active global `omp begin assumes` directive.
isInOpenMPAssumeScope()243   bool isInOpenMPAssumeScope() const { return !OMPAssumeScoped.empty(); }
244 
245   /// Check if there is an active global `omp assumes` directive.
hasGlobalOpenMPAssumes()246   bool hasGlobalOpenMPAssumes() const { return !OMPAssumeGlobal.empty(); }
247 
248   /// Called on well-formed '#pragma omp end assumes'.
249   void ActOnOpenMPEndAssumesDirective();
250 
251   /// Called on well-formed '#pragma omp requires'.
252   DeclGroupPtrTy ActOnOpenMPRequiresDirective(SourceLocation Loc,
253                                               ArrayRef<OMPClause *> ClauseList);
254   /// Check restrictions on Requires directive
255   OMPRequiresDecl *CheckOMPRequiresDecl(SourceLocation Loc,
256                                         ArrayRef<OMPClause *> Clauses);
257   /// Check if the specified type is allowed to be used in 'omp declare
258   /// reduction' construct.
259   QualType ActOnOpenMPDeclareReductionType(SourceLocation TyLoc,
260                                            TypeResult ParsedType);
261   /// Called on start of '#pragma omp declare reduction'.
262   DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveStart(
263       Scope *S, DeclContext *DC, DeclarationName Name,
264       ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes,
265       AccessSpecifier AS, Decl *PrevDeclInScope = nullptr);
266   /// Initialize declare reduction construct initializer.
267   void ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D);
268   /// Finish current declare reduction construct initializer.
269   void ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner);
270   /// Initialize declare reduction construct initializer.
271   /// \return omp_priv variable.
272   VarDecl *ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D);
273   /// Finish current declare reduction construct initializer.
274   void ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer,
275                                                  VarDecl *OmpPrivParm);
276   /// Called at the end of '#pragma omp declare reduction'.
277   DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveEnd(
278       Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid);
279 
280   /// Check variable declaration in 'omp declare mapper' construct.
281   TypeResult ActOnOpenMPDeclareMapperVarDecl(Scope *S, Declarator &D);
282   /// Check if the specified type is allowed to be used in 'omp declare
283   /// mapper' construct.
284   QualType ActOnOpenMPDeclareMapperType(SourceLocation TyLoc,
285                                         TypeResult ParsedType);
286   /// Called for '#pragma omp declare mapper'.
287   DeclGroupPtrTy ActOnOpenMPDeclareMapperDirective(
288       Scope *S, DeclContext *DC, DeclarationName Name, QualType MapperType,
289       SourceLocation StartLoc, DeclarationName VN, AccessSpecifier AS,
290       Expr *MapperVarRef, ArrayRef<OMPClause *> Clauses,
291       Decl *PrevDeclInScope = nullptr);
292   /// Build the mapper variable of '#pragma omp declare mapper'.
293   ExprResult ActOnOpenMPDeclareMapperDirectiveVarDecl(Scope *S,
294                                                       QualType MapperType,
295                                                       SourceLocation StartLoc,
296                                                       DeclarationName VN);
297   void ActOnOpenMPIteratorVarDecl(VarDecl *VD);
298   bool isOpenMPDeclareMapperVarDeclAllowed(const VarDecl *VD) const;
299   const ValueDecl *getOpenMPDeclareMapperVarName() const;
300 
301   struct DeclareTargetContextInfo {
302     struct MapInfo {
303       OMPDeclareTargetDeclAttr::MapTypeTy MT;
304       SourceLocation Loc;
305     };
306     /// Explicitly listed variables and functions in a 'to' or 'link' clause.
307     llvm::DenseMap<NamedDecl *, MapInfo> ExplicitlyMapped;
308 
309     /// The 'device_type' as parsed from the clause.
310     OMPDeclareTargetDeclAttr::DevTypeTy DT = OMPDeclareTargetDeclAttr::DT_Any;
311 
312     /// The directive kind, `begin declare target` or `declare target`.
313     OpenMPDirectiveKind Kind;
314 
315     /// The directive with indirect clause.
316     std::optional<Expr *> Indirect;
317 
318     /// The directive location.
319     SourceLocation Loc;
320 
DeclareTargetContextInfoDeclareTargetContextInfo321     DeclareTargetContextInfo(OpenMPDirectiveKind Kind, SourceLocation Loc)
322         : Kind(Kind), Loc(Loc) {}
323   };
324 
325   /// Called on the start of target region i.e. '#pragma omp declare target'.
326   bool ActOnStartOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI);
327 
328   /// Called at the end of target region i.e. '#pragma omp end declare target'.
329   const DeclareTargetContextInfo ActOnOpenMPEndDeclareTargetDirective();
330 
331   /// Called once a target context is completed, that can be when a
332   /// '#pragma omp end declare target' was encountered or when a
333   /// '#pragma omp declare target' without declaration-definition-seq was
334   /// encountered.
335   void ActOnFinishedOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI);
336 
337   /// Report unterminated 'omp declare target' or 'omp begin declare target' at
338   /// the end of a compilation unit.
339   void DiagnoseUnterminatedOpenMPDeclareTarget();
340 
341   /// Searches for the provided declaration name for OpenMP declare target
342   /// directive.
343   NamedDecl *lookupOpenMPDeclareTargetName(Scope *CurScope,
344                                            CXXScopeSpec &ScopeSpec,
345                                            const DeclarationNameInfo &Id);
346 
347   /// Called on correct id-expression from the '#pragma omp declare target'.
348   void ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc,
349                                     OMPDeclareTargetDeclAttr::MapTypeTy MT,
350                                     DeclareTargetContextInfo &DTCI);
351 
352   /// Check declaration inside target region.
353   void
354   checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D,
355                                    SourceLocation IdLoc = SourceLocation());
356 
357   /// Adds OMPDeclareTargetDeclAttr to referenced variables in declare target
358   /// directive.
359   void ActOnOpenMPDeclareTargetInitializer(Decl *D);
360 
361   /// Finishes analysis of the deferred functions calls that may be declared as
362   /// host/nohost during device/host compilation.
363   void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller,
364                                      const FunctionDecl *Callee,
365                                      SourceLocation Loc);
366 
367   /// Return true if currently in OpenMP task with untied clause context.
368   bool isInOpenMPTaskUntiedContext() const;
369 
370   /// Return true inside OpenMP declare target region.
isInOpenMPDeclareTargetContext()371   bool isInOpenMPDeclareTargetContext() const {
372     return !DeclareTargetNesting.empty();
373   }
374   /// Return true inside OpenMP target region.
375   bool isInOpenMPTargetExecutionDirective() const;
376 
377   /// Return the number of captured regions created for an OpenMP directive.
378   static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind);
379 
380   /// Initialization of captured region for OpenMP region.
381   void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope);
382 
383   /// Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to
384   /// an OpenMP loop directive.
385   StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt);
386 
387   /// Process a canonical OpenMP loop nest that can either be a canonical
388   /// literal loop (ForStmt or CXXForRangeStmt), or the generated loop of an
389   /// OpenMP loop transformation construct.
390   StmtResult ActOnOpenMPLoopnest(Stmt *AStmt);
391 
392   /// End of OpenMP region.
393   ///
394   /// \param S Statement associated with the current OpenMP region.
395   /// \param Clauses List of clauses for the current OpenMP region.
396   ///
397   /// \returns Statement for finished OpenMP region.
398   StmtResult ActOnOpenMPRegionEnd(StmtResult S, ArrayRef<OMPClause *> Clauses);
399   StmtResult ActOnOpenMPExecutableDirective(
400       OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName,
401       OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
402       Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc);
403   /// Process an OpenMP informational directive.
404   ///
405   /// \param Kind The directive kind.
406   /// \param DirName Declaration name info.
407   /// \param Clauses Array of clauses for directive.
408   /// \param AStmt The associated statement.
409   /// \param StartLoc The start location.
410   /// \param EndLoc The end location.
411   StmtResult ActOnOpenMPInformationalDirective(
412       OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName,
413       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
414       SourceLocation EndLoc);
415   /// Process an OpenMP assume directive.
416   ///
417   /// \param Clauses Array of clauses for directive.
418   /// \param AStmt The associated statement.
419   /// \param StartLoc The start location.
420   /// \param EndLoc The end location.
421   StmtResult ActOnOpenMPAssumeDirective(ArrayRef<OMPClause *> Clauses,
422                                         Stmt *AStmt, SourceLocation StartLoc,
423                                         SourceLocation EndLoc);
424 
425   /// Called on well-formed '\#pragma omp parallel' after parsing
426   /// of the  associated statement.
427   StmtResult ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses,
428                                           Stmt *AStmt, SourceLocation StartLoc,
429                                           SourceLocation EndLoc);
430   using VarsWithInheritedDSAType =
431       llvm::SmallDenseMap<const ValueDecl *, const Expr *, 4>;
432   /// Called on well-formed '\#pragma omp simd' after parsing
433   /// of the associated statement.
434   StmtResult
435   ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
436                            SourceLocation StartLoc, SourceLocation EndLoc,
437                            VarsWithInheritedDSAType &VarsWithImplicitDSA);
438   /// Called on well-formed '#pragma omp tile' after parsing of its clauses and
439   /// the associated statement.
440   StmtResult ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
441                                       Stmt *AStmt, SourceLocation StartLoc,
442                                       SourceLocation EndLoc);
443   StmtResult ActOnOpenMPStripeDirective(ArrayRef<OMPClause *> Clauses,
444                                         Stmt *AStmt, SourceLocation StartLoc,
445                                         SourceLocation EndLoc);
446   /// Called on well-formed '#pragma omp unroll' after parsing of its clauses
447   /// and the associated statement.
448   StmtResult ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses,
449                                         Stmt *AStmt, SourceLocation StartLoc,
450                                         SourceLocation EndLoc);
451   /// Called on well-formed '#pragma omp reverse'.
452   StmtResult ActOnOpenMPReverseDirective(Stmt *AStmt, SourceLocation StartLoc,
453                                          SourceLocation EndLoc);
454   /// Called on well-formed '#pragma omp interchange' after parsing of its
455   /// clauses and the associated statement.
456   StmtResult ActOnOpenMPInterchangeDirective(ArrayRef<OMPClause *> Clauses,
457                                              Stmt *AStmt,
458                                              SourceLocation StartLoc,
459                                              SourceLocation EndLoc);
460   /// Called on well-formed '\#pragma omp for' after parsing
461   /// of the associated statement.
462   StmtResult
463   ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
464                           SourceLocation StartLoc, SourceLocation EndLoc,
465                           VarsWithInheritedDSAType &VarsWithImplicitDSA);
466   /// Called on well-formed '\#pragma omp for simd' after parsing
467   /// of the associated statement.
468   StmtResult
469   ActOnOpenMPForSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
470                               SourceLocation StartLoc, SourceLocation EndLoc,
471                               VarsWithInheritedDSAType &VarsWithImplicitDSA);
472   /// Called on well-formed '\#pragma omp sections' after parsing
473   /// of the associated statement.
474   StmtResult ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
475                                           Stmt *AStmt, SourceLocation StartLoc,
476                                           SourceLocation EndLoc);
477   /// Called on well-formed '\#pragma omp section' after parsing of the
478   /// associated statement.
479   StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc,
480                                          SourceLocation EndLoc);
481   /// Called on well-formed '\#pragma omp scope' after parsing of the
482   /// associated statement.
483   StmtResult ActOnOpenMPScopeDirective(ArrayRef<OMPClause *> Clauses,
484                                        Stmt *AStmt, SourceLocation StartLoc,
485                                        SourceLocation EndLoc);
486   /// Called on well-formed '\#pragma omp single' after parsing of the
487   /// associated statement.
488   StmtResult ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses,
489                                         Stmt *AStmt, SourceLocation StartLoc,
490                                         SourceLocation EndLoc);
491   /// Called on well-formed '\#pragma omp master' after parsing of the
492   /// associated statement.
493   StmtResult ActOnOpenMPMasterDirective(Stmt *AStmt, SourceLocation StartLoc,
494                                         SourceLocation EndLoc);
495   /// Called on well-formed '\#pragma omp critical' after parsing of the
496   /// associated statement.
497   StmtResult ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName,
498                                           ArrayRef<OMPClause *> Clauses,
499                                           Stmt *AStmt, SourceLocation StartLoc,
500                                           SourceLocation EndLoc);
501   /// Called on well-formed '\#pragma omp parallel for' after parsing
502   /// of the  associated statement.
503   StmtResult ActOnOpenMPParallelForDirective(
504       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
505       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
506   /// Called on well-formed '\#pragma omp parallel for simd' after
507   /// parsing of the  associated statement.
508   StmtResult ActOnOpenMPParallelForSimdDirective(
509       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
510       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
511   /// Called on well-formed '\#pragma omp parallel master' after
512   /// parsing of the  associated statement.
513   StmtResult ActOnOpenMPParallelMasterDirective(ArrayRef<OMPClause *> Clauses,
514                                                 Stmt *AStmt,
515                                                 SourceLocation StartLoc,
516                                                 SourceLocation EndLoc);
517   /// Called on well-formed '\#pragma omp parallel masked' after
518   /// parsing of the associated statement.
519   StmtResult ActOnOpenMPParallelMaskedDirective(ArrayRef<OMPClause *> Clauses,
520                                                 Stmt *AStmt,
521                                                 SourceLocation StartLoc,
522                                                 SourceLocation EndLoc);
523   /// Called on well-formed '\#pragma omp parallel sections' after
524   /// parsing of the  associated statement.
525   StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses,
526                                                   Stmt *AStmt,
527                                                   SourceLocation StartLoc,
528                                                   SourceLocation EndLoc);
529   /// Called on well-formed '\#pragma omp task' after parsing of the
530   /// associated statement.
531   StmtResult ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses,
532                                       Stmt *AStmt, SourceLocation StartLoc,
533                                       SourceLocation EndLoc);
534   /// Called on well-formed '\#pragma omp taskyield'.
535   StmtResult ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc,
536                                            SourceLocation EndLoc);
537   /// Called on well-formed '\#pragma omp error'.
538   /// Error direcitive is allowed in both declared and excutable contexts.
539   /// Adding InExContext to identify which context is called from.
540   StmtResult ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses,
541                                        SourceLocation StartLoc,
542                                        SourceLocation EndLoc,
543                                        bool InExContext = true);
544   /// Called on well-formed '\#pragma omp barrier'.
545   StmtResult ActOnOpenMPBarrierDirective(SourceLocation StartLoc,
546                                          SourceLocation EndLoc);
547   /// Called on well-formed '\#pragma omp taskwait'.
548   StmtResult ActOnOpenMPTaskwaitDirective(ArrayRef<OMPClause *> Clauses,
549                                           SourceLocation StartLoc,
550                                           SourceLocation EndLoc);
551   /// Called on well-formed '\#pragma omp taskgroup'.
552   StmtResult ActOnOpenMPTaskgroupDirective(ArrayRef<OMPClause *> Clauses,
553                                            Stmt *AStmt, SourceLocation StartLoc,
554                                            SourceLocation EndLoc);
555   /// Called on well-formed '\#pragma omp flush'.
556   StmtResult ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses,
557                                        SourceLocation StartLoc,
558                                        SourceLocation EndLoc);
559   /// Called on well-formed '\#pragma omp depobj'.
560   StmtResult ActOnOpenMPDepobjDirective(ArrayRef<OMPClause *> Clauses,
561                                         SourceLocation StartLoc,
562                                         SourceLocation EndLoc);
563   /// Called on well-formed '\#pragma omp scan'.
564   StmtResult ActOnOpenMPScanDirective(ArrayRef<OMPClause *> Clauses,
565                                       SourceLocation StartLoc,
566                                       SourceLocation EndLoc);
567   /// Called on well-formed '\#pragma omp ordered' after parsing of the
568   /// associated statement.
569   StmtResult ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses,
570                                          Stmt *AStmt, SourceLocation StartLoc,
571                                          SourceLocation EndLoc);
572   /// Called on well-formed '\#pragma omp atomic' after parsing of the
573   /// associated statement.
574   StmtResult ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses,
575                                         Stmt *AStmt, SourceLocation StartLoc,
576                                         SourceLocation EndLoc);
577   /// Called on well-formed '\#pragma omp target' after parsing of the
578   /// associated statement.
579   StmtResult ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses,
580                                         Stmt *AStmt, SourceLocation StartLoc,
581                                         SourceLocation EndLoc);
582   /// Called on well-formed '\#pragma omp target data' after parsing of
583   /// the associated statement.
584   StmtResult ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses,
585                                             Stmt *AStmt,
586                                             SourceLocation StartLoc,
587                                             SourceLocation EndLoc);
588   /// Called on well-formed '\#pragma omp target enter data' after
589   /// parsing of the associated statement.
590   StmtResult ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses,
591                                                  SourceLocation StartLoc,
592                                                  SourceLocation EndLoc,
593                                                  Stmt *AStmt);
594   /// Called on well-formed '\#pragma omp target exit data' after
595   /// parsing of the associated statement.
596   StmtResult ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses,
597                                                 SourceLocation StartLoc,
598                                                 SourceLocation EndLoc,
599                                                 Stmt *AStmt);
600   /// Called on well-formed '\#pragma omp target parallel' after
601   /// parsing of the associated statement.
602   StmtResult ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses,
603                                                 Stmt *AStmt,
604                                                 SourceLocation StartLoc,
605                                                 SourceLocation EndLoc);
606   /// Called on well-formed '\#pragma omp target parallel for' after
607   /// parsing of the  associated statement.
608   StmtResult ActOnOpenMPTargetParallelForDirective(
609       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
610       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
611   /// Called on well-formed '\#pragma omp teams' after parsing of the
612   /// associated statement.
613   StmtResult ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses,
614                                        Stmt *AStmt, SourceLocation StartLoc,
615                                        SourceLocation EndLoc);
616   /// Called on well-formed '\#pragma omp teams loop' after parsing of the
617   /// associated statement.
618   StmtResult ActOnOpenMPTeamsGenericLoopDirective(
619       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
620       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
621   /// Called on well-formed '\#pragma omp target teams loop' after parsing of
622   /// the associated statement.
623   StmtResult ActOnOpenMPTargetTeamsGenericLoopDirective(
624       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
625       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
626   /// Called on well-formed '\#pragma omp parallel loop' after parsing of the
627   /// associated statement.
628   StmtResult ActOnOpenMPParallelGenericLoopDirective(
629       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
630       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
631   /// Called on well-formed '\#pragma omp target parallel loop' after parsing
632   /// of the associated statement.
633   StmtResult ActOnOpenMPTargetParallelGenericLoopDirective(
634       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
635       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
636   /// Called on well-formed '\#pragma omp cancellation point'.
637   StmtResult
638   ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc,
639                                         SourceLocation EndLoc,
640                                         OpenMPDirectiveKind CancelRegion);
641   /// Called on well-formed '\#pragma omp cancel'.
642   StmtResult ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses,
643                                         SourceLocation StartLoc,
644                                         SourceLocation EndLoc,
645                                         OpenMPDirectiveKind CancelRegion);
646   /// Called on well-formed '\#pragma omp taskloop' after parsing of the
647   /// associated statement.
648   StmtResult
649   ActOnOpenMPTaskLoopDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
650                                SourceLocation StartLoc, SourceLocation EndLoc,
651                                VarsWithInheritedDSAType &VarsWithImplicitDSA);
652   /// Called on well-formed '\#pragma omp taskloop simd' after parsing of
653   /// the associated statement.
654   StmtResult ActOnOpenMPTaskLoopSimdDirective(
655       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
656       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
657   /// Called on well-formed '\#pragma omp master taskloop' after parsing of the
658   /// associated statement.
659   StmtResult ActOnOpenMPMasterTaskLoopDirective(
660       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
661       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
662   /// Called on well-formed '\#pragma omp master taskloop simd' after parsing of
663   /// the associated statement.
664   StmtResult ActOnOpenMPMasterTaskLoopSimdDirective(
665       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
666       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
667   /// Called on well-formed '\#pragma omp parallel master taskloop' after
668   /// parsing of the associated statement.
669   StmtResult ActOnOpenMPParallelMasterTaskLoopDirective(
670       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
671       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
672   /// Called on well-formed '\#pragma omp parallel master taskloop simd' after
673   /// parsing of the associated statement.
674   StmtResult ActOnOpenMPParallelMasterTaskLoopSimdDirective(
675       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
676       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
677   /// Called on well-formed '\#pragma omp masked taskloop' after parsing of the
678   /// associated statement.
679   StmtResult ActOnOpenMPMaskedTaskLoopDirective(
680       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
681       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
682   /// Called on well-formed '\#pragma omp masked taskloop simd' after parsing of
683   /// the associated statement.
684   StmtResult ActOnOpenMPMaskedTaskLoopSimdDirective(
685       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
686       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
687   /// Called on well-formed '\#pragma omp parallel masked taskloop' after
688   /// parsing of the associated statement.
689   StmtResult ActOnOpenMPParallelMaskedTaskLoopDirective(
690       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
691       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
692   /// Called on well-formed '\#pragma omp parallel masked taskloop simd' after
693   /// parsing of the associated statement.
694   StmtResult ActOnOpenMPParallelMaskedTaskLoopSimdDirective(
695       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
696       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
697   /// Called on well-formed '\#pragma omp distribute' after parsing
698   /// of the associated statement.
699   StmtResult
700   ActOnOpenMPDistributeDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
701                                  SourceLocation StartLoc, SourceLocation EndLoc,
702                                  VarsWithInheritedDSAType &VarsWithImplicitDSA);
703   /// Called on well-formed '\#pragma omp target update'.
704   StmtResult ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses,
705                                               SourceLocation StartLoc,
706                                               SourceLocation EndLoc,
707                                               Stmt *AStmt);
708   /// Called on well-formed '\#pragma omp distribute parallel for' after
709   /// parsing of the associated statement.
710   StmtResult ActOnOpenMPDistributeParallelForDirective(
711       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
712       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
713   /// Called on well-formed '\#pragma omp distribute parallel for simd'
714   /// after parsing of the associated statement.
715   StmtResult ActOnOpenMPDistributeParallelForSimdDirective(
716       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
717       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
718   /// Called on well-formed '\#pragma omp distribute simd' after
719   /// parsing of the associated statement.
720   StmtResult ActOnOpenMPDistributeSimdDirective(
721       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
722       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
723   /// Called on well-formed '\#pragma omp target parallel for simd' after
724   /// parsing of the associated statement.
725   StmtResult ActOnOpenMPTargetParallelForSimdDirective(
726       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
727       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
728   /// Called on well-formed '\#pragma omp target simd' after parsing of
729   /// the associated statement.
730   StmtResult
731   ActOnOpenMPTargetSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
732                                  SourceLocation StartLoc, SourceLocation EndLoc,
733                                  VarsWithInheritedDSAType &VarsWithImplicitDSA);
734   /// Called on well-formed '\#pragma omp teams distribute' after parsing of
735   /// the associated statement.
736   StmtResult ActOnOpenMPTeamsDistributeDirective(
737       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
738       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
739   /// Called on well-formed '\#pragma omp teams distribute simd' after parsing
740   /// of the associated statement.
741   StmtResult ActOnOpenMPTeamsDistributeSimdDirective(
742       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
743       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
744   /// Called on well-formed '\#pragma omp teams distribute parallel for simd'
745   /// after parsing of the associated statement.
746   StmtResult ActOnOpenMPTeamsDistributeParallelForSimdDirective(
747       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
748       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
749   /// Called on well-formed '\#pragma omp teams distribute parallel for'
750   /// after parsing of the associated statement.
751   StmtResult ActOnOpenMPTeamsDistributeParallelForDirective(
752       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
753       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
754   /// Called on well-formed '\#pragma omp target teams' after parsing of the
755   /// associated statement.
756   StmtResult ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses,
757                                              Stmt *AStmt,
758                                              SourceLocation StartLoc,
759                                              SourceLocation EndLoc);
760   /// Called on well-formed '\#pragma omp target teams distribute' after parsing
761   /// of the associated statement.
762   StmtResult ActOnOpenMPTargetTeamsDistributeDirective(
763       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
764       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
765   /// Called on well-formed '\#pragma omp target teams distribute parallel for'
766   /// after parsing of the associated statement.
767   StmtResult ActOnOpenMPTargetTeamsDistributeParallelForDirective(
768       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
769       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
770   /// Called on well-formed '\#pragma omp target teams distribute parallel for
771   /// simd' after parsing of the associated statement.
772   StmtResult ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective(
773       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
774       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
775   /// Called on well-formed '\#pragma omp target teams distribute simd' after
776   /// parsing of the associated statement.
777   StmtResult ActOnOpenMPTargetTeamsDistributeSimdDirective(
778       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
779       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
780   /// Called on well-formed '\#pragma omp interop'.
781   StmtResult ActOnOpenMPInteropDirective(ArrayRef<OMPClause *> Clauses,
782                                          SourceLocation StartLoc,
783                                          SourceLocation EndLoc);
784   /// Called on well-formed '\#pragma omp dispatch' after parsing of the
785   // /associated statement.
786   StmtResult ActOnOpenMPDispatchDirective(ArrayRef<OMPClause *> Clauses,
787                                           Stmt *AStmt, SourceLocation StartLoc,
788                                           SourceLocation EndLoc);
789   /// Called on well-formed '\#pragma omp masked' after parsing of the
790   // /associated statement.
791   StmtResult ActOnOpenMPMaskedDirective(ArrayRef<OMPClause *> Clauses,
792                                         Stmt *AStmt, SourceLocation StartLoc,
793                                         SourceLocation EndLoc);
794 
795   /// Called on well-formed '\#pragma omp loop' after parsing of the
796   /// associated statement.
797   StmtResult ActOnOpenMPGenericLoopDirective(
798       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
799       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
800 
801   /// Checks correctness of linear modifiers.
802   bool CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind,
803                                  SourceLocation LinLoc);
804   /// Checks that the specified declaration matches requirements for the linear
805   /// decls.
806   bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
807                              OpenMPLinearClauseKind LinKind, QualType Type,
808                              bool IsDeclareSimd = false);
809 
810   /// Called on well-formed '\#pragma omp declare simd' after parsing of
811   /// the associated method/function.
812   DeclGroupPtrTy ActOnOpenMPDeclareSimdDirective(
813       DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS,
814       Expr *Simdlen, ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds,
815       ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears,
816       ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR);
817 
818   /// Checks '\#pragma omp declare variant' variant function and original
819   /// functions after parsing of the associated method/function.
820   /// \param DG Function declaration to which declare variant directive is
821   /// applied to.
822   /// \param VariantRef Expression that references the variant function, which
823   /// must be used instead of the original one, specified in \p DG.
824   /// \param TI The trait info object representing the match clause.
825   /// \param NumAppendArgs The number of omp_interop_t arguments to account for
826   /// in checking.
827   /// \returns std::nullopt, if the function/variant function are not compatible
828   /// with the pragma, pair of original function/variant ref expression
829   /// otherwise.
830   std::optional<std::pair<FunctionDecl *, Expr *>>
831   checkOpenMPDeclareVariantFunction(DeclGroupPtrTy DG, Expr *VariantRef,
832                                     OMPTraitInfo &TI, unsigned NumAppendArgs,
833                                     SourceRange SR);
834 
835   /// Called on well-formed '\#pragma omp declare variant' after parsing of
836   /// the associated method/function.
837   /// \param FD Function declaration to which declare variant directive is
838   /// applied to.
839   /// \param VariantRef Expression that references the variant function, which
840   /// must be used instead of the original one, specified in \p DG.
841   /// \param TI The context traits associated with the function variant.
842   /// \param AdjustArgsNothing The list of 'nothing' arguments.
843   /// \param AdjustArgsNeedDevicePtr The list of 'need_device_ptr' arguments.
844   /// \param AppendArgs The list of 'append_args' arguments.
845   /// \param AdjustArgsLoc The Location of an 'adjust_args' clause.
846   /// \param AppendArgsLoc The Location of an 'append_args' clause.
847   /// \param SR The SourceRange of the 'declare variant' directive.
848   void ActOnOpenMPDeclareVariantDirective(
849       FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI,
850       ArrayRef<Expr *> AdjustArgsNothing,
851       ArrayRef<Expr *> AdjustArgsNeedDevicePtr,
852       ArrayRef<Expr *> AdjustArgsNeedDeviceAddr,
853       ArrayRef<OMPInteropInfo> AppendArgs, SourceLocation AdjustArgsLoc,
854       SourceLocation AppendArgsLoc, SourceRange SR);
855 
856   /// Called on device_num selector in context selectors.
857   void ActOnOpenMPDeviceNum(Expr *DeviceNumExpr);
858 
859   OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
860                                          SourceLocation StartLoc,
861                                          SourceLocation LParenLoc,
862                                          SourceLocation EndLoc);
863   /// Called on well-formed 'allocator' clause.
864   OMPClause *ActOnOpenMPAllocatorClause(Expr *Allocator,
865                                         SourceLocation StartLoc,
866                                         SourceLocation LParenLoc,
867                                         SourceLocation EndLoc);
868   /// Called on well-formed 'if' clause.
869   OMPClause *ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier,
870                                  Expr *Condition, SourceLocation StartLoc,
871                                  SourceLocation LParenLoc,
872                                  SourceLocation NameModifierLoc,
873                                  SourceLocation ColonLoc,
874                                  SourceLocation EndLoc);
875   /// Called on well-formed 'final' clause.
876   OMPClause *ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc,
877                                     SourceLocation LParenLoc,
878                                     SourceLocation EndLoc);
879   /// Called on well-formed 'num_threads' clause.
880   OMPClause *ActOnOpenMPNumThreadsClause(
881       OpenMPNumThreadsClauseModifier Modifier, Expr *NumThreads,
882       SourceLocation StartLoc, SourceLocation LParenLoc,
883       SourceLocation ModifierLoc, SourceLocation EndLoc);
884   /// Called on well-formed 'align' clause.
885   OMPClause *ActOnOpenMPAlignClause(Expr *Alignment, SourceLocation StartLoc,
886                                     SourceLocation LParenLoc,
887                                     SourceLocation EndLoc);
888   /// Called on well-formed 'safelen' clause.
889   OMPClause *ActOnOpenMPSafelenClause(Expr *Length, SourceLocation StartLoc,
890                                       SourceLocation LParenLoc,
891                                       SourceLocation EndLoc);
892   /// Called on well-formed 'simdlen' clause.
893   OMPClause *ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc,
894                                       SourceLocation LParenLoc,
895                                       SourceLocation EndLoc);
896   /// Called on well-form 'sizes' clause.
897   OMPClause *ActOnOpenMPSizesClause(ArrayRef<Expr *> SizeExprs,
898                                     SourceLocation StartLoc,
899                                     SourceLocation LParenLoc,
900                                     SourceLocation EndLoc);
901   /// Called on well-form 'permutation' clause after parsing its arguments.
902   OMPClause *ActOnOpenMPPermutationClause(ArrayRef<Expr *> PermExprs,
903                                           SourceLocation StartLoc,
904                                           SourceLocation LParenLoc,
905                                           SourceLocation EndLoc);
906   /// Called on well-form 'full' clauses.
907   OMPClause *ActOnOpenMPFullClause(SourceLocation StartLoc,
908                                    SourceLocation EndLoc);
909   /// Called on well-form 'partial' clauses.
910   OMPClause *ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc,
911                                       SourceLocation LParenLoc,
912                                       SourceLocation EndLoc);
913   /// Called on well-formed 'collapse' clause.
914   OMPClause *ActOnOpenMPCollapseClause(Expr *NumForLoops,
915                                        SourceLocation StartLoc,
916                                        SourceLocation LParenLoc,
917                                        SourceLocation EndLoc);
918   /// Called on well-formed 'ordered' clause.
919   OMPClause *
920   ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc,
921                            SourceLocation LParenLoc = SourceLocation(),
922                            Expr *NumForLoops = nullptr);
923   /// Called on well-formed 'grainsize' clause.
924   OMPClause *ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier,
925                                         Expr *Size, SourceLocation StartLoc,
926                                         SourceLocation LParenLoc,
927                                         SourceLocation ModifierLoc,
928                                         SourceLocation EndLoc);
929   /// Called on well-formed 'num_tasks' clause.
930   OMPClause *ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier,
931                                        Expr *NumTasks, SourceLocation StartLoc,
932                                        SourceLocation LParenLoc,
933                                        SourceLocation ModifierLoc,
934                                        SourceLocation EndLoc);
935   /// Called on well-formed 'hint' clause.
936   OMPClause *ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc,
937                                    SourceLocation LParenLoc,
938                                    SourceLocation EndLoc);
939   /// Called on well-formed 'detach' clause.
940   OMPClause *ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc,
941                                      SourceLocation LParenLoc,
942                                      SourceLocation EndLoc);
943 
944   OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, unsigned Argument,
945                                      SourceLocation ArgumentLoc,
946                                      SourceLocation StartLoc,
947                                      SourceLocation LParenLoc,
948                                      SourceLocation EndLoc);
949   /// Called on well-formed 'when' clause.
950   OMPClause *ActOnOpenMPWhenClause(OMPTraitInfo &TI, SourceLocation StartLoc,
951                                    SourceLocation LParenLoc,
952                                    SourceLocation EndLoc);
953   /// Called on well-formed 'default' clause.
954   OMPClause *ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind,
955                                       SourceLocation KindLoc,
956                                       SourceLocation StartLoc,
957                                       SourceLocation LParenLoc,
958                                       SourceLocation EndLoc);
959   /// Called on well-formed 'proc_bind' clause.
960   OMPClause *ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind,
961                                        SourceLocation KindLoc,
962                                        SourceLocation StartLoc,
963                                        SourceLocation LParenLoc,
964                                        SourceLocation EndLoc);
965   /// Called on well-formed 'order' clause.
966   OMPClause *ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier,
967                                     OpenMPOrderClauseKind Kind,
968                                     SourceLocation StartLoc,
969                                     SourceLocation LParenLoc,
970                                     SourceLocation MLoc, SourceLocation KindLoc,
971                                     SourceLocation EndLoc);
972   /// Called on well-formed 'update' clause.
973   OMPClause *ActOnOpenMPUpdateClause(OpenMPDependClauseKind Kind,
974                                      SourceLocation KindLoc,
975                                      SourceLocation StartLoc,
976                                      SourceLocation LParenLoc,
977                                      SourceLocation EndLoc);
978   /// Called on well-formed 'holds' clause.
979   OMPClause *ActOnOpenMPHoldsClause(Expr *E, SourceLocation StartLoc,
980                                     SourceLocation LParenLoc,
981                                     SourceLocation EndLoc);
982   /// Called on well-formed 'absent' or 'contains' clauses.
983   OMPClause *ActOnOpenMPDirectivePresenceClause(
984       OpenMPClauseKind CK, llvm::ArrayRef<OpenMPDirectiveKind> DKVec,
985       SourceLocation Loc, SourceLocation LLoc, SourceLocation RLoc);
986   OMPClause *ActOnOpenMPNullaryAssumptionClause(OpenMPClauseKind CK,
987                                                 SourceLocation Loc,
988                                                 SourceLocation RLoc);
989 
990   OMPClause *ActOnOpenMPSingleExprWithArgClause(
991       OpenMPClauseKind Kind, ArrayRef<unsigned> Arguments, Expr *Expr,
992       SourceLocation StartLoc, SourceLocation LParenLoc,
993       ArrayRef<SourceLocation> ArgumentsLoc, SourceLocation DelimLoc,
994       SourceLocation EndLoc);
995   /// Called on well-formed 'schedule' clause.
996   OMPClause *ActOnOpenMPScheduleClause(
997       OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
998       OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
999       SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1000       SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc);
1001 
1002   OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc,
1003                                SourceLocation EndLoc);
1004   /// Called on well-formed 'nowait' clause.
1005   OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc,
1006                                      SourceLocation EndLoc);
1007   /// Called on well-formed 'untied' clause.
1008   OMPClause *ActOnOpenMPUntiedClause(SourceLocation StartLoc,
1009                                      SourceLocation EndLoc);
1010   /// Called on well-formed 'mergeable' clause.
1011   OMPClause *ActOnOpenMPMergeableClause(SourceLocation StartLoc,
1012                                         SourceLocation EndLoc);
1013   /// Called on well-formed 'read' clause.
1014   OMPClause *ActOnOpenMPReadClause(SourceLocation StartLoc,
1015                                    SourceLocation EndLoc);
1016   /// Called on well-formed 'write' clause.
1017   OMPClause *ActOnOpenMPWriteClause(SourceLocation StartLoc,
1018                                     SourceLocation EndLoc);
1019   /// Called on well-formed 'update' clause.
1020   OMPClause *ActOnOpenMPUpdateClause(SourceLocation StartLoc,
1021                                      SourceLocation EndLoc);
1022   /// Called on well-formed 'capture' clause.
1023   OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc,
1024                                       SourceLocation EndLoc);
1025   /// Called on well-formed 'compare' clause.
1026   OMPClause *ActOnOpenMPCompareClause(SourceLocation StartLoc,
1027                                       SourceLocation EndLoc);
1028   /// Called on well-formed 'fail' clause.
1029   OMPClause *ActOnOpenMPFailClause(SourceLocation StartLoc,
1030                                    SourceLocation EndLoc);
1031   OMPClause *ActOnOpenMPFailClause(OpenMPClauseKind Kind,
1032                                    SourceLocation KindLoc,
1033                                    SourceLocation StartLoc,
1034                                    SourceLocation LParenLoc,
1035                                    SourceLocation EndLoc);
1036 
1037   /// Called on well-formed 'seq_cst' clause.
1038   OMPClause *ActOnOpenMPSeqCstClause(SourceLocation StartLoc,
1039                                      SourceLocation EndLoc);
1040   /// Called on well-formed 'acq_rel' clause.
1041   OMPClause *ActOnOpenMPAcqRelClause(SourceLocation StartLoc,
1042                                      SourceLocation EndLoc);
1043   /// Called on well-formed 'acquire' clause.
1044   OMPClause *ActOnOpenMPAcquireClause(SourceLocation StartLoc,
1045                                       SourceLocation EndLoc);
1046   /// Called on well-formed 'release' clause.
1047   OMPClause *ActOnOpenMPReleaseClause(SourceLocation StartLoc,
1048                                       SourceLocation EndLoc);
1049   /// Called on well-formed 'relaxed' clause.
1050   OMPClause *ActOnOpenMPRelaxedClause(SourceLocation StartLoc,
1051                                       SourceLocation EndLoc);
1052   /// Called on well-formed 'weak' clause.
1053   OMPClause *ActOnOpenMPWeakClause(SourceLocation StartLoc,
1054                                    SourceLocation EndLoc);
1055 
1056   /// Called on well-formed 'init' clause.
1057   OMPClause *
1058   ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo,
1059                         SourceLocation StartLoc, SourceLocation LParenLoc,
1060                         SourceLocation VarLoc, SourceLocation EndLoc);
1061 
1062   /// Called on well-formed 'use' clause.
1063   OMPClause *ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc,
1064                                   SourceLocation LParenLoc,
1065                                   SourceLocation VarLoc, SourceLocation EndLoc);
1066 
1067   /// Called on well-formed 'destroy' clause.
1068   OMPClause *ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc,
1069                                       SourceLocation LParenLoc,
1070                                       SourceLocation VarLoc,
1071                                       SourceLocation EndLoc);
1072   /// Called on well-formed 'novariants' clause.
1073   OMPClause *ActOnOpenMPNovariantsClause(Expr *Condition,
1074                                          SourceLocation StartLoc,
1075                                          SourceLocation LParenLoc,
1076                                          SourceLocation EndLoc);
1077   /// Called on well-formed 'nocontext' clause.
1078   OMPClause *ActOnOpenMPNocontextClause(Expr *Condition,
1079                                         SourceLocation StartLoc,
1080                                         SourceLocation LParenLoc,
1081                                         SourceLocation EndLoc);
1082   /// Called on well-formed 'filter' clause.
1083   OMPClause *ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc,
1084                                      SourceLocation LParenLoc,
1085                                      SourceLocation EndLoc);
1086   /// Called on well-formed 'threads' clause.
1087   OMPClause *ActOnOpenMPThreadsClause(SourceLocation StartLoc,
1088                                       SourceLocation EndLoc);
1089   /// Called on well-formed 'simd' clause.
1090   OMPClause *ActOnOpenMPSIMDClause(SourceLocation StartLoc,
1091                                    SourceLocation EndLoc);
1092   /// Called on well-formed 'nogroup' clause.
1093   OMPClause *ActOnOpenMPNogroupClause(SourceLocation StartLoc,
1094                                       SourceLocation EndLoc);
1095   /// Called on well-formed 'unified_address' clause.
1096   OMPClause *ActOnOpenMPUnifiedAddressClause(SourceLocation StartLoc,
1097                                              SourceLocation EndLoc);
1098 
1099   /// Called on well-formed 'unified_address' clause.
1100   OMPClause *ActOnOpenMPUnifiedSharedMemoryClause(SourceLocation StartLoc,
1101                                                   SourceLocation EndLoc);
1102 
1103   /// Called on well-formed 'reverse_offload' clause.
1104   OMPClause *ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc,
1105                                              SourceLocation EndLoc);
1106 
1107   /// Called on well-formed 'dynamic_allocators' clause.
1108   OMPClause *ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc,
1109                                                 SourceLocation EndLoc);
1110 
1111   /// Called on well-formed 'atomic_default_mem_order' clause.
1112   OMPClause *ActOnOpenMPAtomicDefaultMemOrderClause(
1113       OpenMPAtomicDefaultMemOrderClauseKind Kind, SourceLocation KindLoc,
1114       SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc);
1115 
1116   /// Called on well-formed 'self_maps' clause.
1117   OMPClause *ActOnOpenMPSelfMapsClause(SourceLocation StartLoc,
1118                                        SourceLocation EndLoc);
1119 
1120   /// Called on well-formed 'at' clause.
1121   OMPClause *ActOnOpenMPAtClause(OpenMPAtClauseKind Kind,
1122                                  SourceLocation KindLoc,
1123                                  SourceLocation StartLoc,
1124                                  SourceLocation LParenLoc,
1125                                  SourceLocation EndLoc);
1126 
1127   /// Called on well-formed 'severity' clause.
1128   OMPClause *ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind,
1129                                        SourceLocation KindLoc,
1130                                        SourceLocation StartLoc,
1131                                        SourceLocation LParenLoc,
1132                                        SourceLocation EndLoc);
1133 
1134   /// Called on well-formed 'message' clause.
1135   /// passing string for message.
1136   OMPClause *ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc,
1137                                       SourceLocation LParenLoc,
1138                                       SourceLocation EndLoc);
1139 
1140   /// Data used for processing a list of variables in OpenMP clauses.
1141   struct OpenMPVarListDataTy final {
1142     Expr *DepModOrTailExpr = nullptr;
1143     Expr *IteratorExpr = nullptr;
1144     SourceLocation ColonLoc;
1145     SourceLocation RLoc;
1146     CXXScopeSpec ReductionOrMapperIdScopeSpec;
1147     DeclarationNameInfo ReductionOrMapperId;
1148     int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or
1149                             ///< lastprivate clause.
1150     int OriginalSharingModifier = 0; // Default is shared
1151     SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
1152         MapTypeModifiers;
1153     SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers>
1154         MapTypeModifiersLoc;
1155     SmallVector<OpenMPMotionModifierKind, NumberOfOMPMotionModifiers>
1156         MotionModifiers;
1157     SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc;
1158     bool IsMapTypeImplicit = false;
1159     SourceLocation ExtraModifierLoc;
1160     SourceLocation OriginalSharingModifierLoc;
1161     SourceLocation OmpAllMemoryLoc;
1162     SourceLocation
1163         StepModifierLoc; /// 'step' modifier location for linear clause
1164     SmallVector<OpenMPAllocateClauseModifier,
1165                 NumberOfOMPAllocateClauseModifiers>
1166         AllocClauseModifiers;
1167     SmallVector<SourceLocation, NumberOfOMPAllocateClauseModifiers>
1168         AllocClauseModifiersLoc;
1169     Expr *AllocateAlignment = nullptr;
1170     struct OpenMPReductionClauseModifiers {
1171       int ExtraModifier;
1172       int OriginalSharingModifier;
OpenMPReductionClauseModifiersfinal::OpenMPReductionClauseModifiers1173       OpenMPReductionClauseModifiers(int Extra, int Original)
1174           : ExtraModifier(Extra), OriginalSharingModifier(Original) {}
1175     };
1176   };
1177 
1178   OMPClause *ActOnOpenMPVarListClause(OpenMPClauseKind Kind,
1179                                       ArrayRef<Expr *> Vars,
1180                                       const OMPVarListLocTy &Locs,
1181                                       OpenMPVarListDataTy &Data);
1182   /// Called on well-formed 'inclusive' clause.
1183   OMPClause *ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList,
1184                                         SourceLocation StartLoc,
1185                                         SourceLocation LParenLoc,
1186                                         SourceLocation EndLoc);
1187   /// Called on well-formed 'exclusive' clause.
1188   OMPClause *ActOnOpenMPExclusiveClause(ArrayRef<Expr *> VarList,
1189                                         SourceLocation StartLoc,
1190                                         SourceLocation LParenLoc,
1191                                         SourceLocation EndLoc);
1192   /// Called on well-formed 'allocate' clause.
1193   OMPClause *
1194   ActOnOpenMPAllocateClause(Expr *Allocator, Expr *Alignment,
1195                             OpenMPAllocateClauseModifier FirstModifier,
1196                             SourceLocation FirstModifierLoc,
1197                             OpenMPAllocateClauseModifier SecondModifier,
1198                             SourceLocation SecondModifierLoc,
1199                             ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1200                             SourceLocation ColonLoc, SourceLocation LParenLoc,
1201                             SourceLocation EndLoc);
1202   /// Called on well-formed 'private' clause.
1203   OMPClause *ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList,
1204                                       SourceLocation StartLoc,
1205                                       SourceLocation LParenLoc,
1206                                       SourceLocation EndLoc);
1207   /// Called on well-formed 'firstprivate' clause.
1208   OMPClause *ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList,
1209                                            SourceLocation StartLoc,
1210                                            SourceLocation LParenLoc,
1211                                            SourceLocation EndLoc);
1212   /// Called on well-formed 'lastprivate' clause.
1213   OMPClause *ActOnOpenMPLastprivateClause(
1214       ArrayRef<Expr *> VarList, OpenMPLastprivateModifier LPKind,
1215       SourceLocation LPKindLoc, SourceLocation ColonLoc,
1216       SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc);
1217   /// Called on well-formed 'shared' clause.
1218   OMPClause *ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList,
1219                                      SourceLocation StartLoc,
1220                                      SourceLocation LParenLoc,
1221                                      SourceLocation EndLoc);
1222   /// Called on well-formed 'reduction' clause.
1223   OMPClause *ActOnOpenMPReductionClause(
1224       ArrayRef<Expr *> VarList,
1225       OpenMPVarListDataTy::OpenMPReductionClauseModifiers Modifiers,
1226       SourceLocation StartLoc, SourceLocation LParenLoc,
1227       SourceLocation ModifierLoc, SourceLocation ColonLoc,
1228       SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1229       const DeclarationNameInfo &ReductionId,
1230       ArrayRef<Expr *> UnresolvedReductions = {});
1231   /// Called on well-formed 'task_reduction' clause.
1232   OMPClause *ActOnOpenMPTaskReductionClause(
1233       ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1234       SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1235       CXXScopeSpec &ReductionIdScopeSpec,
1236       const DeclarationNameInfo &ReductionId,
1237       ArrayRef<Expr *> UnresolvedReductions = {});
1238   /// Called on well-formed 'in_reduction' clause.
1239   OMPClause *ActOnOpenMPInReductionClause(
1240       ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1241       SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1242       CXXScopeSpec &ReductionIdScopeSpec,
1243       const DeclarationNameInfo &ReductionId,
1244       ArrayRef<Expr *> UnresolvedReductions = {});
1245   /// Called on well-formed 'linear' clause.
1246   OMPClause *ActOnOpenMPLinearClause(
1247       ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1248       SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind,
1249       SourceLocation LinLoc, SourceLocation ColonLoc,
1250       SourceLocation StepModifierLoc, SourceLocation EndLoc);
1251   /// Called on well-formed 'aligned' clause.
1252   OMPClause *ActOnOpenMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1253                                       SourceLocation StartLoc,
1254                                       SourceLocation LParenLoc,
1255                                       SourceLocation ColonLoc,
1256                                       SourceLocation EndLoc);
1257   /// Called on well-formed 'copyin' clause.
1258   OMPClause *ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList,
1259                                      SourceLocation StartLoc,
1260                                      SourceLocation LParenLoc,
1261                                      SourceLocation EndLoc);
1262   /// Called on well-formed 'copyprivate' clause.
1263   OMPClause *ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList,
1264                                           SourceLocation StartLoc,
1265                                           SourceLocation LParenLoc,
1266                                           SourceLocation EndLoc);
1267   /// Called on well-formed 'flush' pseudo clause.
1268   OMPClause *ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList,
1269                                     SourceLocation StartLoc,
1270                                     SourceLocation LParenLoc,
1271                                     SourceLocation EndLoc);
1272   /// Called on well-formed 'depobj' pseudo clause.
1273   OMPClause *ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc,
1274                                      SourceLocation LParenLoc,
1275                                      SourceLocation EndLoc);
1276   /// Called on well-formed 'depend' clause.
1277   OMPClause *ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data,
1278                                      Expr *DepModifier,
1279                                      ArrayRef<Expr *> VarList,
1280                                      SourceLocation StartLoc,
1281                                      SourceLocation LParenLoc,
1282                                      SourceLocation EndLoc);
1283   /// Called on well-formed 'device' clause.
1284   OMPClause *ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier,
1285                                      Expr *Device, SourceLocation StartLoc,
1286                                      SourceLocation LParenLoc,
1287                                      SourceLocation ModifierLoc,
1288                                      SourceLocation EndLoc);
1289   /// Called on well-formed 'map' clause.
1290   OMPClause *ActOnOpenMPMapClause(
1291       Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1292       ArrayRef<SourceLocation> MapTypeModifiersLoc,
1293       CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId,
1294       OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1295       SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1296       const OMPVarListLocTy &Locs, bool NoDiagnose = false,
1297       ArrayRef<Expr *> UnresolvedMappers = {});
1298   /// Called on well-formed 'num_teams' clause.
1299   OMPClause *ActOnOpenMPNumTeamsClause(ArrayRef<Expr *> VarList,
1300                                        SourceLocation StartLoc,
1301                                        SourceLocation LParenLoc,
1302                                        SourceLocation EndLoc);
1303   /// Called on well-formed 'thread_limit' clause.
1304   OMPClause *ActOnOpenMPThreadLimitClause(ArrayRef<Expr *> VarList,
1305                                           SourceLocation StartLoc,
1306                                           SourceLocation LParenLoc,
1307                                           SourceLocation EndLoc);
1308   /// Called on well-formed 'priority' clause.
1309   OMPClause *ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1310                                        SourceLocation LParenLoc,
1311                                        SourceLocation EndLoc);
1312   /// Called on well-formed 'dist_schedule' clause.
1313   OMPClause *ActOnOpenMPDistScheduleClause(
1314       OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
1315       SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc,
1316       SourceLocation CommaLoc, SourceLocation EndLoc);
1317   /// Called on well-formed 'defaultmap' clause.
1318   OMPClause *ActOnOpenMPDefaultmapClause(
1319       OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind,
1320       SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc,
1321       SourceLocation KindLoc, SourceLocation EndLoc);
1322   /// Called on well-formed 'to' clause.
1323   OMPClause *
1324   ActOnOpenMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
1325                       ArrayRef<SourceLocation> MotionModifiersLoc,
1326                       CXXScopeSpec &MapperIdScopeSpec,
1327                       DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
1328                       ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
1329                       ArrayRef<Expr *> UnresolvedMappers = {});
1330   /// Called on well-formed 'from' clause.
1331   OMPClause *
1332   ActOnOpenMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
1333                         ArrayRef<SourceLocation> MotionModifiersLoc,
1334                         CXXScopeSpec &MapperIdScopeSpec,
1335                         DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
1336                         ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
1337                         ArrayRef<Expr *> UnresolvedMappers = {});
1338   /// Called on well-formed 'use_device_ptr' clause.
1339   OMPClause *ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1340                                            const OMPVarListLocTy &Locs);
1341   /// Called on well-formed 'use_device_addr' clause.
1342   OMPClause *ActOnOpenMPUseDeviceAddrClause(ArrayRef<Expr *> VarList,
1343                                             const OMPVarListLocTy &Locs);
1344   /// Called on well-formed 'is_device_ptr' clause.
1345   OMPClause *ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1346                                           const OMPVarListLocTy &Locs);
1347   /// Called on well-formed 'has_device_addr' clause.
1348   OMPClause *ActOnOpenMPHasDeviceAddrClause(ArrayRef<Expr *> VarList,
1349                                             const OMPVarListLocTy &Locs);
1350   /// Called on well-formed 'nontemporal' clause.
1351   OMPClause *ActOnOpenMPNontemporalClause(ArrayRef<Expr *> VarList,
1352                                           SourceLocation StartLoc,
1353                                           SourceLocation LParenLoc,
1354                                           SourceLocation EndLoc);
1355 
1356   /// Data for list of allocators.
1357   struct UsesAllocatorsData {
1358     /// Allocator.
1359     Expr *Allocator = nullptr;
1360     /// Allocator traits.
1361     Expr *AllocatorTraits = nullptr;
1362     /// Locations of '(' and ')' symbols.
1363     SourceLocation LParenLoc, RParenLoc;
1364   };
1365   /// Called on well-formed 'uses_allocators' clause.
1366   OMPClause *ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc,
1367                                             SourceLocation LParenLoc,
1368                                             SourceLocation EndLoc,
1369                                             ArrayRef<UsesAllocatorsData> Data);
1370   /// Called on well-formed 'affinity' clause.
1371   OMPClause *ActOnOpenMPAffinityClause(SourceLocation StartLoc,
1372                                        SourceLocation LParenLoc,
1373                                        SourceLocation ColonLoc,
1374                                        SourceLocation EndLoc, Expr *Modifier,
1375                                        ArrayRef<Expr *> Locators);
1376   /// Called on a well-formed 'bind' clause.
1377   OMPClause *ActOnOpenMPBindClause(OpenMPBindClauseKind Kind,
1378                                    SourceLocation KindLoc,
1379                                    SourceLocation StartLoc,
1380                                    SourceLocation LParenLoc,
1381                                    SourceLocation EndLoc);
1382 
1383   /// Called on a well-formed 'ompx_dyn_cgroup_mem' clause.
1384   OMPClause *ActOnOpenMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc,
1385                                             SourceLocation LParenLoc,
1386                                             SourceLocation EndLoc);
1387 
1388   /// Called on well-formed 'doacross' clause.
1389   OMPClause *
1390   ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType,
1391                             SourceLocation DepLoc, SourceLocation ColonLoc,
1392                             ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1393                             SourceLocation LParenLoc, SourceLocation EndLoc);
1394 
1395   /// Called on a well-formed 'ompx_attribute' clause.
1396   OMPClause *ActOnOpenMPXAttributeClause(ArrayRef<const Attr *> Attrs,
1397                                          SourceLocation StartLoc,
1398                                          SourceLocation LParenLoc,
1399                                          SourceLocation EndLoc);
1400 
1401   /// Called on a well-formed 'ompx_bare' clause.
1402   OMPClause *ActOnOpenMPXBareClause(SourceLocation StartLoc,
1403                                     SourceLocation EndLoc);
1404 
1405   ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc,
1406                                       Expr *LowerBound,
1407                                       SourceLocation ColonLocFirst,
1408                                       SourceLocation ColonLocSecond,
1409                                       Expr *Length, Expr *Stride,
1410                                       SourceLocation RBLoc);
1411   ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc,
1412                                       SourceLocation RParenLoc,
1413                                       ArrayRef<Expr *> Dims,
1414                                       ArrayRef<SourceRange> Brackets);
1415 
1416   /// Data structure for iterator expression.
1417   struct OMPIteratorData {
1418     IdentifierInfo *DeclIdent = nullptr;
1419     SourceLocation DeclIdentLoc;
1420     ParsedType Type;
1421     OMPIteratorExpr::IteratorRange Range;
1422     SourceLocation AssignLoc;
1423     SourceLocation ColonLoc;
1424     SourceLocation SecColonLoc;
1425   };
1426 
1427   ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc,
1428                                   SourceLocation LLoc, SourceLocation RLoc,
1429                                   ArrayRef<OMPIteratorData> Data);
1430 
1431   void handleOMPAssumeAttr(Decl *D, const ParsedAttr &AL);
1432 
1433   /// Setter and getter functions for device_num.
1434   void setOpenMPDeviceNum(int Num);
1435 
1436   int getOpenMPDeviceNum() const;
1437 
1438   void setOpenMPDeviceNumID(StringRef ID);
1439 
1440 private:
1441   void *VarDataSharingAttributesStack;
1442 
1443   /// Number of nested '#pragma omp declare target' directives.
1444   SmallVector<DeclareTargetContextInfo, 4> DeclareTargetNesting;
1445 
1446   /// Initialization of data-sharing attributes stack.
1447   void InitDataSharingAttributesStack();
1448   void DestroyDataSharingAttributesStack();
1449 
1450   /// Returns OpenMP nesting level for current directive.
1451   unsigned getOpenMPNestingLevel() const;
1452 
1453   /// Adjusts the function scopes index for the target-based regions.
1454   void adjustOpenMPTargetScopeIndex(unsigned &FunctionScopesIndex,
1455                                     unsigned Level) const;
1456 
1457   /// Returns the number of scopes associated with the construct on the given
1458   /// OpenMP level.
1459   int getNumberOfConstructScopes(unsigned Level) const;
1460 
1461   /// Push new OpenMP function region for non-capturing function.
1462   void pushOpenMPFunctionRegion();
1463 
1464   /// Pop OpenMP function region for non-capturing function.
1465   void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI);
1466 
1467   /// Analyzes and checks a loop nest for use by a loop transformation.
1468   ///
1469   /// \param Kind          The loop transformation directive kind.
1470   /// \param NumLoops      How many nested loops the directive is expecting.
1471   /// \param AStmt         Associated statement of the transformation directive.
1472   /// \param LoopHelpers   [out] The loop analysis result.
1473   /// \param Body          [out] The body code nested in \p NumLoops loop.
1474   /// \param OriginalInits [out] Collection of statements and declarations that
1475   ///                      must have been executed/declared before entering the
1476   ///                      loop.
1477   ///
1478   /// \return Whether there was any error.
1479   bool checkTransformableLoopNest(
1480       OpenMPDirectiveKind Kind, Stmt *AStmt, int NumLoops,
1481       SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers,
1482       Stmt *&Body, SmallVectorImpl<SmallVector<Stmt *, 0>> &OriginalInits);
1483 
1484   /// Helper to keep information about the current `omp begin/end declare
1485   /// variant` nesting.
1486   struct OMPDeclareVariantScope {
1487     /// The associated OpenMP context selector.
1488     OMPTraitInfo *TI;
1489 
1490     /// The associated OpenMP context selector mangling.
1491     std::string NameSuffix;
1492 
1493     OMPDeclareVariantScope(OMPTraitInfo &TI);
1494   };
1495 
1496   /// Return the OMPTraitInfo for the surrounding scope, if any.
getOMPTraitInfoForSurroundingScope()1497   OMPTraitInfo *getOMPTraitInfoForSurroundingScope() {
1498     return OMPDeclareVariantScopes.empty() ? nullptr
1499                                            : OMPDeclareVariantScopes.back().TI;
1500   }
1501 
1502   /// The current `omp begin/end declare variant` scopes.
1503   SmallVector<OMPDeclareVariantScope, 4> OMPDeclareVariantScopes;
1504 
1505   /// The current `omp begin/end assumes` scopes.
1506   SmallVector<OMPAssumeAttr *, 4> OMPAssumeScoped;
1507 
1508   /// All `omp assumes` we encountered so far.
1509   SmallVector<OMPAssumeAttr *, 4> OMPAssumeGlobal;
1510 
1511   /// Device number specified by the context selector.
1512   int DeviceNum = -1;
1513 
1514   /// Device number identifier specified by the context selector.
1515   StringRef DeviceNumID;
1516 };
1517 
1518 } // namespace clang
1519 
1520 #endif // LLVM_CLANG_SEMA_SEMAOPENMP_H
1521