[clang] e4c7298 - [OpenMP 5.1] Parsing and Sema support for `scope` directive

Fazlay Rabbi via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 24 18:14:30 PDT 2023


Author: Fazlay Rabbi
Date: 2023-08-24T18:13:52-07:00
New Revision: e4c7298bea88727ed55817c436db1675c867d72b

URL: https://github.com/llvm/llvm-project/commit/e4c7298bea88727ed55817c436db1675c867d72b
DIFF: https://github.com/llvm/llvm-project/commit/e4c7298bea88727ed55817c436db1675c867d72b.diff

LOG: [OpenMP 5.1] Parsing and Sema support for `scope` directive

structured-block

where clause is one of the following:

private(list)
reduction([reduction-modifier ,] reduction-identifier : list)
nowait

Differential Revision: https://reviews.llvm.org/D157933

Added: 
    clang/test/OpenMP/scope_ast_print.cpp
    clang/test/OpenMP/scope_messages.cpp

Modified: 
    clang/docs/OpenMPSupport.rst
    clang/include/clang-c/Index.h
    clang/include/clang/AST/RecursiveASTVisitor.h
    clang/include/clang/AST/StmtOpenMP.h
    clang/include/clang/Basic/StmtNodes.td
    clang/include/clang/Sema/Sema.h
    clang/include/clang/Serialization/ASTBitCodes.h
    clang/lib/AST/StmtOpenMP.cpp
    clang/lib/AST/StmtPrinter.cpp
    clang/lib/AST/StmtProfile.cpp
    clang/lib/Basic/OpenMPKinds.cpp
    clang/lib/CodeGen/CGStmt.cpp
    clang/lib/Parse/ParseOpenMP.cpp
    clang/lib/Sema/SemaExceptionSpec.cpp
    clang/lib/Sema/SemaOpenMP.cpp
    clang/lib/Sema/TreeTransform.h
    clang/lib/Serialization/ASTReaderStmt.cpp
    clang/lib/Serialization/ASTWriterStmt.cpp
    clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
    clang/test/OpenMP/nesting_of_regions.cpp
    clang/tools/libclang/CIndex.cpp
    clang/tools/libclang/CXCursor.cpp
    llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 
    


################################################################################
diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index adb2391c4af6cb..5a5fa950adcd41 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -321,7 +321,7 @@ implementation.
 +------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
 | misc                         | error directive                                              | :none:`unclaimed`        |                                                                       |
 +------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
-| misc                         | scope construct                                              | :none:`unclaimed`        |                                                                       |
+| misc                         | scope construct                                              | :none:`worked on`        | D157933                                                               |
 +------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
 | misc                         | routines for controlling and querying team regions           | :none:`unclaimed`        |                                                                       |
 +------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+

diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 601b91f67d6588..1b91feabd584c5 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2136,7 +2136,11 @@ enum CXCursorKind {
    */
   CXCursor_OMPErrorDirective = 305,
 
-  CXCursor_LastStmt = CXCursor_OMPErrorDirective,
+  /** OpenMP scope directive.
+   */
+  CXCursor_OMPScopeDirective = 306,
+
+  CXCursor_LastStmt = CXCursor_OMPScopeDirective,
 
   /**
    * Cursor that represents the translation unit itself.

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h
index fc2d1ff708bf7a..18c6291e6261e6 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2980,6 +2980,9 @@ DEF_TRAVERSE_STMT(OMPSectionsDirective,
 DEF_TRAVERSE_STMT(OMPSectionDirective,
                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
 
+DEF_TRAVERSE_STMT(OMPScopeDirective,
+                  { TRY_TO(TraverseOMPExecutableDirective(S)); })
+
 DEF_TRAVERSE_STMT(OMPSingleDirective,
                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
 

diff  --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h
index 20cd198f5f0cc5..2725747e051e72 100644
--- a/clang/include/clang/AST/StmtOpenMP.h
+++ b/clang/include/clang/AST/StmtOpenMP.h
@@ -1931,6 +1931,57 @@ class OMPSectionDirective : public OMPExecutableDirective {
   }
 };
 
+/// This represents '#pragma omp scope' directive.
+/// \code
+/// #pragma omp scope private(a,b) nowait
+/// \endcode
+/// In this example directive '#pragma omp scope' has clauses 'private' with
+/// the variables 'a' and 'b' and nowait.
+///
+class OMPScopeDirective final : public OMPExecutableDirective {
+  friend class ASTStmtReader;
+  friend class OMPExecutableDirective;
+
+  /// Build directive with the given start and end location.
+  ///
+  /// \param StartLoc Starting location of the directive kind.
+  /// \param EndLoc Ending location of the directive.
+  ///
+  OMPScopeDirective(SourceLocation StartLoc, SourceLocation EndLoc)
+      : OMPExecutableDirective(OMPScopeDirectiveClass, llvm::omp::OMPD_scope,
+                               StartLoc, EndLoc) {}
+
+  /// Build an empty directive.
+  ///
+  explicit OMPScopeDirective()
+      : OMPExecutableDirective(OMPScopeDirectiveClass, llvm::omp::OMPD_scope,
+                               SourceLocation(), SourceLocation()) {}
+
+public:
+  /// Creates directive.
+  ///
+  /// \param C AST context.
+  /// \param StartLoc Starting location of the directive kind.
+  /// \param EndLoc Ending Location of the directive.
+  /// \param AssociatedStmt Statement, associated with the directive.
+  ///
+  static OMPScopeDirective *Create(const ASTContext &C, SourceLocation StartLoc,
+                                   SourceLocation EndLoc,
+                                   ArrayRef<OMPClause *> Clauses,
+                                   Stmt *AssociatedStmt);
+
+  /// Creates an empty directive.
+  ///
+  /// \param C AST context.
+  ///
+  static OMPScopeDirective *CreateEmpty(const ASTContext &C,
+                                        unsigned NumClauses, EmptyShell);
+
+  static bool classof(const Stmt *T) {
+    return T->getStmtClass() == OMPScopeDirectiveClass;
+  }
+};
+
 /// This represents '#pragma omp single' directive.
 ///
 /// \code

diff  --git a/clang/include/clang/Basic/StmtNodes.td b/clang/include/clang/Basic/StmtNodes.td
index 4b31e06eb2cdb7..cec301dfca2817 100644
--- a/clang/include/clang/Basic/StmtNodes.td
+++ b/clang/include/clang/Basic/StmtNodes.td
@@ -259,6 +259,7 @@ def OMPTargetUpdateDirective : StmtNode<OMPExecutableDirective>;
 def OMPTeamsDirective : StmtNode<OMPExecutableDirective>;
 def OMPCancellationPointDirective : StmtNode<OMPExecutableDirective>;
 def OMPCancelDirective : StmtNode<OMPExecutableDirective>;
+def OMPScopeDirective : StmtNode<OMPExecutableDirective>;
 def OMPTaskLoopDirective : StmtNode<OMPLoopDirective>;
 def OMPTaskLoopSimdDirective : StmtNode<OMPLoopDirective>;
 def OMPMasterTaskLoopDirective : StmtNode<OMPLoopDirective>;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 807a52886ccb19..04c2faddec5bf4 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11554,6 +11554,11 @@ class Sema final {
   /// associated statement.
   StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc,
                                          SourceLocation EndLoc);
+  /// Called on well-formed '\#pragma omp scope' after parsing of the
+  /// associated statement.
+  StmtResult ActOnOpenMPScopeDirective(ArrayRef<OMPClause *> Clauses,
+                                       Stmt *AStmt, SourceLocation StartLoc,
+                                       SourceLocation EndLoc);
   /// Called on well-formed '\#pragma omp single' after parsing of the
   /// associated statement.
   StmtResult ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses,

diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h
index 3ad22bbcf5d12d..dcc7bdf9b4eaac 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1995,6 +1995,7 @@ enum StmtCode {
   STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE,
   STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE,
   STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE,
+  STMT_OMP_SCOPE_DIRECTIVE,
   STMT_OMP_INTEROP_DIRECTIVE,
   STMT_OMP_DISPATCH_DIRECTIVE,
   STMT_OMP_MASKED_DIRECTIVE,

diff  --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp
index 5a1001d95b552c..426b35848cb5c8 100644
--- a/clang/lib/AST/StmtOpenMP.cpp
+++ b/clang/lib/AST/StmtOpenMP.cpp
@@ -531,6 +531,23 @@ OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C,
                                                    /*HasAssociatedStmt=*/true);
 }
 
