Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:05

0001 //===----- SemaOpenMP.h -- Semantic Analysis for OpenMP constructs -------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 /// \file
0009 /// This file declares semantic analysis for OpenMP constructs and
0010 /// clauses.
0011 ///
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CLANG_SEMA_SEMAOPENMP_H
0015 #define LLVM_CLANG_SEMA_SEMAOPENMP_H
0016 
0017 #include "clang/AST/ASTFwd.h"
0018 #include "clang/AST/Attr.h"
0019 #include "clang/AST/DeclarationName.h"
0020 #include "clang/AST/ExprOpenMP.h"
0021 #include "clang/AST/OpenMPClause.h"
0022 #include "clang/AST/StmtOpenMP.h"
0023 #include "clang/Basic/IdentifierTable.h"
0024 #include "clang/Basic/LLVM.h"
0025 #include "clang/Basic/OpenMPKinds.h"
0026 #include "clang/Basic/SourceLocation.h"
0027 #include "clang/Basic/Specifiers.h"
0028 #include "clang/Sema/DeclSpec.h"
0029 #include "clang/Sema/Ownership.h"
0030 #include "clang/Sema/SemaBase.h"
0031 #include "llvm/ADT/DenseMap.h"
0032 #include "llvm/Frontend/OpenMP/OMP.h.inc"
0033 #include "llvm/Frontend/OpenMP/OMPConstants.h"
0034 #include <optional>
0035 #include <string>
0036 #include <utility>
0037 
0038 namespace clang {
0039 namespace sema {
0040 class FunctionScopeInfo;
0041 } // namespace sema
0042 
0043 class DeclContext;
0044 class DeclGroupRef;
0045 class ParsedAttr;
0046 class Scope;
0047 
0048 class SemaOpenMP : public SemaBase {
0049 public:
0050   SemaOpenMP(Sema &S);
0051 
0052   friend class Parser;
0053   friend class Sema;
0054 
0055   using DeclGroupPtrTy = OpaquePtr<DeclGroupRef>;
0056   using CapturedParamNameType = std::pair<StringRef, QualType>;
0057 
0058   /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current
0059   /// context is "used as device code".
0060   ///
0061   /// - If CurContext is a `declare target` function or it is known that the
0062   /// function is emitted for the device, emits the diagnostics immediately.
0063   /// - If CurContext is a non-`declare target` function and we are compiling
0064   ///   for the device, creates a diagnostic which is emitted if and when we
0065   ///   realize that the function will be codegen'ed.
0066   ///
0067   /// Example usage:
0068   ///
0069   ///  // Variable-length arrays are not allowed in NVPTX device code.
0070   ///  if (diagIfOpenMPDeviceCode(Loc, diag::err_vla_unsupported))
0071   ///    return ExprError();
0072   ///  // Otherwise, continue parsing as normal.
0073   SemaDiagnosticBuilder diagIfOpenMPDeviceCode(SourceLocation Loc,
0074                                                unsigned DiagID,
0075                                                const FunctionDecl *FD);
0076 
0077   /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current
0078   /// context is "used as host code".
0079   ///
0080   /// - If CurContext is a `declare target` function or it is known that the
0081   /// function is emitted for the host, emits the diagnostics immediately.
0082   /// - If CurContext is a non-host function, just ignore it.
0083   ///
0084   /// Example usage:
0085   ///
0086   ///  // Variable-length arrays are not allowed in NVPTX device code.
0087   ///  if (diagIfOpenMPHostode(Loc, diag::err_vla_unsupported))
0088   ///    return ExprError();
0089   ///  // Otherwise, continue parsing as normal.
0090   SemaDiagnosticBuilder diagIfOpenMPHostCode(SourceLocation Loc,
0091                                              unsigned DiagID,
0092                                              const FunctionDecl *FD);
0093 
0094   /// The declarator \p D defines a function in the scope \p S which is nested
0095   /// in an `omp begin/end declare variant` scope. In this method we create a
0096   /// declaration for \p D and rename \p D according to the OpenMP context
0097   /// selector of the surrounding scope. Return all base functions in \p Bases.
0098   void ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
0099       Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists,
0100       SmallVectorImpl<FunctionDecl *> &Bases);
0101 
0102   /// Register \p D as specialization of all base functions in \p Bases in the
0103   /// current `omp begin/end declare variant` scope.
0104   void ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope(
0105       Decl *D, SmallVectorImpl<FunctionDecl *> &Bases);
0106 
0107   /// Act on \p D, a function definition inside of an `omp [begin/end] assumes`.
0108   void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D);
0109 
0110   /// Can we exit an OpenMP declare variant scope at the moment.
0111   bool isInOpenMPDeclareVariantScope() const {
0112     return !OMPDeclareVariantScopes.empty();
0113   }
0114 
0115   ExprResult
0116   VerifyPositiveIntegerConstantInClause(Expr *Op, OpenMPClauseKind CKind,
0117                                         bool StrictlyPositive = true,
0118                                         bool SuppressExprDiags = false);
0119 
0120   /// Given the potential call expression \p Call, determine if there is a
0121   /// specialization via the OpenMP declare variant mechanism available. If
0122   /// there is, return the specialized call expression, otherwise return the
0123   /// original \p Call.
0124   ExprResult ActOnOpenMPCall(ExprResult Call, Scope *Scope,
0125                              SourceLocation LParenLoc, MultiExprArg ArgExprs,
0126                              SourceLocation RParenLoc, Expr *ExecConfig);
0127 
0128   /// Handle a `omp begin declare variant`.
0129   void ActOnOpenMPBeginDeclareVariant(SourceLocation Loc, OMPTraitInfo &TI);
0130 
0131   /// Handle a `omp end declare variant`.
0132   void ActOnOpenMPEndDeclareVariant();
0133 
0134   /// Function tries to capture lambda's captured variables in the OpenMP region
0135   /// before the original lambda is captured.
0136   void tryCaptureOpenMPLambdas(ValueDecl *V);
0137 
0138   /// Return true if the provided declaration \a VD should be captured by
0139   /// reference.
0140   /// \param Level Relative level of nested OpenMP construct for that the check
0141   /// is performed.
0142   /// \param OpenMPCaptureLevel Capture level within an OpenMP construct.
0143   bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level,
0144                              unsigned OpenMPCaptureLevel) const;
0145 
0146   /// Check if the specified variable is used in one of the private
0147   /// clauses (private, firstprivate, lastprivate, reduction etc.) in OpenMP
0148   /// constructs.
0149   VarDecl *isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo = false,
0150                                 unsigned StopAt = 0);
0151 
0152   /// The member expression(this->fd) needs to be rebuilt in the template
0153   /// instantiation to generate private copy for OpenMP when default
0154   /// clause is used. The function will return true if default
0155   /// cluse is used.
0156   bool isOpenMPRebuildMemberExpr(ValueDecl *D);
0157 
0158   ExprResult getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK,
0159                                    ExprObjectKind OK, SourceLocation Loc);
0160 
0161   /// If the current region is a loop-based region, mark the start of the loop
0162   /// construct.
0163   void startOpenMPLoop();
0164 
0165   /// If the current region is a range loop-based region, mark the start of the
0166   /// loop construct.
0167   void startOpenMPCXXRangeFor();
0168 
0169   /// Check if the specified variable is used in 'private' clause.
0170   /// \param Level Relative level of nested OpenMP construct for that the check
0171   /// is performed.
0172   OpenMPClauseKind isOpenMPPrivateDecl(ValueDecl *D, unsigned Level,
0173                                        unsigned CapLevel) const;
0174 
0175   /// Sets OpenMP capture kind (OMPC_private, OMPC_firstprivate, OMPC_map etc.)
0176   /// for \p FD based on DSA for the provided corresponding captured declaration
0177   /// \p D.
0178   void setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, unsigned Level);
0179 
0180   /// Check if the specified variable is captured  by 'target' directive.
0181   /// \param Level Relative level of nested OpenMP construct for that the check
0182   /// is performed.
0183   bool isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level,
0184                                   unsigned CaptureLevel) const;
0185 
0186   /// Check if the specified global variable must be captured  by outer capture
0187   /// regions.
0188   /// \param Level Relative level of nested OpenMP construct for that
0189   /// the check is performed.
0190   bool isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level,
0191                                   unsigned CaptureLevel) const;
0192 
0193   ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc,
0194                                                     Expr *Op);
0195   /// Called on start of new data sharing attribute block.
0196   void StartOpenMPDSABlock(OpenMPDirectiveKind K,
0197                            const DeclarationNameInfo &DirName, Scope *CurScope,
0198                            SourceLocation Loc);
0199   /// Start analysis of clauses.
0200   void StartOpenMPClause(OpenMPClauseKind K);
0201   /// End analysis of clauses.
0202   void EndOpenMPClause();
0203   /// Called on end of data sharing attribute block.
0204   void EndOpenMPDSABlock(Stmt *CurDirective);
0205 
0206   /// Check if the current region is an OpenMP loop region and if it is,
0207   /// mark loop control variable, used in \p Init for loop initialization, as
0208   /// private by default.
0209   /// \param Init First part of the for loop.
0210   void ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init);
0211 
0212   /// Called on well-formed '\#pragma omp metadirective' after parsing
0213   /// of the  associated statement.
0214   StmtResult ActOnOpenMPMetaDirective(ArrayRef<OMPClause *> Clauses,
0215                                       Stmt *AStmt, SourceLocation StartLoc,
0216                                       SourceLocation EndLoc);
0217 
0218   // OpenMP directives and clauses.
0219   /// Called on correct id-expression from the '#pragma omp
0220   /// threadprivate'.
0221   ExprResult ActOnOpenMPIdExpression(Scope *CurScope, CXXScopeSpec &ScopeSpec,
0222                                      const DeclarationNameInfo &Id,
0223                                      OpenMPDirectiveKind Kind);
0224   /// Called on well-formed '#pragma omp threadprivate'.
0225   DeclGroupPtrTy ActOnOpenMPThreadprivateDirective(SourceLocation Loc,
0226                                                    ArrayRef<Expr *> VarList);
0227   /// Builds a new OpenMPThreadPrivateDecl and checks its correctness.
0228   OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(SourceLocation Loc,
0229                                                   ArrayRef<Expr *> VarList);
0230   /// Called on well-formed '#pragma omp allocate'.
0231   DeclGroupPtrTy ActOnOpenMPAllocateDirective(SourceLocation Loc,
0232                                               ArrayRef<Expr *> VarList,
0233                                               ArrayRef<OMPClause *> Clauses,
0234                                               DeclContext *Owner = nullptr);
0235 
0236   /// Called on well-formed '#pragma omp [begin] assume[s]'.
0237   void ActOnOpenMPAssumesDirective(SourceLocation Loc,
0238                                    OpenMPDirectiveKind DKind,
0239                                    ArrayRef<std::string> Assumptions,
0240                                    bool SkippedClauses);
0241 
0242   /// Check if there is an active global `omp begin assumes` directive.
0243   bool isInOpenMPAssumeScope() const { return !OMPAssumeScoped.empty(); }
0244 
0245   /// Check if there is an active global `omp assumes` directive.
0246   bool hasGlobalOpenMPAssumes() const { return !OMPAssumeGlobal.empty(); }
0247 
0248   /// Called on well-formed '#pragma omp end assumes'.
0249   void ActOnOpenMPEndAssumesDirective();
0250 
0251   /// Called on well-formed '#pragma omp requires'.
0252   DeclGroupPtrTy ActOnOpenMPRequiresDirective(SourceLocation Loc,
0253                                               ArrayRef<OMPClause *> ClauseList);
0254   /// Check restrictions on Requires directive
0255   OMPRequiresDecl *CheckOMPRequiresDecl(SourceLocation Loc,
0256                                         ArrayRef<OMPClause *> Clauses);
0257   /// Check if the specified type is allowed to be used in 'omp declare
0258   /// reduction' construct.
0259   QualType ActOnOpenMPDeclareReductionType(SourceLocation TyLoc,
0260                                            TypeResult ParsedType);
0261   /// Called on start of '#pragma omp declare reduction'.
0262   DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveStart(
0263       Scope *S, DeclContext *DC, DeclarationName Name,
0264       ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes,
0265       AccessSpecifier AS, Decl *PrevDeclInScope = nullptr);
0266   /// Initialize declare reduction construct initializer.
0267   void ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D);
0268   /// Finish current declare reduction construct initializer.
0269   void ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner);
0270   /// Initialize declare reduction construct initializer.
0271   /// \return omp_priv variable.
0272   VarDecl *ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D);
0273   /// Finish current declare reduction construct initializer.
0274   void ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer,
0275                                                  VarDecl *OmpPrivParm);
0276   /// Called at the end of '#pragma omp declare reduction'.
0277   DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveEnd(
0278       Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid);
0279 
0280   /// Check variable declaration in 'omp declare mapper' construct.
0281   TypeResult ActOnOpenMPDeclareMapperVarDecl(Scope *S, Declarator &D);
0282   /// Check if the specified type is allowed to be used in 'omp declare
0283   /// mapper' construct.
0284   QualType ActOnOpenMPDeclareMapperType(SourceLocation TyLoc,
0285                                         TypeResult ParsedType);
0286   /// Called on start of '#pragma omp declare mapper'.
0287   DeclGroupPtrTy ActOnOpenMPDeclareMapperDirective(
0288       Scope *S, DeclContext *DC, DeclarationName Name, QualType MapperType,
0289       SourceLocation StartLoc, DeclarationName VN, AccessSpecifier AS,
0290       Expr *MapperVarRef, ArrayRef<OMPClause *> Clauses,
0291       Decl *PrevDeclInScope = nullptr);
0292   /// Build the mapper variable of '#pragma omp declare mapper'.
0293   ExprResult ActOnOpenMPDeclareMapperDirectiveVarDecl(Scope *S,
0294                                                       QualType MapperType,
0295                                                       SourceLocation StartLoc,
0296                                                       DeclarationName VN);
0297   void ActOnOpenMPIteratorVarDecl(VarDecl *VD);
0298   bool isOpenMPDeclareMapperVarDeclAllowed(const VarDecl *VD) const;
0299   const ValueDecl *getOpenMPDeclareMapperVarName() const;
0300 
0301   struct DeclareTargetContextInfo {
0302     struct MapInfo {
0303       OMPDeclareTargetDeclAttr::MapTypeTy MT;
0304       SourceLocation Loc;
0305     };
0306     /// Explicitly listed variables and functions in a 'to' or 'link' clause.
0307     llvm::DenseMap<NamedDecl *, MapInfo> ExplicitlyMapped;
0308 
0309     /// The 'device_type' as parsed from the clause.
0310     OMPDeclareTargetDeclAttr::DevTypeTy DT = OMPDeclareTargetDeclAttr::DT_Any;
0311 
0312     /// The directive kind, `begin declare target` or `declare target`.
0313     OpenMPDirectiveKind Kind;
0314 
0315     /// The directive with indirect clause.
0316     std::optional<Expr *> Indirect;
0317 
0318     /// The directive location.
0319     SourceLocation Loc;
0320 
0321     DeclareTargetContextInfo(OpenMPDirectiveKind Kind, SourceLocation Loc)
0322         : Kind(Kind), Loc(Loc) {}
0323   };
0324 
0325   /// Called on the start of target region i.e. '#pragma omp declare target'.
0326   bool ActOnStartOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI);
0327 
0328   /// Called at the end of target region i.e. '#pragma omp end declare target'.
0329   const DeclareTargetContextInfo ActOnOpenMPEndDeclareTargetDirective();
0330 
0331   /// Called once a target context is completed, that can be when a
0332   /// '#pragma omp end declare target' was encountered or when a
0333   /// '#pragma omp declare target' without declaration-definition-seq was
0334   /// encountered.
0335   void ActOnFinishedOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI);
0336 
0337   /// Report unterminated 'omp declare target' or 'omp begin declare target' at
0338   /// the end of a compilation unit.
0339   void DiagnoseUnterminatedOpenMPDeclareTarget();
0340 
0341   /// Searches for the provided declaration name for OpenMP declare target
0342   /// directive.
0343   NamedDecl *lookupOpenMPDeclareTargetName(Scope *CurScope,
0344                                            CXXScopeSpec &ScopeSpec,
0345                                            const DeclarationNameInfo &Id);
0346 
0347   /// Called on correct id-expression from the '#pragma omp declare target'.
0348   void ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc,
0349                                     OMPDeclareTargetDeclAttr::MapTypeTy MT,
0350                                     DeclareTargetContextInfo &DTCI);
0351 
0352   /// Check declaration inside target region.
0353   void
0354   checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D,
0355                                    SourceLocation IdLoc = SourceLocation());
0356 
0357   /// Adds OMPDeclareTargetDeclAttr to referenced variables in declare target
0358   /// directive.
0359   void ActOnOpenMPDeclareTargetInitializer(Decl *D);
0360 
0361   /// Finishes analysis of the deferred functions calls that may be declared as
0362   /// host/nohost during device/host compilation.
0363   void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller,
0364                                      const FunctionDecl *Callee,
0365                                      SourceLocation Loc);
0366 
0367   /// Return true if currently in OpenMP task with untied clause context.
0368   bool isInOpenMPTaskUntiedContext() const;
0369 
0370   /// Return true inside OpenMP declare target region.
0371   bool isInOpenMPDeclareTargetContext() const {
0372     return !DeclareTargetNesting.empty();
0373   }
0374   /// Return true inside OpenMP target region.
0375   bool isInOpenMPTargetExecutionDirective() const;
0376 
0377   /// Return the number of captured regions created for an OpenMP directive.
0378   static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind);
0379 
0380   /// Initialization of captured region for OpenMP region.
0381   void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope);
0382 
0383   /// Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to
0384   /// an OpenMP loop directive.
0385   StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt);
0386 
0387   /// Process a canonical OpenMP loop nest that can either be a canonical
0388   /// literal loop (ForStmt or CXXForRangeStmt), or the generated loop of an
0389   /// OpenMP loop transformation construct.
0390   StmtResult ActOnOpenMPLoopnest(Stmt *AStmt);
0391 
0392   /// End of OpenMP region.
0393   ///
0394   /// \param S Statement associated with the current OpenMP region.
0395   /// \param Clauses List of clauses for the current OpenMP region.
0396   ///
0397   /// \returns Statement for finished OpenMP region.
0398   StmtResult ActOnOpenMPRegionEnd(StmtResult S, ArrayRef<OMPClause *> Clauses);
0399   StmtResult ActOnOpenMPExecutableDirective(
0400       OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName,
0401       OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
0402       Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc);
0403   /// Process an OpenMP informational directive.
0404   ///
0405   /// \param Kind The directive kind.
0406   /// \param DirName Declaration name info.
0407   /// \param Clauses Array of clauses for directive.
0408   /// \param AStmt The associated statement.
0409   /// \param StartLoc The start location.
0410   /// \param EndLoc The end location.
0411   StmtResult ActOnOpenMPInformationalDirective(
0412       OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName,
0413       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0414       SourceLocation EndLoc);
0415   /// Process an OpenMP assume directive.
0416   ///
0417   /// \param Clauses Array of clauses for directive.
0418   /// \param AStmt The associated statement.
0419   /// \param StartLoc The start location.
0420   /// \param EndLoc The end location.
0421   StmtResult ActOnOpenMPAssumeDirective(ArrayRef<OMPClause *> Clauses,
0422                                         Stmt *AStmt, SourceLocation StartLoc,
0423                                         SourceLocation EndLoc);
0424 
0425   /// Called on well-formed '\#pragma omp parallel' after parsing
0426   /// of the  associated statement.
0427   StmtResult ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses,
0428                                           Stmt *AStmt, SourceLocation StartLoc,
0429                                           SourceLocation EndLoc);
0430   using VarsWithInheritedDSAType =
0431       llvm::SmallDenseMap<const ValueDecl *, const Expr *, 4>;
0432   /// Called on well-formed '\#pragma omp simd' after parsing
0433   /// of the associated statement.
0434   StmtResult
0435   ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
0436                            SourceLocation StartLoc, SourceLocation EndLoc,
0437                            VarsWithInheritedDSAType &VarsWithImplicitDSA);
0438   /// Called on well-formed '#pragma omp tile' after parsing of its clauses and
0439   /// the associated statement.
0440   StmtResult ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses,
0441                                       Stmt *AStmt, SourceLocation StartLoc,
0442                                       SourceLocation EndLoc);
0443   /// Called on well-formed '#pragma omp unroll' after parsing of its clauses
0444   /// and the associated statement.
0445   StmtResult ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses,
0446                                         Stmt *AStmt, SourceLocation StartLoc,
0447                                         SourceLocation EndLoc);
0448   /// Called on well-formed '#pragma omp reverse'.
0449   StmtResult ActOnOpenMPReverseDirective(Stmt *AStmt, SourceLocation StartLoc,
0450                                          SourceLocation EndLoc);
0451   /// Called on well-formed '#pragma omp interchange' after parsing of its
0452   /// clauses and the associated statement.
0453   StmtResult ActOnOpenMPInterchangeDirective(ArrayRef<OMPClause *> Clauses,
0454                                              Stmt *AStmt,
0455                                              SourceLocation StartLoc,
0456                                              SourceLocation EndLoc);
0457   /// Called on well-formed '\#pragma omp for' after parsing
0458   /// of the associated statement.
0459   StmtResult
0460   ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
0461                           SourceLocation StartLoc, SourceLocation EndLoc,
0462                           VarsWithInheritedDSAType &VarsWithImplicitDSA);
0463   /// Called on well-formed '\#pragma omp for simd' after parsing
0464   /// of the associated statement.
0465   StmtResult
0466   ActOnOpenMPForSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
0467                               SourceLocation StartLoc, SourceLocation EndLoc,
0468                               VarsWithInheritedDSAType &VarsWithImplicitDSA);
0469   /// Called on well-formed '\#pragma omp sections' after parsing
0470   /// of the associated statement.
0471   StmtResult ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
0472                                           Stmt *AStmt, SourceLocation StartLoc,
0473                                           SourceLocation EndLoc);
0474   /// Called on well-formed '\#pragma omp section' after parsing of the
0475   /// associated statement.
0476   StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc,
0477                                          SourceLocation EndLoc);
0478   /// Called on well-formed '\#pragma omp scope' after parsing of the
0479   /// associated statement.
0480   StmtResult ActOnOpenMPScopeDirective(ArrayRef<OMPClause *> Clauses,
0481                                        Stmt *AStmt, SourceLocation StartLoc,
0482                                        SourceLocation EndLoc);
0483   /// Called on well-formed '\#pragma omp single' after parsing of the
0484   /// associated statement.
0485   StmtResult ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses,
0486                                         Stmt *AStmt, SourceLocation StartLoc,
0487                                         SourceLocation EndLoc);
0488   /// Called on well-formed '\#pragma omp master' after parsing of the
0489   /// associated statement.
0490   StmtResult ActOnOpenMPMasterDirective(Stmt *AStmt, SourceLocation StartLoc,
0491                                         SourceLocation EndLoc);
0492   /// Called on well-formed '\#pragma omp critical' after parsing of the
0493   /// associated statement.
0494   StmtResult ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName,
0495                                           ArrayRef<OMPClause *> Clauses,
0496                                           Stmt *AStmt, SourceLocation StartLoc,
0497                                           SourceLocation EndLoc);
0498   /// Called on well-formed '\#pragma omp parallel for' after parsing
0499   /// of the  associated statement.
0500   StmtResult ActOnOpenMPParallelForDirective(
0501       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0502       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0503   /// Called on well-formed '\#pragma omp parallel for simd' after
0504   /// parsing of the  associated statement.
0505   StmtResult ActOnOpenMPParallelForSimdDirective(
0506       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0507       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0508   /// Called on well-formed '\#pragma omp parallel master' after
0509   /// parsing of the  associated statement.
0510   StmtResult ActOnOpenMPParallelMasterDirective(ArrayRef<OMPClause *> Clauses,
0511                                                 Stmt *AStmt,
0512                                                 SourceLocation StartLoc,
0513                                                 SourceLocation EndLoc);
0514   /// Called on well-formed '\#pragma omp parallel masked' after
0515   /// parsing of the associated statement.
0516   StmtResult ActOnOpenMPParallelMaskedDirective(ArrayRef<OMPClause *> Clauses,
0517                                                 Stmt *AStmt,
0518                                                 SourceLocation StartLoc,
0519                                                 SourceLocation EndLoc);
0520   /// Called on well-formed '\#pragma omp parallel sections' after
0521   /// parsing of the  associated statement.
0522   StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses,
0523                                                   Stmt *AStmt,
0524                                                   SourceLocation StartLoc,
0525                                                   SourceLocation EndLoc);
0526   /// Called on well-formed '\#pragma omp task' after parsing of the
0527   /// associated statement.
0528   StmtResult ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses,
0529                                       Stmt *AStmt, SourceLocation StartLoc,
0530                                       SourceLocation EndLoc);
0531   /// Called on well-formed '\#pragma omp taskyield'.
0532   StmtResult ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc,
0533                                            SourceLocation EndLoc);
0534   /// Called on well-formed '\#pragma omp error'.
0535   /// Error direcitive is allowed in both declared and excutable contexts.
0536   /// Adding InExContext to identify which context is called from.
0537   StmtResult ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses,
0538                                        SourceLocation StartLoc,
0539                                        SourceLocation EndLoc,
0540                                        bool InExContext = true);
0541   /// Called on well-formed '\#pragma omp barrier'.
0542   StmtResult ActOnOpenMPBarrierDirective(SourceLocation StartLoc,
0543                                          SourceLocation EndLoc);
0544   /// Called on well-formed '\#pragma omp taskwait'.
0545   StmtResult ActOnOpenMPTaskwaitDirective(ArrayRef<OMPClause *> Clauses,
0546                                           SourceLocation StartLoc,
0547                                           SourceLocation EndLoc);
0548   /// Called on well-formed '\#pragma omp taskgroup'.
0549   StmtResult ActOnOpenMPTaskgroupDirective(ArrayRef<OMPClause *> Clauses,
0550                                            Stmt *AStmt, SourceLocation StartLoc,
0551                                            SourceLocation EndLoc);
0552   /// Called on well-formed '\#pragma omp flush'.
0553   StmtResult ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses,
0554                                        SourceLocation StartLoc,
0555                                        SourceLocation EndLoc);
0556   /// Called on well-formed '\#pragma omp depobj'.
0557   StmtResult ActOnOpenMPDepobjDirective(ArrayRef<OMPClause *> Clauses,
0558                                         SourceLocation StartLoc,
0559                                         SourceLocation EndLoc);
0560   /// Called on well-formed '\#pragma omp scan'.
0561   StmtResult ActOnOpenMPScanDirective(ArrayRef<OMPClause *> Clauses,
0562                                       SourceLocation StartLoc,
0563                                       SourceLocation EndLoc);
0564   /// Called on well-formed '\#pragma omp ordered' after parsing of the
0565   /// associated statement.
0566   StmtResult ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses,
0567                                          Stmt *AStmt, SourceLocation StartLoc,
0568                                          SourceLocation EndLoc);
0569   /// Called on well-formed '\#pragma omp atomic' after parsing of the
0570   /// associated statement.
0571   StmtResult ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses,
0572                                         Stmt *AStmt, SourceLocation StartLoc,
0573                                         SourceLocation EndLoc);
0574   /// Called on well-formed '\#pragma omp target' after parsing of the
0575   /// associated statement.
0576   StmtResult ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses,
0577                                         Stmt *AStmt, SourceLocation StartLoc,
0578                                         SourceLocation EndLoc);
0579   /// Called on well-formed '\#pragma omp target data' after parsing of
0580   /// the associated statement.
0581   StmtResult ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses,
0582                                             Stmt *AStmt,
0583                                             SourceLocation StartLoc,
0584                                             SourceLocation EndLoc);
0585   /// Called on well-formed '\#pragma omp target enter data' after
0586   /// parsing of the associated statement.
0587   StmtResult ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses,
0588                                                  SourceLocation StartLoc,
0589                                                  SourceLocation EndLoc,
0590                                                  Stmt *AStmt);
0591   /// Called on well-formed '\#pragma omp target exit data' after
0592   /// parsing of the associated statement.
0593   StmtResult ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses,
0594                                                 SourceLocation StartLoc,
0595                                                 SourceLocation EndLoc,
0596                                                 Stmt *AStmt);
0597   /// Called on well-formed '\#pragma omp target parallel' after
0598   /// parsing of the associated statement.
0599   StmtResult ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses,
0600                                                 Stmt *AStmt,
0601                                                 SourceLocation StartLoc,
0602                                                 SourceLocation EndLoc);
0603   /// Called on well-formed '\#pragma omp target parallel for' after
0604   /// parsing of the  associated statement.
0605   StmtResult ActOnOpenMPTargetParallelForDirective(
0606       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0607       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0608   /// Called on well-formed '\#pragma omp teams' after parsing of the
0609   /// associated statement.
0610   StmtResult ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses,
0611                                        Stmt *AStmt, SourceLocation StartLoc,
0612                                        SourceLocation EndLoc);
0613   /// Called on well-formed '\#pragma omp teams loop' after parsing of the
0614   /// associated statement.
0615   StmtResult ActOnOpenMPTeamsGenericLoopDirective(
0616       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0617       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0618   /// Called on well-formed '\#pragma omp target teams loop' after parsing of
0619   /// the associated statement.
0620   StmtResult ActOnOpenMPTargetTeamsGenericLoopDirective(
0621       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0622       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0623   /// Called on well-formed '\#pragma omp parallel loop' after parsing of the
0624   /// associated statement.
0625   StmtResult ActOnOpenMPParallelGenericLoopDirective(
0626       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0627       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0628   /// Called on well-formed '\#pragma omp target parallel loop' after parsing
0629   /// of the associated statement.
0630   StmtResult ActOnOpenMPTargetParallelGenericLoopDirective(
0631       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0632       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0633   /// Called on well-formed '\#pragma omp cancellation point'.
0634   StmtResult
0635   ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc,
0636                                         SourceLocation EndLoc,
0637                                         OpenMPDirectiveKind CancelRegion);
0638   /// Called on well-formed '\#pragma omp cancel'.
0639   StmtResult ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses,
0640                                         SourceLocation StartLoc,
0641                                         SourceLocation EndLoc,
0642                                         OpenMPDirectiveKind CancelRegion);
0643   /// Called on well-formed '\#pragma omp taskloop' after parsing of the
0644   /// associated statement.
0645   StmtResult
0646   ActOnOpenMPTaskLoopDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
0647                                SourceLocation StartLoc, SourceLocation EndLoc,
0648                                VarsWithInheritedDSAType &VarsWithImplicitDSA);
0649   /// Called on well-formed '\#pragma omp taskloop simd' after parsing of
0650   /// the associated statement.
0651   StmtResult ActOnOpenMPTaskLoopSimdDirective(
0652       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0653       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0654   /// Called on well-formed '\#pragma omp master taskloop' after parsing of the
0655   /// associated statement.
0656   StmtResult ActOnOpenMPMasterTaskLoopDirective(
0657       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0658       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0659   /// Called on well-formed '\#pragma omp master taskloop simd' after parsing of
0660   /// the associated statement.
0661   StmtResult ActOnOpenMPMasterTaskLoopSimdDirective(
0662       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0663       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0664   /// Called on well-formed '\#pragma omp parallel master taskloop' after
0665   /// parsing of the associated statement.
0666   StmtResult ActOnOpenMPParallelMasterTaskLoopDirective(
0667       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0668       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0669   /// Called on well-formed '\#pragma omp parallel master taskloop simd' after
0670   /// parsing of the associated statement.
0671   StmtResult ActOnOpenMPParallelMasterTaskLoopSimdDirective(
0672       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0673       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0674   /// Called on well-formed '\#pragma omp masked taskloop' after parsing of the
0675   /// associated statement.
0676   StmtResult ActOnOpenMPMaskedTaskLoopDirective(
0677       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0678       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0679   /// Called on well-formed '\#pragma omp masked taskloop simd' after parsing of
0680   /// the associated statement.
0681   StmtResult ActOnOpenMPMaskedTaskLoopSimdDirective(
0682       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0683       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0684   /// Called on well-formed '\#pragma omp parallel masked taskloop' after
0685   /// parsing of the associated statement.
0686   StmtResult ActOnOpenMPParallelMaskedTaskLoopDirective(
0687       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0688       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0689   /// Called on well-formed '\#pragma omp parallel masked taskloop simd' after
0690   /// parsing of the associated statement.
0691   StmtResult ActOnOpenMPParallelMaskedTaskLoopSimdDirective(
0692       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0693       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0694   /// Called on well-formed '\#pragma omp distribute' after parsing
0695   /// of the associated statement.
0696   StmtResult
0697   ActOnOpenMPDistributeDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
0698                                  SourceLocation StartLoc, SourceLocation EndLoc,
0699                                  VarsWithInheritedDSAType &VarsWithImplicitDSA);
0700   /// Called on well-formed '\#pragma omp target update'.
0701   StmtResult ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses,
0702                                               SourceLocation StartLoc,
0703                                               SourceLocation EndLoc,
0704                                               Stmt *AStmt);
0705   /// Called on well-formed '\#pragma omp distribute parallel for' after
0706   /// parsing of the associated statement.
0707   StmtResult ActOnOpenMPDistributeParallelForDirective(
0708       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0709       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0710   /// Called on well-formed '\#pragma omp distribute parallel for simd'
0711   /// after parsing of the associated statement.
0712   StmtResult ActOnOpenMPDistributeParallelForSimdDirective(
0713       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0714       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0715   /// Called on well-formed '\#pragma omp distribute simd' after
0716   /// parsing of the associated statement.
0717   StmtResult ActOnOpenMPDistributeSimdDirective(
0718       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0719       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0720   /// Called on well-formed '\#pragma omp target parallel for simd' after
0721   /// parsing of the associated statement.
0722   StmtResult ActOnOpenMPTargetParallelForSimdDirective(
0723       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0724       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0725   /// Called on well-formed '\#pragma omp target simd' after parsing of
0726   /// the associated statement.
0727   StmtResult
0728   ActOnOpenMPTargetSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
0729                                  SourceLocation StartLoc, SourceLocation EndLoc,
0730                                  VarsWithInheritedDSAType &VarsWithImplicitDSA);
0731   /// Called on well-formed '\#pragma omp teams distribute' after parsing of
0732   /// the associated statement.
0733   StmtResult ActOnOpenMPTeamsDistributeDirective(
0734       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0735       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0736   /// Called on well-formed '\#pragma omp teams distribute simd' after parsing
0737   /// of the associated statement.
0738   StmtResult ActOnOpenMPTeamsDistributeSimdDirective(
0739       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0740       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0741   /// Called on well-formed '\#pragma omp teams distribute parallel for simd'
0742   /// after parsing of the associated statement.
0743   StmtResult ActOnOpenMPTeamsDistributeParallelForSimdDirective(
0744       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0745       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0746   /// Called on well-formed '\#pragma omp teams distribute parallel for'
0747   /// after parsing of the associated statement.
0748   StmtResult ActOnOpenMPTeamsDistributeParallelForDirective(
0749       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0750       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0751   /// Called on well-formed '\#pragma omp target teams' after parsing of the
0752   /// associated statement.
0753   StmtResult ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses,
0754                                              Stmt *AStmt,
0755                                              SourceLocation StartLoc,
0756                                              SourceLocation EndLoc);
0757   /// Called on well-formed '\#pragma omp target teams distribute' after parsing
0758   /// of the associated statement.
0759   StmtResult ActOnOpenMPTargetTeamsDistributeDirective(
0760       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0761       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0762   /// Called on well-formed '\#pragma omp target teams distribute parallel for'
0763   /// after parsing of the associated statement.
0764   StmtResult ActOnOpenMPTargetTeamsDistributeParallelForDirective(
0765       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0766       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0767   /// Called on well-formed '\#pragma omp target teams distribute parallel for
0768   /// simd' after parsing of the associated statement.
0769   StmtResult ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective(
0770       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0771       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0772   /// Called on well-formed '\#pragma omp target teams distribute simd' after
0773   /// parsing of the associated statement.
0774   StmtResult ActOnOpenMPTargetTeamsDistributeSimdDirective(
0775       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0776       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0777   /// Called on well-formed '\#pragma omp interop'.
0778   StmtResult ActOnOpenMPInteropDirective(ArrayRef<OMPClause *> Clauses,
0779                                          SourceLocation StartLoc,
0780                                          SourceLocation EndLoc);
0781   /// Called on well-formed '\#pragma omp dispatch' after parsing of the
0782   // /associated statement.
0783   StmtResult ActOnOpenMPDispatchDirective(ArrayRef<OMPClause *> Clauses,
0784                                           Stmt *AStmt, SourceLocation StartLoc,
0785                                           SourceLocation EndLoc);
0786   /// Called on well-formed '\#pragma omp masked' after parsing of the
0787   // /associated statement.
0788   StmtResult ActOnOpenMPMaskedDirective(ArrayRef<OMPClause *> Clauses,
0789                                         Stmt *AStmt, SourceLocation StartLoc,
0790                                         SourceLocation EndLoc);
0791 
0792   /// Called on well-formed '\#pragma omp loop' after parsing of the
0793   /// associated statement.
0794   StmtResult ActOnOpenMPGenericLoopDirective(
0795       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
0796       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
0797 
0798   /// Checks correctness of linear modifiers.
0799   bool CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind,
0800                                  SourceLocation LinLoc);
0801   /// Checks that the specified declaration matches requirements for the linear
0802   /// decls.
0803   bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
0804                              OpenMPLinearClauseKind LinKind, QualType Type,
0805                              bool IsDeclareSimd = false);
0806 
0807   /// Called on well-formed '\#pragma omp declare simd' after parsing of
0808   /// the associated method/function.
0809   DeclGroupPtrTy ActOnOpenMPDeclareSimdDirective(
0810       DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS,
0811       Expr *Simdlen, ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds,
0812       ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears,
0813       ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR);
0814 
0815   /// Checks '\#pragma omp declare variant' variant function and original
0816   /// functions after parsing of the associated method/function.
0817   /// \param DG Function declaration to which declare variant directive is
0818   /// applied to.
0819   /// \param VariantRef Expression that references the variant function, which
0820   /// must be used instead of the original one, specified in \p DG.
0821   /// \param TI The trait info object representing the match clause.
0822   /// \param NumAppendArgs The number of omp_interop_t arguments to account for
0823   /// in checking.
0824   /// \returns std::nullopt, if the function/variant function are not compatible
0825   /// with the pragma, pair of original function/variant ref expression
0826   /// otherwise.
0827   std::optional<std::pair<FunctionDecl *, Expr *>>
0828   checkOpenMPDeclareVariantFunction(DeclGroupPtrTy DG, Expr *VariantRef,
0829                                     OMPTraitInfo &TI, unsigned NumAppendArgs,
0830                                     SourceRange SR);
0831 
0832   /// Called on well-formed '\#pragma omp declare variant' after parsing of
0833   /// the associated method/function.
0834   /// \param FD Function declaration to which declare variant directive is
0835   /// applied to.
0836   /// \param VariantRef Expression that references the variant function, which
0837   /// must be used instead of the original one, specified in \p DG.
0838   /// \param TI The context traits associated with the function variant.
0839   /// \param AdjustArgsNothing The list of 'nothing' arguments.
0840   /// \param AdjustArgsNeedDevicePtr The list of 'need_device_ptr' arguments.
0841   /// \param AppendArgs The list of 'append_args' arguments.
0842   /// \param AdjustArgsLoc The Location of an 'adjust_args' clause.
0843   /// \param AppendArgsLoc The Location of an 'append_args' clause.
0844   /// \param SR The SourceRange of the 'declare variant' directive.
0845   void ActOnOpenMPDeclareVariantDirective(
0846       FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI,
0847       ArrayRef<Expr *> AdjustArgsNothing,
0848       ArrayRef<Expr *> AdjustArgsNeedDevicePtr,
0849       ArrayRef<OMPInteropInfo> AppendArgs, SourceLocation AdjustArgsLoc,
0850       SourceLocation AppendArgsLoc, SourceRange SR);
0851 
0852   OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
0853                                          SourceLocation StartLoc,
0854                                          SourceLocation LParenLoc,
0855                                          SourceLocation EndLoc);
0856   /// Called on well-formed 'allocator' clause.
0857   OMPClause *ActOnOpenMPAllocatorClause(Expr *Allocator,
0858                                         SourceLocation StartLoc,
0859                                         SourceLocation LParenLoc,
0860                                         SourceLocation EndLoc);
0861   /// Called on well-formed 'if' clause.
0862   OMPClause *ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier,
0863                                  Expr *Condition, SourceLocation StartLoc,
0864                                  SourceLocation LParenLoc,
0865                                  SourceLocation NameModifierLoc,
0866                                  SourceLocation ColonLoc,
0867                                  SourceLocation EndLoc);
0868   /// Called on well-formed 'final' clause.
0869   OMPClause *ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc,
0870                                     SourceLocation LParenLoc,
0871                                     SourceLocation EndLoc);
0872   /// Called on well-formed 'num_threads' clause.
0873   OMPClause *ActOnOpenMPNumThreadsClause(Expr *NumThreads,
0874                                          SourceLocation StartLoc,
0875                                          SourceLocation LParenLoc,
0876                                          SourceLocation EndLoc);
0877   /// Called on well-formed 'align' clause.
0878   OMPClause *ActOnOpenMPAlignClause(Expr *Alignment, SourceLocation StartLoc,
0879                                     SourceLocation LParenLoc,
0880                                     SourceLocation EndLoc);
0881   /// Called on well-formed 'safelen' clause.
0882   OMPClause *ActOnOpenMPSafelenClause(Expr *Length, SourceLocation StartLoc,
0883                                       SourceLocation LParenLoc,
0884                                       SourceLocation EndLoc);
0885   /// Called on well-formed 'simdlen' clause.
0886   OMPClause *ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc,
0887                                       SourceLocation LParenLoc,
0888                                       SourceLocation EndLoc);
0889   /// Called on well-form 'sizes' clause.
0890   OMPClause *ActOnOpenMPSizesClause(ArrayRef<Expr *> SizeExprs,
0891                                     SourceLocation StartLoc,
0892                                     SourceLocation LParenLoc,
0893                                     SourceLocation EndLoc);
0894   /// Called on well-form 'permutation' clause after parsing its arguments.
0895   OMPClause *ActOnOpenMPPermutationClause(ArrayRef<Expr *> PermExprs,
0896                                           SourceLocation StartLoc,
0897                                           SourceLocation LParenLoc,
0898                                           SourceLocation EndLoc);
0899   /// Called on well-form 'full' clauses.
0900   OMPClause *ActOnOpenMPFullClause(SourceLocation StartLoc,
0901                                    SourceLocation EndLoc);
0902   /// Called on well-form 'partial' clauses.
0903   OMPClause *ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc,
0904                                       SourceLocation LParenLoc,
0905                                       SourceLocation EndLoc);
0906   /// Called on well-formed 'collapse' clause.
0907   OMPClause *ActOnOpenMPCollapseClause(Expr *NumForLoops,
0908                                        SourceLocation StartLoc,
0909                                        SourceLocation LParenLoc,
0910                                        SourceLocation EndLoc);
0911   /// Called on well-formed 'ordered' clause.
0912   OMPClause *
0913   ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc,
0914                            SourceLocation LParenLoc = SourceLocation(),
0915                            Expr *NumForLoops = nullptr);
0916   /// Called on well-formed 'grainsize' clause.
0917   OMPClause *ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier,
0918                                         Expr *Size, SourceLocation StartLoc,
0919                                         SourceLocation LParenLoc,
0920                                         SourceLocation ModifierLoc,
0921                                         SourceLocation EndLoc);
0922   /// Called on well-formed 'num_tasks' clause.
0923   OMPClause *ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier,
0924                                        Expr *NumTasks, SourceLocation StartLoc,
0925                                        SourceLocation LParenLoc,
0926                                        SourceLocation ModifierLoc,
0927                                        SourceLocation EndLoc);
0928   /// Called on well-formed 'hint' clause.
0929   OMPClause *ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc,
0930                                    SourceLocation LParenLoc,
0931                                    SourceLocation EndLoc);
0932   /// Called on well-formed 'detach' clause.
0933   OMPClause *ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc,
0934                                      SourceLocation LParenLoc,
0935                                      SourceLocation EndLoc);
0936 
0937   OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, unsigned Argument,
0938                                      SourceLocation ArgumentLoc,
0939                                      SourceLocation StartLoc,
0940                                      SourceLocation LParenLoc,
0941                                      SourceLocation EndLoc);
0942   /// Called on well-formed 'when' clause.
0943   OMPClause *ActOnOpenMPWhenClause(OMPTraitInfo &TI, SourceLocation StartLoc,
0944                                    SourceLocation LParenLoc,
0945                                    SourceLocation EndLoc);
0946   /// Called on well-formed 'default' clause.
0947   OMPClause *ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind,
0948                                       SourceLocation KindLoc,
0949                                       SourceLocation StartLoc,
0950                                       SourceLocation LParenLoc,
0951                                       SourceLocation EndLoc);
0952   /// Called on well-formed 'proc_bind' clause.
0953   OMPClause *ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind,
0954                                        SourceLocation KindLoc,
0955                                        SourceLocation StartLoc,
0956                                        SourceLocation LParenLoc,
0957                                        SourceLocation EndLoc);
0958   /// Called on well-formed 'order' clause.
0959   OMPClause *ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier,
0960                                     OpenMPOrderClauseKind Kind,
0961                                     SourceLocation StartLoc,
0962                                     SourceLocation LParenLoc,
0963                                     SourceLocation MLoc, SourceLocation KindLoc,
0964                                     SourceLocation EndLoc);
0965   /// Called on well-formed 'update' clause.
0966   OMPClause *ActOnOpenMPUpdateClause(OpenMPDependClauseKind Kind,
0967                                      SourceLocation KindLoc,
0968                                      SourceLocation StartLoc,
0969                                      SourceLocation LParenLoc,
0970                                      SourceLocation EndLoc);
0971   /// Called on well-formed 'holds' clause.
0972   OMPClause *ActOnOpenMPHoldsClause(Expr *E, SourceLocation StartLoc,
0973                                     SourceLocation LParenLoc,
0974                                     SourceLocation EndLoc);
0975   /// Called on well-formed 'absent' or 'contains' clauses.
0976   OMPClause *ActOnOpenMPDirectivePresenceClause(
0977       OpenMPClauseKind CK, llvm::ArrayRef<OpenMPDirectiveKind> DKVec,
0978       SourceLocation Loc, SourceLocation LLoc, SourceLocation RLoc);
0979   OMPClause *ActOnOpenMPNullaryAssumptionClause(OpenMPClauseKind CK,
0980                                                 SourceLocation Loc,
0981                                                 SourceLocation RLoc);
0982 
0983   OMPClause *ActOnOpenMPSingleExprWithArgClause(
0984       OpenMPClauseKind Kind, ArrayRef<unsigned> Arguments, Expr *Expr,
0985       SourceLocation StartLoc, SourceLocation LParenLoc,
0986       ArrayRef<SourceLocation> ArgumentsLoc, SourceLocation DelimLoc,
0987       SourceLocation EndLoc);
0988   /// Called on well-formed 'schedule' clause.
0989   OMPClause *ActOnOpenMPScheduleClause(
0990       OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
0991       OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
0992       SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
0993       SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc);
0994 
0995   OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc,
0996                                SourceLocation EndLoc);
0997   /// Called on well-formed 'nowait' clause.
0998   OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc,
0999                                      SourceLocation EndLoc);
1000   /// Called on well-formed 'untied' clause.
1001   OMPClause *ActOnOpenMPUntiedClause(SourceLocation StartLoc,
1002                                      SourceLocation EndLoc);
1003   /// Called on well-formed 'mergeable' clause.
1004   OMPClause *ActOnOpenMPMergeableClause(SourceLocation StartLoc,
1005                                         SourceLocation EndLoc);
1006   /// Called on well-formed 'read' clause.
1007   OMPClause *ActOnOpenMPReadClause(SourceLocation StartLoc,
1008                                    SourceLocation EndLoc);
1009   /// Called on well-formed 'write' clause.
1010   OMPClause *ActOnOpenMPWriteClause(SourceLocation StartLoc,
1011                                     SourceLocation EndLoc);
1012   /// Called on well-formed 'update' clause.
1013   OMPClause *ActOnOpenMPUpdateClause(SourceLocation StartLoc,
1014                                      SourceLocation EndLoc);
1015   /// Called on well-formed 'capture' clause.
1016   OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc,
1017                                       SourceLocation EndLoc);
1018   /// Called on well-formed 'compare' clause.
1019   OMPClause *ActOnOpenMPCompareClause(SourceLocation StartLoc,
1020                                       SourceLocation EndLoc);
1021   /// Called on well-formed 'fail' clause.
1022   OMPClause *ActOnOpenMPFailClause(SourceLocation StartLoc,
1023                                    SourceLocation EndLoc);
1024   OMPClause *ActOnOpenMPFailClause(OpenMPClauseKind Kind,
1025                                    SourceLocation KindLoc,
1026                                    SourceLocation StartLoc,
1027                                    SourceLocation LParenLoc,
1028                                    SourceLocation EndLoc);
1029 
1030   /// Called on well-formed 'seq_cst' clause.
1031   OMPClause *ActOnOpenMPSeqCstClause(SourceLocation StartLoc,
1032                                      SourceLocation EndLoc);
1033   /// Called on well-formed 'acq_rel' clause.
1034   OMPClause *ActOnOpenMPAcqRelClause(SourceLocation StartLoc,
1035                                      SourceLocation EndLoc);
1036   /// Called on well-formed 'acquire' clause.
1037   OMPClause *ActOnOpenMPAcquireClause(SourceLocation StartLoc,
1038                                       SourceLocation EndLoc);
1039   /// Called on well-formed 'release' clause.
1040   OMPClause *ActOnOpenMPReleaseClause(SourceLocation StartLoc,
1041                                       SourceLocation EndLoc);
1042   /// Called on well-formed 'relaxed' clause.
1043   OMPClause *ActOnOpenMPRelaxedClause(SourceLocation StartLoc,
1044                                       SourceLocation EndLoc);
1045   /// Called on well-formed 'weak' clause.
1046   OMPClause *ActOnOpenMPWeakClause(SourceLocation StartLoc,
1047                                    SourceLocation EndLoc);
1048 
1049   /// Called on well-formed 'init' clause.
1050   OMPClause *
1051   ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo,
1052                         SourceLocation StartLoc, SourceLocation LParenLoc,
1053                         SourceLocation VarLoc, SourceLocation EndLoc);
1054 
1055   /// Called on well-formed 'use' clause.
1056   OMPClause *ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc,
1057                                   SourceLocation LParenLoc,
1058                                   SourceLocation VarLoc, SourceLocation EndLoc);
1059 
1060   /// Called on well-formed 'destroy' clause.
1061   OMPClause *ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc,
1062                                       SourceLocation LParenLoc,
1063                                       SourceLocation VarLoc,
1064                                       SourceLocation EndLoc);
1065   /// Called on well-formed 'novariants' clause.
1066   OMPClause *ActOnOpenMPNovariantsClause(Expr *Condition,
1067                                          SourceLocation StartLoc,
1068                                          SourceLocation LParenLoc,
1069                                          SourceLocation EndLoc);
1070   /// Called on well-formed 'nocontext' clause.
1071   OMPClause *ActOnOpenMPNocontextClause(Expr *Condition,
1072                                         SourceLocation StartLoc,
1073                                         SourceLocation LParenLoc,
1074                                         SourceLocation EndLoc);
1075   /// Called on well-formed 'filter' clause.
1076   OMPClause *ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc,
1077                                      SourceLocation LParenLoc,
1078                                      SourceLocation EndLoc);
1079   /// Called on well-formed 'threads' clause.
1080   OMPClause *ActOnOpenMPThreadsClause(SourceLocation StartLoc,
1081                                       SourceLocation EndLoc);
1082   /// Called on well-formed 'simd' clause.
1083   OMPClause *ActOnOpenMPSIMDClause(SourceLocation StartLoc,
1084                                    SourceLocation EndLoc);
1085   /// Called on well-formed 'nogroup' clause.
1086   OMPClause *ActOnOpenMPNogroupClause(SourceLocation StartLoc,
1087                                       SourceLocation EndLoc);
1088   /// Called on well-formed 'unified_address' clause.
1089   OMPClause *ActOnOpenMPUnifiedAddressClause(SourceLocation StartLoc,
1090                                              SourceLocation EndLoc);
1091 
1092   /// Called on well-formed 'unified_address' clause.
1093   OMPClause *ActOnOpenMPUnifiedSharedMemoryClause(SourceLocation StartLoc,
1094                                                   SourceLocation EndLoc);
1095 
1096   /// Called on well-formed 'reverse_offload' clause.
1097   OMPClause *ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc,
1098                                              SourceLocation EndLoc);
1099 
1100   /// Called on well-formed 'dynamic_allocators' clause.
1101   OMPClause *ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc,
1102                                                 SourceLocation EndLoc);
1103 
1104   /// Called on well-formed 'atomic_default_mem_order' clause.
1105   OMPClause *ActOnOpenMPAtomicDefaultMemOrderClause(
1106       OpenMPAtomicDefaultMemOrderClauseKind Kind, SourceLocation KindLoc,
1107       SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc);
1108 
1109   /// Called on well-formed 'at' clause.
1110   OMPClause *ActOnOpenMPAtClause(OpenMPAtClauseKind Kind,
1111                                  SourceLocation KindLoc,
1112                                  SourceLocation StartLoc,
1113                                  SourceLocation LParenLoc,
1114                                  SourceLocation EndLoc);
1115 
1116   /// Called on well-formed 'severity' clause.
1117   OMPClause *ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind,
1118                                        SourceLocation KindLoc,
1119                                        SourceLocation StartLoc,
1120                                        SourceLocation LParenLoc,
1121                                        SourceLocation EndLoc);
1122 
1123   /// Called on well-formed 'message' clause.
1124   /// passing string for message.
1125   OMPClause *ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc,
1126                                       SourceLocation LParenLoc,
1127                                       SourceLocation EndLoc);
1128 
1129   /// Data used for processing a list of variables in OpenMP clauses.
1130   struct OpenMPVarListDataTy final {
1131     Expr *DepModOrTailExpr = nullptr;
1132     Expr *IteratorExpr = nullptr;
1133     SourceLocation ColonLoc;
1134     SourceLocation RLoc;
1135     CXXScopeSpec ReductionOrMapperIdScopeSpec;
1136     DeclarationNameInfo ReductionOrMapperId;
1137     int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or
1138                             ///< lastprivate clause.
1139     SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
1140         MapTypeModifiers;
1141     SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers>
1142         MapTypeModifiersLoc;
1143     SmallVector<OpenMPMotionModifierKind, NumberOfOMPMotionModifiers>
1144         MotionModifiers;
1145     SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc;
1146     bool IsMapTypeImplicit = false;
1147     SourceLocation ExtraModifierLoc;
1148     SourceLocation OmpAllMemoryLoc;
1149     SourceLocation
1150         StepModifierLoc; /// 'step' modifier location for linear clause
1151     SmallVector<OpenMPAllocateClauseModifier,
1152                 NumberOfOMPAllocateClauseModifiers>
1153         AllocClauseModifiers;
1154     SmallVector<SourceLocation, NumberOfOMPAllocateClauseModifiers>
1155         AllocClauseModifiersLoc;
1156     Expr *AllocateAlignment = nullptr;
1157   };
1158 
1159   OMPClause *ActOnOpenMPVarListClause(OpenMPClauseKind Kind,
1160                                       ArrayRef<Expr *> Vars,
1161                                       const OMPVarListLocTy &Locs,
1162                                       OpenMPVarListDataTy &Data);
1163   /// Called on well-formed 'inclusive' clause.
1164   OMPClause *ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList,
1165                                         SourceLocation StartLoc,
1166                                         SourceLocation LParenLoc,
1167                                         SourceLocation EndLoc);
1168   /// Called on well-formed 'exclusive' clause.
1169   OMPClause *ActOnOpenMPExclusiveClause(ArrayRef<Expr *> VarList,
1170                                         SourceLocation StartLoc,
1171                                         SourceLocation LParenLoc,
1172                                         SourceLocation EndLoc);
1173   /// Called on well-formed 'allocate' clause.
1174   OMPClause *
1175   ActOnOpenMPAllocateClause(Expr *Allocator, Expr *Alignment,
1176                             OpenMPAllocateClauseModifier FirstModifier,
1177                             SourceLocation FirstModifierLoc,
1178                             OpenMPAllocateClauseModifier SecondModifier,
1179                             SourceLocation SecondModifierLoc,
1180                             ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1181                             SourceLocation ColonLoc, SourceLocation LParenLoc,
1182                             SourceLocation EndLoc);
1183   /// Called on well-formed 'private' clause.
1184   OMPClause *ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList,
1185                                       SourceLocation StartLoc,
1186                                       SourceLocation LParenLoc,
1187                                       SourceLocation EndLoc);
1188   /// Called on well-formed 'firstprivate' clause.
1189   OMPClause *ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList,
1190                                            SourceLocation StartLoc,
1191                                            SourceLocation LParenLoc,
1192                                            SourceLocation EndLoc);
1193   /// Called on well-formed 'lastprivate' clause.
1194   OMPClause *ActOnOpenMPLastprivateClause(
1195       ArrayRef<Expr *> VarList, OpenMPLastprivateModifier LPKind,
1196       SourceLocation LPKindLoc, SourceLocation ColonLoc,
1197       SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc);
1198   /// Called on well-formed 'shared' clause.
1199   OMPClause *ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList,
1200                                      SourceLocation StartLoc,
1201                                      SourceLocation LParenLoc,
1202                                      SourceLocation EndLoc);
1203   /// Called on well-formed 'reduction' clause.
1204   OMPClause *ActOnOpenMPReductionClause(
1205       ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier,
1206       SourceLocation StartLoc, SourceLocation LParenLoc,
1207       SourceLocation ModifierLoc, SourceLocation ColonLoc,
1208       SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1209       const DeclarationNameInfo &ReductionId,
1210       ArrayRef<Expr *> UnresolvedReductions = {});
1211   /// Called on well-formed 'task_reduction' clause.
1212   OMPClause *ActOnOpenMPTaskReductionClause(
1213       ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1214       SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1215       CXXScopeSpec &ReductionIdScopeSpec,
1216       const DeclarationNameInfo &ReductionId,
1217       ArrayRef<Expr *> UnresolvedReductions = {});
1218   /// Called on well-formed 'in_reduction' clause.
1219   OMPClause *ActOnOpenMPInReductionClause(
1220       ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1221       SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1222       CXXScopeSpec &ReductionIdScopeSpec,
1223       const DeclarationNameInfo &ReductionId,
1224       ArrayRef<Expr *> UnresolvedReductions = {});
1225   /// Called on well-formed 'linear' clause.
1226   OMPClause *ActOnOpenMPLinearClause(
1227       ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1228       SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind,
1229       SourceLocation LinLoc, SourceLocation ColonLoc,
1230       SourceLocation StepModifierLoc, SourceLocation EndLoc);
1231   /// Called on well-formed 'aligned' clause.
1232   OMPClause *ActOnOpenMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1233                                       SourceLocation StartLoc,
1234                                       SourceLocation LParenLoc,
1235                                       SourceLocation ColonLoc,
1236                                       SourceLocation EndLoc);
1237   /// Called on well-formed 'copyin' clause.
1238   OMPClause *ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList,
1239                                      SourceLocation StartLoc,
1240                                      SourceLocation LParenLoc,
1241                                      SourceLocation EndLoc);
1242   /// Called on well-formed 'copyprivate' clause.
1243   OMPClause *ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList,
1244                                           SourceLocation StartLoc,
1245                                           SourceLocation LParenLoc,
1246                                           SourceLocation EndLoc);
1247   /// Called on well-formed 'flush' pseudo clause.
1248   OMPClause *ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList,
1249                                     SourceLocation StartLoc,
1250                                     SourceLocation LParenLoc,
1251                                     SourceLocation EndLoc);
1252   /// Called on well-formed 'depobj' pseudo clause.
1253   OMPClause *ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc,
1254                                      SourceLocation LParenLoc,
1255                                      SourceLocation EndLoc);
1256   /// Called on well-formed 'depend' clause.
1257   OMPClause *ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data,
1258                                      Expr *DepModifier,
1259                                      ArrayRef<Expr *> VarList,
1260                                      SourceLocation StartLoc,
1261                                      SourceLocation LParenLoc,
1262                                      SourceLocation EndLoc);
1263   /// Called on well-formed 'device' clause.
1264   OMPClause *ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier,
1265                                      Expr *Device, SourceLocation StartLoc,
1266                                      SourceLocation LParenLoc,
1267                                      SourceLocation ModifierLoc,
1268                                      SourceLocation EndLoc);
1269   /// Called on well-formed 'map' clause.
1270   OMPClause *ActOnOpenMPMapClause(
1271       Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1272       ArrayRef<SourceLocation> MapTypeModifiersLoc,
1273       CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId,
1274       OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1275       SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1276       const OMPVarListLocTy &Locs, bool NoDiagnose = false,
1277       ArrayRef<Expr *> UnresolvedMappers = {});
1278   /// Called on well-formed 'num_teams' clause.
1279   OMPClause *ActOnOpenMPNumTeamsClause(ArrayRef<Expr *> VarList,
1280                                        SourceLocation StartLoc,
1281                                        SourceLocation LParenLoc,
1282                                        SourceLocation EndLoc);
1283   /// Called on well-formed 'thread_limit' clause.
1284   OMPClause *ActOnOpenMPThreadLimitClause(ArrayRef<Expr *> VarList,
1285                                           SourceLocation StartLoc,
1286                                           SourceLocation LParenLoc,
1287                                           SourceLocation EndLoc);
1288   /// Called on well-formed 'priority' clause.
1289   OMPClause *ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1290                                        SourceLocation LParenLoc,
1291                                        SourceLocation EndLoc);
1292   /// Called on well-formed 'dist_schedule' clause.
1293   OMPClause *ActOnOpenMPDistScheduleClause(
1294       OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
1295       SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc,
1296       SourceLocation CommaLoc, SourceLocation EndLoc);
1297   /// Called on well-formed 'defaultmap' clause.
1298   OMPClause *ActOnOpenMPDefaultmapClause(
1299       OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind,
1300       SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc,
1301       SourceLocation KindLoc, SourceLocation EndLoc);
1302   /// Called on well-formed 'to' clause.
1303   OMPClause *
1304   ActOnOpenMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
1305                       ArrayRef<SourceLocation> MotionModifiersLoc,
1306                       CXXScopeSpec &MapperIdScopeSpec,
1307                       DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
1308                       ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
1309                       ArrayRef<Expr *> UnresolvedMappers = {});
1310   /// Called on well-formed 'from' clause.
1311   OMPClause *
1312   ActOnOpenMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
1313                         ArrayRef<SourceLocation> MotionModifiersLoc,
1314                         CXXScopeSpec &MapperIdScopeSpec,
1315                         DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
1316                         ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
1317                         ArrayRef<Expr *> UnresolvedMappers = {});
1318   /// Called on well-formed 'use_device_ptr' clause.
1319   OMPClause *ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1320                                            const OMPVarListLocTy &Locs);
1321   /// Called on well-formed 'use_device_addr' clause.
1322   OMPClause *ActOnOpenMPUseDeviceAddrClause(ArrayRef<Expr *> VarList,
1323                                             const OMPVarListLocTy &Locs);
1324   /// Called on well-formed 'is_device_ptr' clause.
1325   OMPClause *ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1326                                           const OMPVarListLocTy &Locs);
1327   /// Called on well-formed 'has_device_addr' clause.
1328   OMPClause *ActOnOpenMPHasDeviceAddrClause(ArrayRef<Expr *> VarList,
1329                                             const OMPVarListLocTy &Locs);
1330   /// Called on well-formed 'nontemporal' clause.
1331   OMPClause *ActOnOpenMPNontemporalClause(ArrayRef<Expr *> VarList,
1332                                           SourceLocation StartLoc,
1333                                           SourceLocation LParenLoc,
1334                                           SourceLocation EndLoc);
1335 
1336   /// Data for list of allocators.
1337   struct UsesAllocatorsData {
1338     /// Allocator.
1339     Expr *Allocator = nullptr;
1340     /// Allocator traits.
1341     Expr *AllocatorTraits = nullptr;
1342     /// Locations of '(' and ')' symbols.
1343     SourceLocation LParenLoc, RParenLoc;
1344   };
1345   /// Called on well-formed 'uses_allocators' clause.
1346   OMPClause *ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc,
1347                                             SourceLocation LParenLoc,
1348                                             SourceLocation EndLoc,
1349                                             ArrayRef<UsesAllocatorsData> Data);
1350   /// Called on well-formed 'affinity' clause.
1351   OMPClause *ActOnOpenMPAffinityClause(SourceLocation StartLoc,
1352                                        SourceLocation LParenLoc,
1353                                        SourceLocation ColonLoc,
1354                                        SourceLocation EndLoc, Expr *Modifier,
1355                                        ArrayRef<Expr *> Locators);
1356   /// Called on a well-formed 'bind' clause.
1357   OMPClause *ActOnOpenMPBindClause(OpenMPBindClauseKind Kind,
1358                                    SourceLocation KindLoc,
1359                                    SourceLocation StartLoc,
1360                                    SourceLocation LParenLoc,
1361                                    SourceLocation EndLoc);
1362 
1363   /// Called on a well-formed 'ompx_dyn_cgroup_mem' clause.
1364   OMPClause *ActOnOpenMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc,
1365                                             SourceLocation LParenLoc,
1366                                             SourceLocation EndLoc);
1367 
1368   /// Called on well-formed 'doacross' clause.
1369   OMPClause *
1370   ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType,
1371                             SourceLocation DepLoc, SourceLocation ColonLoc,
1372                             ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1373                             SourceLocation LParenLoc, SourceLocation EndLoc);
1374 
1375   /// Called on a well-formed 'ompx_attribute' clause.
1376   OMPClause *ActOnOpenMPXAttributeClause(ArrayRef<const Attr *> Attrs,
1377                                          SourceLocation StartLoc,
1378                                          SourceLocation LParenLoc,
1379                                          SourceLocation EndLoc);
1380 
1381   /// Called on a well-formed 'ompx_bare' clause.
1382   OMPClause *ActOnOpenMPXBareClause(SourceLocation StartLoc,
1383                                     SourceLocation EndLoc);
1384 
1385   ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc,
1386                                       Expr *LowerBound,
1387                                       SourceLocation ColonLocFirst,
1388                                       SourceLocation ColonLocSecond,
1389                                       Expr *Length, Expr *Stride,
1390                                       SourceLocation RBLoc);
1391   ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc,
1392                                       SourceLocation RParenLoc,
1393                                       ArrayRef<Expr *> Dims,
1394                                       ArrayRef<SourceRange> Brackets);
1395 
1396   /// Data structure for iterator expression.
1397   struct OMPIteratorData {
1398     IdentifierInfo *DeclIdent = nullptr;
1399     SourceLocation DeclIdentLoc;
1400     ParsedType Type;
1401     OMPIteratorExpr::IteratorRange Range;
1402     SourceLocation AssignLoc;
1403     SourceLocation ColonLoc;
1404     SourceLocation SecColonLoc;
1405   };
1406 
1407   ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc,
1408                                   SourceLocation LLoc, SourceLocation RLoc,
1409                                   ArrayRef<OMPIteratorData> Data);
1410 
1411   void handleOMPAssumeAttr(Decl *D, const ParsedAttr &AL);
1412 
1413 private:
1414   void *VarDataSharingAttributesStack;
1415 
1416   /// Number of nested '#pragma omp declare target' directives.
1417   SmallVector<DeclareTargetContextInfo, 4> DeclareTargetNesting;
1418 
1419   /// Initialization of data-sharing attributes stack.
1420   void InitDataSharingAttributesStack();
1421   void DestroyDataSharingAttributesStack();
1422 
1423   /// Returns OpenMP nesting level for current directive.
1424   unsigned getOpenMPNestingLevel() const;
1425 
1426   /// Adjusts the function scopes index for the target-based regions.
1427   void adjustOpenMPTargetScopeIndex(unsigned &FunctionScopesIndex,
1428                                     unsigned Level) const;
1429 
1430   /// Returns the number of scopes associated with the construct on the given
1431   /// OpenMP level.
1432   int getNumberOfConstructScopes(unsigned Level) const;
1433 
1434   /// Push new OpenMP function region for non-capturing function.
1435   void pushOpenMPFunctionRegion();
1436 
1437   /// Pop OpenMP function region for non-capturing function.
1438   void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI);
1439 
1440   /// Analyzes and checks a loop nest for use by a loop transformation.
1441   ///
1442   /// \param Kind          The loop transformation directive kind.
1443   /// \param NumLoops      How many nested loops the directive is expecting.
1444   /// \param AStmt         Associated statement of the transformation directive.
1445   /// \param LoopHelpers   [out] The loop analysis result.
1446   /// \param Body          [out] The body code nested in \p NumLoops loop.
1447   /// \param OriginalInits [out] Collection of statements and declarations that
1448   ///                      must have been executed/declared before entering the
1449   ///                      loop.
1450   ///
1451   /// \return Whether there was any error.
1452   bool checkTransformableLoopNest(
1453       OpenMPDirectiveKind Kind, Stmt *AStmt, int NumLoops,
1454       SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers,
1455       Stmt *&Body, SmallVectorImpl<SmallVector<Stmt *, 0>> &OriginalInits);
1456 
1457   /// Helper to keep information about the current `omp begin/end declare
1458   /// variant` nesting.
1459   struct OMPDeclareVariantScope {
1460     /// The associated OpenMP context selector.
1461     OMPTraitInfo *TI;
1462 
1463     /// The associated OpenMP context selector mangling.
1464     std::string NameSuffix;
1465 
1466     OMPDeclareVariantScope(OMPTraitInfo &TI);
1467   };
1468 
1469   /// Return the OMPTraitInfo for the surrounding scope, if any.
1470   OMPTraitInfo *getOMPTraitInfoForSurroundingScope() {
1471     return OMPDeclareVariantScopes.empty() ? nullptr
1472                                            : OMPDeclareVariantScopes.back().TI;
1473   }
1474 
1475   /// The current `omp begin/end declare variant` scopes.
1476   SmallVector<OMPDeclareVariantScope, 4> OMPDeclareVariantScopes;
1477 
1478   /// The current `omp begin/end assumes` scopes.
1479   SmallVector<OMPAssumeAttr *, 4> OMPAssumeScoped;
1480 
1481   /// All `omp assumes` we encountered so far.
1482   SmallVector<OMPAssumeAttr *, 4> OMPAssumeGlobal;
1483 };
1484 
1485 } // namespace clang
1486 
1487 #endif // LLVM_CLANG_SEMA_SEMAOPENMP_H