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