+OMPScopeDirective *OMPScopeDirective::Create(const ASTContext &C,
+                                             SourceLocation StartLoc,
+                                             SourceLocation EndLoc,
+                                             ArrayRef<OMPClause *> Clauses,
+                                             Stmt *AssociatedStmt) {
+  return createDirective<OMPScopeDirective>(C, Clauses, AssociatedStmt,
+                                            /*NumChildren=*/0, StartLoc,
+                                            EndLoc);
+}
+
+OMPScopeDirective *OMPScopeDirective::CreateEmpty(const ASTContext &C,
+                                                  unsigned NumClauses,
+                                                  EmptyShell) {
+  return createEmptyDirective<OMPScopeDirective>(C, NumClauses,
+                                                 /*HasAssociatedStmt=*/true);
+}
+
 OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C,
                                                SourceLocation StartLoc,
                                                SourceLocation EndLoc,

diff  --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index c3db500d8a8def..20e0e5d9cdf59f 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -777,6 +777,11 @@ void StmtPrinter::VisitOMPSectionDirective(OMPSectionDirective *Node) {
   PrintOMPExecutableDirective(Node);
 }
 
+void StmtPrinter::VisitOMPScopeDirective(OMPScopeDirective *Node) {
+  Indent() << "#pragma omp scope";
+  PrintOMPExecutableDirective(Node);
+}
+
 void StmtPrinter::VisitOMPSingleDirective(OMPSingleDirective *Node) {
   Indent() << "#pragma omp single";
   PrintOMPExecutableDirective(Node);

diff  --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 60646f7a0da57c..27f71edd6f99b3 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -996,6 +996,10 @@ void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
   VisitOMPExecutableDirective(S);
 }
 
+void StmtProfiler::VisitOMPScopeDirective(const OMPScopeDirective *S) {
+  VisitOMPExecutableDirective(S);
+}
+
 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
   VisitOMPExecutableDirective(S);
 }

diff  --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 1c59a9091b4a4f..a679f2ecf0e2b5 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -848,6 +848,7 @@ void clang::getOpenMPCaptureRegions(
   case OMPD_atomic:
   case OMPD_target_data:
   case OMPD_distribute_simd:
+  case OMPD_scope:
   case OMPD_dispatch:
     CaptureRegions.push_back(OMPD_unknown);
     break;

diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 2184b8600d764c..6674aa2409a594 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -409,6 +409,8 @@ void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs) {
   case Stmt::OMPDispatchDirectiveClass:
     llvm_unreachable("Dispatch directive not supported yet.");
     break;
+  case Stmt::OMPScopeDirectiveClass:
+    llvm_unreachable("scope not supported with FE outlining");
   case Stmt::OMPMaskedDirectiveClass:
     EmitOMPMaskedDirective(cast<OMPMaskedDirective>(*S));
     break;

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 66cabb19423348..605b97617432ed 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2418,6 +2418,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
   case OMPD_distribute_simd:
   case OMPD_target_parallel_for_simd:
   case OMPD_target_simd:
+  case OMPD_scope:
   case OMPD_teams_distribute:
   case OMPD_teams_distribute_simd:
   case OMPD_teams_distribute_parallel_for_simd:
@@ -2810,6 +2811,7 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   case OMPD_target_teams_loop:
   case OMPD_parallel_loop:
   case OMPD_target_parallel_loop:
+  case OMPD_scope:
   case OMPD_taskloop:
   case OMPD_taskloop_simd:
   case OMPD_master_taskloop:

diff  --git a/clang/lib/Sema/SemaExceptionSpec.cpp b/clang/lib/Sema/SemaExceptionSpec.cpp
index 9b7ff5ff82519c..72304e51ea8ef3 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -1496,6 +1496,7 @@ CanThrowResult Sema::canThrow(const Stmt *S) {
   case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass:
   case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass:
   case Stmt::OMPTargetUpdateDirectiveClass:
+  case Stmt::OMPScopeDirectiveClass:
   case Stmt::OMPTaskDirectiveClass:
   case Stmt::OMPTaskgroupDirectiveClass:
   case Stmt::OMPTaskLoopDirectiveClass:

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 404b21559559f1..04aac12efe8bf0 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -3709,6 +3709,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
         S->getDirectiveKind() == OMPD_section ||
         S->getDirectiveKind() == OMPD_master ||
         S->getDirectiveKind() == OMPD_masked ||
+        S->getDirectiveKind() == OMPD_scope ||
         isOpenMPLoopTransformationDirective(S->getDirectiveKind())) {
       Visit(S->getAssociatedStmt());
       return;
@@ -4319,6 +4320,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) {
   case OMPD_distribute:
   case OMPD_distribute_simd:
   case OMPD_ordered:
+  case OMPD_scope:
   case OMPD_target_data:
   case OMPD_dispatch: {
     Sema::CapturedParamNameType Params[] = {
@@ -5130,7 +5132,10 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
                        diag::note_omp_previous_critical_region);
         return true;
       }
-    } else if (CurrentRegion == OMPD_barrier) {
+    } else if (CurrentRegion == OMPD_barrier || CurrentRegion == OMPD_scope) {
+      // OpenMP 5.1 [2.22, Nesting of Regions]
+      // A scope region may not be closely nested inside a worksharing, loop,
+      // task, taskloop, critical, ordered, atomic, or masked region.
       // OpenMP 5.1 [2.22, Nesting of Regions]
       // A barrier region may not be closely nested inside a worksharing, loop,
       // task, taskloop, critical, ordered, atomic, or masked region.
@@ -6449,6 +6454,10 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
     if (LangOpts.OpenMP >= 50)
       AllowedNameModifiers.push_back(OMPD_simd);
     break;
+  case OMPD_scope:
+    Res =
+        ActOnOpenMPScopeDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc);
+    break;
   case OMPD_parallel_master:
     Res = ActOnOpenMPParallelMasterDirective(ClausesWithImplicit, AStmt,
                                              StartLoc, EndLoc);
@@ -23904,6 +23913,17 @@ OMPClause *Sema::ActOnOpenMPNontemporalClause(ArrayRef<Expr *> VarList,
                                       Vars);
 }
 
+StmtResult Sema::ActOnOpenMPScopeDirective(ArrayRef<OMPClause *> Clauses,
+                                           Stmt *AStmt, SourceLocation StartLoc,
+                                           SourceLocation EndLoc) {
+  if (!AStmt)
+    return StmtError();
+
+  setFunctionHasBranchProtectedScope();
+
+  return OMPScopeDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt);
+}
+
 OMPClause *Sema::ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList,
                                             SourceLocation StartLoc,
                                             SourceLocation LParenLoc,

diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 769811c2772c6f..f553c4131fb25d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -8925,6 +8925,17 @@ TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
   return Res;
 }
 
+template <typename Derived>
+StmtResult
+TreeTransform<Derived>::TransformOMPScopeDirective(OMPScopeDirective *D) {
+  DeclarationNameInfo DirName;
+  getDerived().getSema().StartOpenMPDSABlock(OMPD_scope, DirName, nullptr,
+                                             D->getBeginLoc());
+  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
+  getDerived().getSema().EndOpenMPDSABlock(Res.get());
+  return Res;
+}
+
 template <typename Derived>
 StmtResult
 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {

diff  --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index e9ad324bed04ff..2c08ebb0d70345 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2391,6 +2391,11 @@ void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) {
   D->setHasCancel(Record.readBool());
 }
 
+void ASTStmtReader::VisitOMPScopeDirective(OMPScopeDirective *D) {
+  VisitStmt(D);
+  VisitOMPExecutableDirective(D);
+}
+
 void ASTStmtReader::VisitOMPSingleDirective(OMPSingleDirective *D) {
   VisitStmt(D);
   VisitOMPExecutableDirective(D);
@@ -3352,6 +3357,11 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
       S = OMPSectionDirective::CreateEmpty(Context, Empty);
       break;
 
+    case STMT_OMP_SCOPE_DIRECTIVE:
+      S = OMPScopeDirective::CreateEmpty(
+          Context, Record[ASTStmtReader::NumStmtFields], Empty);
+      break;
+
     case STMT_OMP_SINGLE_DIRECTIVE:
       S = OMPSingleDirective::CreateEmpty(
           Context, Record[ASTStmtReader::NumStmtFields], Empty);

diff  --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index 0c267d35bcf319..20bebd98da2587 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -2308,6 +2308,12 @@ void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) {
   Code = serialization::STMT_OMP_SECTION_DIRECTIVE;
 }
 
+void ASTStmtWriter::VisitOMPScopeDirective(OMPScopeDirective *D) {
+  VisitStmt(D);
+  VisitOMPExecutableDirective(D);
+  Code = serialization::STMT_OMP_SCOPE_DIRECTIVE;
+}
+
 void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) {
   VisitStmt(D);
   VisitOMPExecutableDirective(D);

diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 144f034a9dfeff..0e2ac78f7089c5 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1746,6 +1746,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
     case Stmt::OMPForSimdDirectiveClass:
     case Stmt::OMPSectionsDirectiveClass:
     case Stmt::OMPSectionDirectiveClass:
+    case Stmt::OMPScopeDirectiveClass:
     case Stmt::OMPSingleDirectiveClass:
     case Stmt::OMPMasterDirectiveClass:
     case Stmt::OMPCriticalDirectiveClass:

diff  --git a/clang/test/OpenMP/nesting_of_regions.cpp b/clang/test/OpenMP/nesting_of_regions.cpp
index 6973f63bd95677..9442fb20647d0f 100644
--- a/clang/test/OpenMP/nesting_of_regions.cpp
+++ b/clang/test/OpenMP/nesting_of_regions.cpp
@@ -3,9 +3,11 @@
 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-extensions -verify=expected,omp50 %s
 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -verify=expected,omp45,omp -fno-openmp-extensions -Wno-openmp %s
 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -verify=expected,omp45,omp -fno-openmp-extensions -Wno-source-uses-openmp %s
+// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=51 -verify=expected,omp51,omp -fno-openmp-extensions -Wno-source-uses-openmp %s
 
 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=45 -fno-openmp-extensions -verify=expected,omp45,omp45warn,omp %s
 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -verify=expected,omp50,omp -fno-openmp-extensions %s
+// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=51 -verify=expected,omp51,omp -fno-openmp-extensions %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 
 void bar();
@@ -241,7 +243,7 @@ void foo() {
 // SIMD DIRECTIVE
 #pragma omp simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp for // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{OpenMP constructs may not be nested inside a simd region except for ordered simd, simd, scan, or atomic directive}}
+#pragma omp for // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{OpenMP constructs may not be nested inside a simd region except for ordered simd, simd, scan, or atomic directive}} omp51-error {{OpenMP constructs may not be nested inside a simd region except for ordered simd, simd, scan, or atomic directive}}
     for (int i = 0; i < 10; ++i)
       ;
   }
@@ -350,7 +352,7 @@ void foo() {
   }
 #pragma omp simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
     bar();
   }
 #pragma omp simd
@@ -638,7 +640,7 @@ void foo() {
   }
 #pragma omp for
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
+#pragma omp scan // omp45-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
     bar();
   }
 #pragma omp for
@@ -903,7 +905,7 @@ void foo() {
   }
 #pragma omp for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
     bar();
   }
 #pragma omp for simd
@@ -2676,7 +2678,7 @@ void foo() {
   }
 #pragma omp parallel for
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{region cannot be closely nested inside 'parallel for' region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
+#pragma omp scan // omp45-error {{region cannot be closely nested inside 'parallel for' region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
     bar();
   }
 #pragma omp parallel for
@@ -2950,7 +2952,7 @@ void foo() {
   }
 #pragma omp parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
     bar();
   }
 #pragma omp parallel for simd
@@ -6861,7 +6863,7 @@ void foo() {
 #pragma omp teams
 #pragma omp distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
 #pragma omp target
@@ -7150,7 +7152,7 @@ void foo() {
   }
 #pragma omp target simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'target simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'target simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'target simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
 #pragma omp target simd
@@ -7958,7 +7960,7 @@ void foo() {
 #pragma omp target
 #pragma omp teams distribute simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'teams distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'teams distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'teams distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
 #pragma omp target
@@ -8247,7 +8249,7 @@ void foo() {
 #pragma omp target
 #pragma omp teams distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'teams distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'teams distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'teams distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
 #pragma omp target
@@ -9528,7 +9530,7 @@ void foo() {
   }
 #pragma omp target teams distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'target teams distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'target teams distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'target teams distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
 #pragma omp target teams distribute parallel for simd
@@ -9776,7 +9778,7 @@ void foo() {
   }
 #pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'target teams distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'target teams distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'target teams distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
 #pragma omp target teams distribute simd
@@ -9901,338 +9903,734 @@ void foo() {
       ;
   }
 
-}
-
-void foo() {
-  int a = 0;
-// PARALLEL DIRECTIVE
-#pragma omp parallel
+  // SCOPE DIRECTIVE
+#pragma omp scope
+#pragma omp parallel // OK
+  bar();
+#pragma omp scope
+#pragma omp parallel for // OK
+  for(int i = 0; i < 10; i++)
+    ;
+#pragma omp scope
+#pragma omp parallel for simd // OK
+  for(int i = 0; i < 10; i++)
+    ;
+#pragma omp scope
 #pragma omp for
   for (int i = 0; i < 10; ++i)
     ;
-#pragma omp parallel
+#pragma omp scope
 #pragma omp simd
   for (int i = 0; i < 10; ++i)
     ;
-#pragma omp parallel
+#pragma omp scope
 #pragma omp for simd
   for (int i = 0; i < 10; ++i)
     ;
-#pragma omp parallel
+#pragma omp scope
 #pragma omp sections
   {
     bar();
   }
-#pragma omp parallel
-#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a parallel region}}
-  {
-    bar();
-  }
-#pragma omp parallel
-#pragma omp sections
+#pragma omp scope
+#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a scope region}}
   {
     bar();
   }
-#pragma omp parallel
+#pragma omp scope
 #pragma omp single
   bar();
-#pragma omp parallel
+
+#pragma omp scope
 #pragma omp master
-  bar();
-#pragma omp parallel master
-  bar();
-#pragma omp parallel masked
-  bar();
-#pragma omp parallel
+  {
+    bar();
+  }
+#pragma omp scope
 #pragma omp critical
-  bar();
-#pragma omp parallel
-#pragma omp parallel for
-  for (int i = 0; i < 10; ++i)
-    ;
-#pragma omp parallel
-#pragma omp parallel for simd
-  for (int i = 0; i < 10; ++i)
-    ;
-#pragma omp parallel
+  {
+    bar();
+  }
+#pragma omp scope
 #pragma omp parallel sections
   {
     bar();
   }
-#pragma omp parallel
+#pragma omp scope
+#pragma omp parallel master
+  {
+    bar();
+  }
+#pragma omp scope
+#pragma omp parallel masked
+  {
+    bar();
+  }
+#pragma omp scope
 #pragma omp task
   {
     bar();
   }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp taskyield
     bar();
   }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp barrier
     bar();
   }
-#pragma omp parallel
+#pragma omp scope
   {
-#pragma omp scan // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp taskwait
     bar();
   }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp flush
     bar();
   }
-#pragma omp parallel
+#pragma omp scope
   {
-#pragma omp ordered // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
+#pragma omp ordered // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
     bar();
   }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp atomic
     ++a;
   }
-#pragma omp parallel
-  {
-#pragma omp target
-    ++a;
-  }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp target parallel
     ++a;
   }
-#pragma omp parallel
+#pragma omp scope
+  {
 #pragma omp target parallel for
   for (int i = 0; i < 10; ++i)
     ;
-#pragma omp parallel
+  }
+#pragma omp scope
   {
 #pragma omp target enter data map(to: a)
     ++a;
   }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp target exit data map(from: a)
     ++a;
   }
-#pragma omp parallel
-  {
-#pragma omp teams // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp teams' directive into a target region?}}
-    ++a;
-  }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp taskloop
   for (int i = 0; i < 10; ++i)
     ++a;
   }
-#pragma omp parallel
+#pragma omp scope
   {
-#pragma omp distribute // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp distribute' directive into a teams region?}}
-    for (int i = 0; i < 10; ++i)
-      ;
+#pragma omp target // OK
+    a++;
   }
-#pragma omp parallel
+#pragma omp scope
   {
-#pragma omp target update to(a)
+#pragma omp teams // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp teams' directive into a target region?}}
     a++;
   }
-#pragma omp parallel
+#pragma omp scope
   {
-#pragma omp distribute parallel for // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp distribute parallel for' directive into a teams region?}}
-    for (int i = 0; i < 10; ++i)
-      ;
+#pragma omp target teams // OK
+    a++;
   }
-#pragma omp parallel
+#pragma omp scope
   {
-#pragma omp distribute parallel for simd // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp distribute parallel for simd' directive into a teams region?}}
+#pragma omp distribute // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp distribute' directive into a teams region?}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp parallel
+ #pragma omp scope
+   {
+ #pragma omp distribute parallel for simd // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp distribute parallel for simd' directive into a teams region?}}
+     for (int i = 0; i < 10; ++i)
+       ;
+   }
+#pragma omp scope
   {
-#pragma omp distribute simd // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp distribute simd' directive into a teams region?}}
+#pragma omp distribute simd // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp distribute simd' directive into a teams region?}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp target simd // OK
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp parallel
-  {
-#pragma omp teams distribute // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp teams distribute' directive into a target region?}}
-    for (int i = 0; i < 10; ++i)
-      ;
-  }
-#pragma omp parallel
+#pragma omp scope
+   {
+ #pragma omp teams distribute // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp teams distribute' directive into a target region?}}
+     for (int i = 0; i < 10; ++i)
+       ;
+   }
+#pragma omp scope
   {
-#pragma omp teams distribute simd // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp teams distribute simd' directive into a target region?}}
+#pragma omp teams distribute simd // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp teams distribute simd' directive into a target region?}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp parallel
+#pragma omp scope
   {
-#pragma omp teams distribute parallel for simd // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp teams distribute parallel for simd' directive into a target region?}}
+#pragma omp teams distribute parallel for simd // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp teams distribute parallel for simd' directive into a target region?}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp parallel
+#pragma omp scope
   {
-#pragma omp teams distribute parallel for // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp teams distribute parallel for' directive into a target region?}}
+#pragma omp teams distribute parallel for // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp teams distribute parallel for' directive into a target region?}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp target teams // OK
-    a++;
+    ++a;
   }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp target teams distribute // OK
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp target teams distribute parallel for // OK
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp target teams distribute parallel for simd // OK
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp parallel
+#pragma omp scope
   {
 #pragma omp target teams distribute simd // OK
     for (int i = 0; i < 10; ++i)
       ;
   }
-
-// SIMD DIRECTIVE
-#pragma omp simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
-  }
-#pragma omp simd
+#pragma omp for
   for (int i = 0; i < 10; ++i) {
-#pragma omp simd // omp45warn-warning {{OpenMP only allows an ordered construct with the simd clause nested in a simd construct}}
-    for (int i = 0; i < 10; ++i)
-      ;
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'for' region}}
+    bar();
   }
-#pragma omp simd
+
+#pragma omp for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
   }
-#pragma omp simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp parallel // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
+
+#pragma omp sections
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'sections' region}}
+    bar();
   }
-#pragma omp simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+
+#pragma omp sections
+  {
+#pragma omp section
     {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'section' region}}
       bar();
     }
   }
-#pragma omp simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp section // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    {
-      bar();
-    }
+
+#pragma omp single
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'single' region}}
+    bar();
   }
-#pragma omp simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp single // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+
+#pragma omp master
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'master' region}}
     bar();
-#pragma omp master // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+  }
+
+#pragma omp critical
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'critical' region}}
     bar();
   }
-#pragma omp simd
+
+#pragma omp parallel for
   for (int i = 0; i < 10; ++i) {
-#pragma omp single // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    bar();
-#pragma omp critical // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'parallel for' region}}
     bar();
   }
-#pragma omp simd
+
+#pragma omp parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
   }
-#pragma omp simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
+
+#pragma omp parallel master
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'parallel master' region}}
+    bar();
   }
-#pragma omp simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp parallel sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    {
-      bar();
-    }
+
+#pragma omp parallel sections
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'parallel sections' region}}
+    bar();
   }
-#pragma omp simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp task // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    {
-      bar();
-    }
+
+#pragma omp task
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'task' region}}
+    bar();
   }
-#pragma omp simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp taskyield // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+
+#pragma omp ordered
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'ordered' region}}
     bar();
   }
-#pragma omp simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp barrier // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+
+#pragma omp atomic
+  // expected-error at +2 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an lvalue expression with scalar type}}
+  // expected-note at +1 {{expected an expression statement}}
+  {
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside an atomic region}}
     bar();
   }
-#pragma omp simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
+
+#pragma omp target
+#pragma omp teams
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp scope' directive into a parallel region?}}
     bar();
   }
-#pragma omp simd
+
+#pragma omp taskloop
   for (int i = 0; i < 10; ++i) {
-#pragma omp taskwait // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'taskloop' region}}
     bar();
   }
-#pragma omp simd
+
+#pragma omp target
+#pragma omp teams
+#pragma omp distribute parallel for
   for (int i = 0; i < 10; ++i) {
-#pragma omp flush // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'distribute parallel for' region}}
     bar();
   }
-#pragma omp simd
+
+#pragma omp target
+#pragma omp teams
+#pragma omp distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp ordered // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     bar();
   }
-#pragma omp simd
+
+#pragma omp target simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+
+#pragma omp target
+#pragma omp teams distribute simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+
+#pragma omp target
+#pragma omp teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+
+#pragma omp target
+#pragma omp teams distribute parallel for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'teams distribute parallel for' region}}
+    bar();
+  }
+
+#pragma omp target teams
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'target teams' region; perhaps you forget to enclose 'omp scope' directive into a parallel region?}}
+    bar();
+  }
+
+#pragma omp target teams distribute parallel for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'target teams distribute parallel for' region}}
+    bar();
+  }
+
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+
+#pragma omp target teams distribute simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+}
+
+void foo() {
+  int a = 0;
+// PARALLEL DIRECTIVE
+#pragma omp parallel
+#pragma omp for
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp parallel
+#pragma omp simd
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp parallel
+#pragma omp for simd
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp parallel
+#pragma omp sections
+  {
+    bar();
+  }
+#pragma omp parallel
+#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a parallel region}}
+  {
+    bar();
+  }
+#pragma omp parallel
+#pragma omp sections
+  {
+    bar();
+  }
+#pragma omp parallel
+#pragma omp single
+  bar();
+#pragma omp parallel
+#pragma omp master
+  bar();
+#pragma omp parallel master
+  bar();
+#pragma omp parallel masked
+  bar();
+#pragma omp parallel
+#pragma omp critical
+  bar();
+#pragma omp parallel
+#pragma omp parallel for
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp parallel
+#pragma omp parallel for simd
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp parallel
+#pragma omp parallel sections
+  {
+    bar();
+  }
+#pragma omp parallel
+#pragma omp task
+  {
+    bar();
+  }
+#pragma omp parallel
+  {
+#pragma omp taskyield
+    bar();
+  }
+#pragma omp parallel
+  {
+#pragma omp barrier
+    bar();
+  }
+#pragma omp parallel
+  {
+#pragma omp scan // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+    bar();
+  }
+#pragma omp parallel
+  {
+#pragma omp taskwait
+    bar();
+  }
+#pragma omp parallel
+  {
+#pragma omp flush
+    bar();
+  }
+#pragma omp parallel
+  {
+#pragma omp ordered // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
+    bar();
+  }
+#pragma omp parallel
+  {
+#pragma omp atomic
+    ++a;
+  }
+#pragma omp parallel
+  {
+#pragma omp target
+    ++a;
+  }
+#pragma omp parallel
+  {
+#pragma omp target parallel
+    ++a;
+  }
+#pragma omp parallel
+#pragma omp target parallel for
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp parallel
+  {
+#pragma omp target enter data map(to: a)
+    ++a;
+  }
+#pragma omp parallel
+  {
+#pragma omp target exit data map(from: a)
+    ++a;
+  }
+#pragma omp parallel
+  {
+#pragma omp teams // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp teams' directive into a target region?}}
+    ++a;
+  }
+#pragma omp parallel
+  {
+#pragma omp taskloop
+  for (int i = 0; i < 10; ++i)
+    ++a;
+  }
+#pragma omp parallel
+  {
+#pragma omp distribute // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp distribute' directive into a teams region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel
+  {
+#pragma omp target update to(a)
+    a++;
+  }
+#pragma omp parallel
+  {
+#pragma omp distribute parallel for // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp distribute parallel for' directive into a teams region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel
+  {
+#pragma omp distribute parallel for simd // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp distribute parallel for simd' directive into a teams region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel
+  {
+#pragma omp distribute simd // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp distribute simd' directive into a teams region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel
+  {
+#pragma omp target simd // OK
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel
+  {
+#pragma omp teams distribute // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp teams distribute' directive into a target region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel
+  {
+#pragma omp teams distribute simd // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp teams distribute simd' directive into a target region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel
+  {
+#pragma omp teams distribute parallel for simd // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp teams distribute parallel for simd' directive into a target region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel
+  {
+#pragma omp teams distribute parallel for // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp teams distribute parallel for' directive into a target region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel
+  {
+#pragma omp target teams // OK
+    a++;
+  }
+#pragma omp parallel
+  {
+#pragma omp target teams distribute // OK
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel
+  {
+#pragma omp target teams distribute parallel for // OK
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel
+  {
+#pragma omp target teams distribute parallel for simd // OK
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel
+  {
+#pragma omp target teams distribute simd // OK
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+
+// SIMD DIRECTIVE
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp simd // omp45warn-warning {{OpenMP only allows an ordered construct with the simd clause nested in a simd construct}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp parallel // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp section // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp single // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+#pragma omp master // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp single // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+#pragma omp critical // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp parallel sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp task // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp taskyield // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp barrier // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
+    bar();
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp taskwait // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp flush // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp ordered // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+#pragma omp simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp atomic // omp45-error {{OpenMP constructs may not be nested inside a simd region}}
     ++a;
@@ -10469,7 +10867,7 @@ void foo() {
   }
 #pragma omp for
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{region cannot be closely nested inside 'for' region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
+#pragma omp scan // omp45-error {{region cannot be closely nested inside 'for' region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
     bar();
   }
 #pragma omp for
@@ -10714,7 +11112,7 @@ void foo() {
   }
 #pragma omp for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
     bar();
   }
 #pragma omp for simd
@@ -12388,7 +12786,7 @@ void foo() {
   }
 #pragma omp parallel for
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{region cannot be closely nested inside 'parallel for' region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
+#pragma omp scan // omp45-error {{region cannot be closely nested inside 'parallel for' region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
     bar();
   }
 #pragma omp parallel for
@@ -12663,7 +13061,7 @@ void foo() {
   }
 #pragma omp parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
     bar();
   }
 #pragma omp parallel for simd
@@ -15687,7 +16085,7 @@ void foo() {
 #pragma omp teams
 #pragma omp distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
 #pragma omp target
@@ -16006,7 +16404,7 @@ void foo() {
 #pragma omp teams
 #pragma omp distribute simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
 #pragma omp target
@@ -16287,7 +16685,7 @@ void foo() {
   }
 #pragma omp target simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'target simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'target simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'target simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
 #pragma omp target simd
@@ -16837,7 +17235,7 @@ void foo() {
 #pragma omp target
 #pragma omp teams distribute simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'teams distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'teams distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'teams distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
 #pragma omp target
@@ -17126,7 +17524,7 @@ void foo() {
 #pragma omp target
 #pragma omp teams distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'teams distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'teams distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'teams distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
 #pragma omp target
@@ -18254,112 +18652,360 @@ void foo() {
     for (int i = 0; i < 10; ++i)
       ++a;
   }
-#pragma omp target teams distribute parallel for
+#pragma omp target teams distribute parallel for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp target teams // expected-error {{region cannot be nested inside 'target teams distribute parallel for' region}}
+    ++a;
+  }
+#pragma omp target teams distribute parallel for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp target teams distribute // expected-error {{region cannot be nested inside 'target teams distribute parallel for' region}}
+    for (int i = 0; i < 10; ++i)
+      ++a;
+  }
+#pragma omp target teams distribute parallel for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp target teams distribute parallel for // expected-error {{region cannot be nested inside 'target teams distribute parallel for' region}}
+    for (int i = 0; i < 10; ++i)
+      ++a;
+  }
+#pragma omp target teams distribute parallel for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp target teams distribute parallel for simd // expected-error {{region cannot be nested inside 'target teams distribute parallel for' region}}
+    for (int i = 0; i < 10; ++i)
+      ++a;
+  }
+#pragma omp target teams distribute parallel for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp target teams distribute simd // expected-error {{region cannot be nested inside 'target teams distribute parallel for' region}}
+    for (int i = 0; i < 10; ++i)
+      ++a;
+  }
+
+// TARGET TEAMS DISTRIBUTE PARALLEL FOR SIMD DIRECTIVE
+#pragma omp target teams distribute parallel for simd // OK
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp distribute parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp simd // omp45warn-warning {{OpenMP only allows an ordered construct with the simd clause nested in a simd construct}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp parallel // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp section // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp single // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp master // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp critical // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp parallel // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+#pragma omp single
+      {
+        bar();
+      }
+    }
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp parallel sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp task // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp taskyield // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp barrier // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'target teams distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'target teams distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+    bar();
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp taskwait // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp flush // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp ordered // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp atomic // omp45-error {{OpenMP constructs may not be nested inside a simd region}}
+    ++a;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp target // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    ++a;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp target parallel  // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    ++a;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp target parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp target enter data map(to: a) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    ++a;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp target exit data map(from: a) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    ++a;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp teams // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    ++a;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp target update to(a) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    ++a;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp distribute simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ++a;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp target simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ++a;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp teams distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ++a;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp teams distribute simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ++a;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp teams distribute parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ++a;
+  }
+#pragma omp target teams distribute parallel for simd
+  for (int i = 0; i < 10; ++i) {
+#pragma omp teams distribute parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp target teams distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp target teams // expected-error {{region cannot be nested inside 'target teams distribute parallel for' region}}
-    ++a;
+#pragma omp target teams // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    a++;
   }
-#pragma omp target teams distribute parallel for
+#pragma omp target teams distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp target teams distribute // expected-error {{region cannot be nested inside 'target teams distribute parallel for' region}}
+#pragma omp target teams distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
-      ++a;
+      ;
   }
-#pragma omp target teams distribute parallel for
+#pragma omp target teams distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp target teams distribute parallel for // expected-error {{region cannot be nested inside 'target teams distribute parallel for' region}}
+#pragma omp target teams distribute parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
-      ++a;
+      ;
   }
-#pragma omp target teams distribute parallel for
+#pragma omp target teams distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp target teams distribute parallel for simd // expected-error {{region cannot be nested inside 'target teams distribute parallel for' region}}
+#pragma omp target teams distribute parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
-      ++a;
+      ;
   }
-#pragma omp target teams distribute parallel for
+#pragma omp target teams distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp target teams distribute simd // expected-error {{region cannot be nested inside 'target teams distribute parallel for' region}}
+#pragma omp target teams distribute simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
-      ++a;
+      ;
   }
 
-// TARGET TEAMS DISTRIBUTE PARALLEL FOR SIMD DIRECTIVE
-#pragma omp target teams distribute parallel for simd // OK
+// TARGET TEAMS DISTRIBUTE SIMD DIRECTIVE
+#pragma omp target teams distribute simd // OK
   for (int i = 0; i < 10; ++i)
     ;
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp distribute parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp simd // omp45warn-warning {{OpenMP only allows an ordered construct with the simd clause nested in a simd construct}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp parallel // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     {
       bar();
     }
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp section // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     {
       bar();
     }
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp single // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     {
       bar();
     }
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp master // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     {
       bar();
     }
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp critical // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     {
       bar();
     }
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp parallel // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     {
@@ -18369,415 +19015,564 @@ void foo() {
       }
     }
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp parallel sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     {
       bar();
     }
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp task // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     {
       bar();
     }
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp taskyield // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     bar();
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp barrier // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     bar();
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'target teams distribute parallel for simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'target teams distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}} omp51-error {{region cannot be closely nested inside 'target teams distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
     bar();
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp taskwait // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     bar();
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp flush // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     bar();
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp ordered // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     bar();
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp atomic // omp45-error {{OpenMP constructs may not be nested inside a simd region}}
     ++a;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp target // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     ++a;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp target parallel  // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     ++a;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp target parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp target enter data map(to: a) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     ++a;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp target exit data map(from: a) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     ++a;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp teams // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     ++a;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp target update to(a) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     ++a;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp distribute simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ++a;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp target simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ++a;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp teams distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ++a;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp teams distribute simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ++a;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp teams distribute parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ++a;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp teams distribute parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp target teams // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     a++;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp target teams distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp target teams distribute parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp target teams distribute parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute parallel for simd
+#pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
 #pragma omp target teams distribute simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     for (int i = 0; i < 10; ++i)
       ;
   }
 
-// TARGET TEAMS DISTRIBUTE SIMD DIRECTIVE
-#pragma omp target teams distribute simd // OK
+  // SCOPE DIRECTIVE
+#pragma omp scope
+#pragma omp parallel // OK
+  bar();
+#pragma omp scope
+#pragma omp parallel for // OK
+  for(int i = 0; i < 10; i++)
+    ;
+#pragma omp scope
+#pragma omp parallel for simd // OK
+  for(int i = 0; i < 10; i++)
+    ;
+#pragma omp scope
+#pragma omp for
   for (int i = 0; i < 10; ++i)
     ;
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp distribute parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
+#pragma omp scope
+#pragma omp simd
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp scope
+#pragma omp for simd
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp scope
+#pragma omp sections
+  {
+    bar();
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
+#pragma omp scope
+#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a scope region}}
+  {
+    bar();
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#pragma omp scope
+#pragma omp single
+  bar();
+
+#pragma omp scope
+#pragma omp master
+  {
+    bar();
+  }
+#pragma omp scope
+#pragma omp critical
+  {
+    bar();
+  }
+#pragma omp scope
+#pragma omp parallel sections
+  {
+    bar();
+  }
+#pragma omp scope
+#pragma omp parallel master
+  {
+    bar();
+  }
+#pragma omp scope
+#pragma omp parallel masked
+  {
+    bar();
+  }
+#pragma omp scope
+#pragma omp task
+  {
+    bar();
+  }
+#pragma omp scope
+  {
+#pragma omp taskyield
+    bar();
+  }
+#pragma omp scope
+  {
+#pragma omp barrier
+    bar();
+  }
+#pragma omp scope
+  {
+#pragma omp scan // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+    bar();
+  }
+#pragma omp scope
+  {
+#pragma omp taskwait
+    bar();
+  }
+#pragma omp scope
+  {
+#pragma omp flush
+    bar();
+  }
+#pragma omp scope
+  {
+#pragma omp ordered // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
+    bar();
+  }
+#pragma omp scope
+  {
+#pragma omp atomic
+    ++a;
+  }
+#pragma omp scope
+  {
+#pragma omp target parallel
+    ++a;
+  }
+#pragma omp scope
+  {
+#pragma omp target parallel for
+  for (int i = 0; i < 10; ++i)
+    ;
+  }
+#pragma omp scope
+  {
+#pragma omp target enter data map(to: a)
+    ++a;
+  }
+#pragma omp scope
+  {
+#pragma omp target exit data map(from: a)
+    ++a;
+  }
+#pragma omp scope
+  {
+#pragma omp taskloop
+  for (int i = 0; i < 10; ++i)
+    ++a;
+  }
+#pragma omp scope
+  {
+#pragma omp target // OK
+    a++;
+  }
+#pragma omp scope
+  {
+#pragma omp teams // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp teams' directive into a target region?}}
+    a++;
+  }
+#pragma omp scope
+  {
+#pragma omp target teams // OK
+    a++;
+  }
+#pragma omp scope
+  {
+#pragma omp distribute // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp distribute' directive into a teams region?}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp simd // omp45warn-warning {{OpenMP only allows an ordered construct with the simd clause nested in a simd construct}}
+ #pragma omp scope
+   {
+ #pragma omp distribute parallel for simd // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp distribute parallel for simd' directive into a teams region?}}
+     for (int i = 0; i < 10; ++i)
+       ;
+   }
+#pragma omp scope
+  {
+#pragma omp distribute simd // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp distribute simd' directive into a teams region?}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#pragma omp scope
+  {
+#pragma omp target simd // OK
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp parallel // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#pragma omp scope
+   {
+ #pragma omp teams distribute // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp teams distribute' directive into a target region?}}
+     for (int i = 0; i < 10; ++i)
+       ;
+   }
+#pragma omp scope
+  {
+#pragma omp teams distribute simd // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp teams distribute simd' directive into a target region?}}
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    {
-      bar();
-    }
-  }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp section // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    {
-      bar();
-    }
+#pragma omp scope
+  {
+#pragma omp teams distribute parallel for simd // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp teams distribute parallel for simd' directive into a target region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp single // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    {
-      bar();
-    }
+#pragma omp scope
+  {
+#pragma omp teams distribute parallel for // expected-error {{region cannot be closely nested inside 'scope' region; perhaps you forget to enclose 'omp teams distribute parallel for' directive into a target region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp master // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    {
-      bar();
-    }
+#pragma omp scope
+  {
+#pragma omp target teams // OK
+    ++a;
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp critical // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    {
-      bar();
-    }
+#pragma omp scope
+  {
+#pragma omp target teams distribute // OK
+    for (int i = 0; i < 10; ++i)
+      ;
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp parallel // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    {
-#pragma omp single
-      {
-        bar();
-      }
-    }
+#pragma omp scope
+  {
+#pragma omp target teams distribute parallel for // OK
+    for (int i = 0; i < 10; ++i)
+      ;
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#pragma omp scope
+  {
+#pragma omp target teams distribute parallel for simd // OK
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#pragma omp scope
+  {
+#pragma omp target teams distribute simd // OK
     for (int i = 0; i < 10; ++i)
       ;
   }
-#pragma omp target teams distribute simd
+#pragma omp for
   for (int i = 0; i < 10; ++i) {
-#pragma omp parallel sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    {
-      bar();
-    }
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'for' region}}
+    bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp task // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
+  }
+
+#pragma omp sections
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'sections' region}}
+    bar();
+  }
+
+#pragma omp sections
+  {
+#pragma omp section
     {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'section' region}}
       bar();
     }
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp taskyield // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+
+#pragma omp single
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'single' region}}
     bar();
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp barrier // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+
+#pragma omp master
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'master' region}}
     bar();
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp scan // omp45-error {{OpenMP constructs may not be nested inside a simd region}} omp50-error {{region cannot be closely nested inside 'target teams distribute simd' region; perhaps you forget to enclose 'omp scan' directive into a for, simd, for simd, parallel for, or parallel for simd region?}}
+
+#pragma omp critical
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'critical' region}}
     bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp parallel for
   for (int i = 0; i < 10; ++i) {
-#pragma omp taskwait // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'parallel for' region}}
     bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp flush // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     bar();
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp ordered // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+
+#pragma omp parallel master
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'parallel master' region}}
     bar();
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp atomic // omp45-error {{OpenMP constructs may not be nested inside a simd region}}
-    ++a;
-  }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp target // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    ++a;
-  }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp target parallel  // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    ++a;
+
+#pragma omp parallel sections
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'parallel sections' region}}
+    bar();
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp target parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
+
+#pragma omp task
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'task' region}}
+    bar();
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp target enter data map(to: a) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    ++a;
+
+#pragma omp ordered
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'ordered' region}}
+    bar();
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp target exit data map(from: a) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    ++a;
+
+#pragma omp atomic
+  // expected-error at +2 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an lvalue expression with scalar type}}
+  // expected-note at +1 {{expected an expression statement}}
+  {
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside an atomic region}}
+    bar();
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp teams // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    ++a;
+
+#pragma omp target
+#pragma omp teams
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp scope' directive into a parallel region?}}
+    bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp taskloop
   for (int i = 0; i < 10; ++i) {
-#pragma omp target update to(a) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    ++a;
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'taskloop' region}}
+    bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp target
+#pragma omp teams
+#pragma omp distribute parallel for
   for (int i = 0; i < 10; ++i) {
-#pragma omp distribute simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ++a;
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'distribute parallel for' region}}
+    bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp target
+#pragma omp teams
+#pragma omp distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp target simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ++a;
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp target simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp teams distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ++a;
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp target
+#pragma omp teams distribute simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp teams distribute simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ++a;
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp target
+#pragma omp teams distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp teams distribute parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ++a;
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp target
+#pragma omp teams distribute parallel for
   for (int i = 0; i < 10; ++i) {
-#pragma omp teams distribute parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'teams distribute parallel for' region}}
+    bar();
   }
-#pragma omp target teams distribute simd
-  for (int i = 0; i < 10; ++i) {
-#pragma omp target teams // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    a++;
+
+#pragma omp target teams
+  {
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'target teams' region; perhaps you forget to enclose 'omp scope' directive into a parallel region?}}
+    bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp target teams distribute parallel for
   for (int i = 0; i < 10; ++i) {
-#pragma omp target teams distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
+#pragma omp scope // expected-error {{region cannot be closely nested inside 'target teams distribute parallel for' region}}
+    bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp target teams distribute parallel for simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp target teams distribute parallel for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
   }
+
 #pragma omp target teams distribute simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp target teams distribute parallel for simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
   }
-#pragma omp target teams distribute simd
+
+#pragma omp simd
   for (int i = 0; i < 10; ++i) {
-#pragma omp target teams distribute simd // expected-error {{OpenMP constructs may not be nested inside a simd region}}
-    for (int i = 0; i < 10; ++i)
-      ;
+#pragma omp scope // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    bar();
   }
 
   return foo<int>();

diff  --git a/clang/test/OpenMP/scope_ast_print.cpp b/clang/test/OpenMP/scope_ast_print.cpp
new file mode 100644
index 00000000000000..c69908980d2290
--- /dev/null
+++ b/clang/test/OpenMP/scope_ast_print.cpp
@@ -0,0 +1,88 @@
+//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu\
+//RUN:   -fopenmp -fopenmp-version=51 \
+//RUN:   -x c++ -std=c++14 -fexceptions -fcxx-exceptions                   \
+//RUN:   -Wno-source-uses-openmp -Wno-openmp-clauses                       \
+//RUN:   -ast-print %s | FileCheck %s --check-prefix=PRINT
+
+//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu\
+//RUN:   -fopenmp -fopenmp-version=51 \
+//RUN:   -x c++ -std=c++14 -fexceptions -fcxx-exceptions                   \
+//RUN:   -Wno-source-uses-openmp -Wno-openmp-clauses                       \
+//RUN:   -ast-dump %s | FileCheck %s --check-prefix=DUMP
+
+//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu\
+//RUN:   -fopenmp -fopenmp-version=51 \
+//RUN:   -x c++ -std=c++14 -fexceptions -fcxx-exceptions                   \
+//RUN:   -Wno-source-uses-openmp -Wno-openmp-clauses                       \
+//RUN:   -emit-pch -o %t %s
+
+//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu\
+//RUN:   -fopenmp -fopenmp-version=51 \
+//RUN:   -x c++ -std=c++14 -fexceptions -fcxx-exceptions                   \
+//RUN:   -Wno-source-uses-openmp -Wno-openmp-clauses                       \
+//RUN:   -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT
+
+//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu\
+//RUN:   -fopenmp -fopenmp-version=51 \
+//RUN:   -x c++ -std=c++14 -fexceptions -fcxx-exceptions                   \
+//RUN:   -Wno-source-uses-openmp -Wno-openmp-clauses                       \
+//RUN:   -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP
+
+#ifndef HEADER
+#define HEADER
+int foo1() {
+  int a;
+  int i = 1;
+  #pragma omp scope private(a) reduction(+:i) nowait
+  { 
+    a = 123; 
+    ++i; 
+  }
+  return i;
+}
+
+//DUMP: FunctionDecl {{.*}}foo1 'int ()'
+//DUMP: OMPScopeDirective
+//DUMP: OMPPrivateClause
+//DUMP: DeclRefExpr {{.*}}'int' lvalue Var{{.*}}'a' 'int'
+//DUMP: OMPReductionClause
+//DUMP: DeclRefExpr {{.*}}'int' lvalue Var{{.*}}'i' 'int'
+//DUMP: OMPNowaitClause
+//PRINT: #pragma omp scope private(a) reduction(+: i) nowait
+
+template <typename T>
+T run() {
+  T a;
+  T b;
+
+  #pragma omp scope private(a) reduction(*:b)
+  { 
+    b *= a; 
+  }
+  return b;
+}
+
+int template_test() {
+  double d;
+  d = run<double>();
+  return 0;
+}
+
+//DUMP: FunctionTemplateDecl {{.*}}run
+//DUMP: TemplateTypeParmDecl {{.*}}referenced typename depth 0 index 0 T
+//DUMP: FunctionDecl {{.*}}run 'T ()'
+//DUMP: OMPScopeDirective
+//DUMP: OMPPrivateClause
+//DUMP: DeclRefExpr {{.*}}'T' lvalue Var {{.*}} 'a' 'T'
+//DUMP: OMPReductionClause
+//DUMP: DeclRefExpr {{.*}}'T' lvalue Var {{.*}} 'b' 'T'
+//DUMP: FunctionDecl {{.*}}used run 'double ()'
+//DUMP: TemplateArgument type 'double'
+//DUMP: BuiltinType {{.*}}'double'
+//DUMP: OMPScopeDirective
+//DUMP: OMPPrivateClause
+//DUMP: DeclRefExpr {{.*}}'double':'double' lvalue Var {{.*}} 'a' 'double':'double'
+//DUMP: OMPReductionClause
+//DUMP: DeclRefExpr {{.*}}'double':'double' lvalue Var {{.*}} 'b' 'double':'double'
+//PRINT: #pragma omp scope private(a) reduction(*: b)
+#endif // HEADER

diff  --git a/clang/test/OpenMP/scope_messages.cpp b/clang/test/OpenMP/scope_messages.cpp
new file mode 100644
index 00000000000000..f8d7410122485c
--- /dev/null
+++ b/clang/test/OpenMP/scope_messages.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 %s -verify=expected,omp51
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 %s -verify=expected,omp51
+
+void test1()
+{
+  int var1;
+  int var2;
+  int var3 = 1;
+
+  // expected-error at +1 {{directive '#pragma omp scope' cannot contain more than one 'nowait' clause}} //omp51-error at +1{{unexpected OpenMP clause 'firstprivate' in directive '#pragma omp scope'}}
+  #pragma omp scope private(var1) firstprivate(var3) nowait nowait
+  { var1 = 123; ++var2; var3 = 2;}
+}

diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index ca9467eb1ac23e..f0c8ecfcb6264f 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -5951,6 +5951,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
     return cxstring::createRef("OMPSectionsDirective");
   case CXCursor_OMPSectionDirective:
     return cxstring::createRef("OMPSectionDirective");
+  case CXCursor_OMPScopeDirective:
+    return cxstring::createRef("OMPScopeDirective");
   case CXCursor_OMPSingleDirective:
     return cxstring::createRef("OMPSingleDirective");
   case CXCursor_OMPMasterDirective:

diff  --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp
index d48063f105f9f2..fd03c48ba1a42a 100644
--- a/clang/tools/libclang/CXCursor.cpp
+++ b/clang/tools/libclang/CXCursor.cpp
@@ -680,6 +680,9 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
   case Stmt::OMPSectionDirectiveClass:
     K = CXCursor_OMPSectionDirective;
     break;
+  case Stmt::OMPScopeDirectiveClass:
+    K = CXCursor_OMPScopeDirective;
+    break;
   case Stmt::OMPSingleDirectiveClass:
     K = CXCursor_OMPSingleDirective;
     break;

diff  --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td
index 6c9f6a5edb01c1..84ed836ff236cf 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -1979,6 +1979,15 @@ def OMP_BeginAssumes : Directive<"begin assumes"> {}
 def OMP_EndAssumes : Directive<"end assumes"> {}
 def OMP_BeginDeclareVariant : Directive<"begin declare variant"> {}
 def OMP_EndDeclareVariant : Directive<"end declare variant"> {}
+def OMP_scope : Directive<"scope"> {
+  let allowedClauses = [
+    VersionedClause<OMPC_Private, 51>,
+    VersionedClause<OMPC_Reduction, 51>,
+  ];
+  let allowedOnceClauses = [
+    VersionedClause<OMPC_NoWait, 51>
+  ];
+}
 def OMP_ParallelWorkshare : Directive<"parallel workshare"> {
   let allowedClauses = [
     VersionedClause<OMPC_Allocate>,


        


More information about the cfe-commits mailing list