[clang] bb83f8e - [OpenMP] Initial parsing and sema for 'parallel masked' construct

Jennifer Yu via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 16 18:15:57 PDT 2022


Author: Jennifer Yu
Date: 2022-06-16T18:01:15-07:00
New Revision: bb83f8e70bd1d56152f02307adacd718cd67e312

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

LOG: [OpenMP] Initial parsing and sema for 'parallel masked' construct

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

Added: 
    clang/test/OpenMP/parallel_masked_ast_print.cpp
    clang/test/OpenMP/parallel_masked_copyin_messages.cpp
    clang/test/OpenMP/parallel_masked_default_messages.cpp
    clang/test/OpenMP/parallel_masked_firstprivate_messages.cpp
    clang/test/OpenMP/parallel_masked_if_messages.cpp
    clang/test/OpenMP/parallel_masked_message.cpp
    clang/test/OpenMP/parallel_masked_num_threads_messages.cpp
    clang/test/OpenMP/parallel_masked_private_messages.cpp
    clang/test/OpenMP/parallel_masked_proc_bind_messages.cpp
    clang/test/OpenMP/parallel_masked_reduction_messages.cpp
    clang/test/OpenMP/parallel_masked_shared_messages.cpp

Modified: 
    clang/bindings/python/clang/cindex.py
    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/Analysis/cfg-openmp.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/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 44bfba494df21..597dc5dd49738 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -1312,7 +1312,7 @@ def __repr__(self):
 #
 # The translation unit cursor exists primarily to act as the root cursor for
 # traversing the contents of a translation unit.
-CursorKind.TRANSLATION_UNIT = CursorKind(300)
+CursorKind.TRANSLATION_UNIT = CursorKind(350)
 
 ###
 # Attributes

diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 70de5195d0580..4ad7cebb04dcf 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2626,7 +2626,11 @@ enum CXCursorKind {
    */
   CXCursor_OMPTargetParallelGenericLoopDirective = 299,
 
-  CXCursor_LastStmt = CXCursor_OMPTargetParallelGenericLoopDirective,
+  /** OpenMP parallel masked directive.
+   */
+  CXCursor_OMPParallelMaskedDirective = 300,
+
+  CXCursor_LastStmt = CXCursor_OMPParallelMaskedDirective,
 
   /**
    * Cursor that represents the translation unit itself.
@@ -2634,7 +2638,7 @@ enum CXCursorKind {
    * The translation unit cursor exists primarily to act as the root
    * cursor for traversing the contents of a translation unit.
    */
-  CXCursor_TranslationUnit = 300,
+  CXCursor_TranslationUnit = 350,
 
   /* Attributes */
   CXCursor_FirstAttr = 400,

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h
index c6d74d94194bd..e5acaec7358e1 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2994,6 +2994,9 @@ DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
 DEF_TRAVERSE_STMT(OMPParallelMasterDirective,
                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
 
+DEF_TRAVERSE_STMT(OMPParallelMaskedDirective,
+                  { TRY_TO(TraverseOMPExecutableDirective(S)); })
+
 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
 

diff  --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h
index 4ebe7f44aa7ad..0482e6a3b7d3d 100644
--- a/clang/include/clang/AST/StmtOpenMP.h
+++ b/clang/include/clang/AST/StmtOpenMP.h
@@ -2304,6 +2304,69 @@ class OMPParallelMasterDirective : public OMPExecutableDirective {
   }
 };
 
+/// This represents '#pragma omp parallel masked' directive.
+///
+/// \code
+/// #pragma omp parallel masked filter(tid)
+/// \endcode
+/// In this example directive '#pragma omp parallel masked' has a clause
+/// 'filter' with the variable tid
+///
+class OMPParallelMaskedDirective final : public OMPExecutableDirective {
+  friend class ASTStmtReader;
+  friend class OMPExecutableDirective;
+
+  OMPParallelMaskedDirective(SourceLocation StartLoc, SourceLocation EndLoc)
+      : OMPExecutableDirective(OMPParallelMaskedDirectiveClass,
+                               llvm::omp::OMPD_parallel_masked, StartLoc,
+                               EndLoc) {}
+
+  explicit OMPParallelMaskedDirective()
+      : OMPExecutableDirective(OMPParallelMaskedDirectiveClass,
+                               llvm::omp::OMPD_parallel_masked,
+                               SourceLocation(), SourceLocation()) {}
+
+  /// Sets special task reduction descriptor.
+  void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; }
+
+public:
+  /// Creates directive with a list of \a Clauses.
+  ///
+  /// \param C AST context.
+  /// \param StartLoc Starting location of the directive kind.
+  /// \param EndLoc Ending Location of the directive.
+  /// \param Clauses List of clauses.
+  /// \param AssociatedStmt Statement, associated with the directive.
+  /// \param TaskRedRef Task reduction special reference expression to handle
+  /// taskgroup descriptor.
+  ///
+  static OMPParallelMaskedDirective *
+  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
+         ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef);
+
+  /// Creates an empty directive with the place for \a NumClauses
+  /// clauses.
+  ///
+  /// \param C AST context.
+  /// \param NumClauses Number of clauses.
+  ///
+  static OMPParallelMaskedDirective *
+  CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell);
+
+  /// Returns special task reduction reference expression.
+  Expr *getTaskReductionRefExpr() {
+    return cast_or_null<Expr>(Data->getChildren()[0]);
+  }
+  const Expr *getTaskReductionRefExpr() const {
+    return const_cast<OMPParallelMaskedDirective *>(this)
+        ->getTaskReductionRefExpr();
+  }
+
+  static bool classof(const Stmt *T) {
+    return T->getStmtClass() == OMPParallelMaskedDirectiveClass;
+  }
+};
+
 /// This represents '#pragma omp parallel sections' directive.
 ///
 /// \code

diff  --git a/clang/include/clang/Basic/StmtNodes.td b/clang/include/clang/Basic/StmtNodes.td
index 1954bb464d959..9ba6e6fa50df8 100644
--- a/clang/include/clang/Basic/StmtNodes.td
+++ b/clang/include/clang/Basic/StmtNodes.td
@@ -282,6 +282,7 @@ def OMPTargetTeamsDistributeSimdDirective : StmtNode<OMPLoopDirective>;
 def OMPInteropDirective : StmtNode<OMPExecutableDirective>;
 def OMPDispatchDirective : StmtNode<OMPExecutableDirective>;
 def OMPMaskedDirective : StmtNode<OMPExecutableDirective>;
+def OMPParallelMaskedDirective : StmtNode<OMPExecutableDirective>;
 def OMPGenericLoopDirective : StmtNode<OMPLoopDirective>;
 def OMPTeamsGenericLoopDirective : StmtNode<OMPLoopDirective>;
 def OMPTargetTeamsGenericLoopDirective : StmtNode<OMPLoopDirective>;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 8a604f6c2a9f3..7314a60d3a44f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10942,6 +10942,12 @@ class Sema final {
                                                 Stmt *AStmt,
                                                 SourceLocation StartLoc,
                                                 SourceLocation EndLoc);
+  /// Called on well-formed '\#pragma omp parallel masked' after
+  /// parsing of the associated statement.
+  StmtResult ActOnOpenMPParallelMaskedDirective(ArrayRef<OMPClause *> Clauses,
+                                                Stmt *AStmt,
+                                                SourceLocation StartLoc,
+                                                SourceLocation EndLoc);
   /// Called on well-formed '\#pragma omp parallel sections' after
   /// parsing of the  associated statement.
   StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses,

diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h
index 2f699ab943fb4..33b787a83e137 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1922,6 +1922,7 @@ enum StmtCode {
   STMT_OMP_PARALLEL_FOR_DIRECTIVE,
   STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE,
   STMT_OMP_PARALLEL_MASTER_DIRECTIVE,
+  STMT_OMP_PARALLEL_MASKED_DIRECTIVE,
   STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE,
   STMT_OMP_TASK_DIRECTIVE,
   STMT_OMP_TASKYIELD_DIRECTIVE,

diff  --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp
index 74d1020e15b66..c3dd47cdea9bd 100644
--- a/clang/lib/AST/StmtOpenMP.cpp
+++ b/clang/lib/AST/StmtOpenMP.cpp
@@ -682,6 +682,22 @@ OMPParallelMasterDirective::CreateEmpty(const ASTContext &C,
       C, NumClauses, /*HasAssociatedStmt=*/true, /*NumChildren=*/1);
 }
 
+OMPParallelMaskedDirective *OMPParallelMaskedDirective::Create(
+    const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
+    ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef) {
+  auto *Dir = createDirective<OMPParallelMaskedDirective>(
+      C, Clauses, AssociatedStmt, /*NumChildren=*/1, StartLoc, EndLoc);
+  Dir->setTaskReductionRefExpr(TaskRedRef);
+  return Dir;
+}
+
+OMPParallelMaskedDirective *
+OMPParallelMaskedDirective::CreateEmpty(const ASTContext &C,
+                                        unsigned NumClauses, EmptyShell) {
+  return createEmptyDirective<OMPParallelMaskedDirective>(
+      C, NumClauses, /*HasAssociatedStmt=*/true, /*NumChildren=*/1);
+}
+
 OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create(
     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
     ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef,

diff  --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index 7552e0481e940..180155402d9de 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -749,6 +749,12 @@ void StmtPrinter::VisitOMPParallelMasterDirective(
   PrintOMPExecutableDirective(Node);
 }
 
+void StmtPrinter::VisitOMPParallelMaskedDirective(
+    OMPParallelMaskedDirective *Node) {
+  Indent() << "#pragma omp parallel masked";
+  PrintOMPExecutableDirective(Node);
+}
+
 void StmtPrinter::VisitOMPParallelSectionsDirective(
     OMPParallelSectionsDirective *Node) {
   Indent() << "#pragma omp parallel sections";

diff  --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 77d5d95a1ad10..858d483a890dd 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -988,6 +988,11 @@ void StmtProfiler::VisitOMPParallelMasterDirective(
   VisitOMPExecutableDirective(S);
 }
 
+void StmtProfiler::VisitOMPParallelMaskedDirective(
+    const OMPParallelMaskedDirective *S) {
+  VisitOMPExecutableDirective(S);
+}
+
 void StmtProfiler::VisitOMPParallelSectionsDirective(
     const OMPParallelSectionsDirective *S) {
   VisitOMPExecutableDirective(S);

diff  --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 7b1086330f1e3..54460981c8f7e 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -535,7 +535,7 @@ bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
          DKind == OMPD_teams_distribute_parallel_for_simd ||
          DKind == OMPD_target_teams_distribute_parallel_for ||
          DKind == OMPD_target_teams_distribute_parallel_for_simd ||
-         DKind == OMPD_parallel_master ||
+         DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
          DKind == OMPD_parallel_master_taskloop ||
          DKind == OMPD_parallel_master_taskloop_simd ||
          DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
@@ -652,6 +652,7 @@ void clang::getOpenMPCaptureRegions(
   case OMPD_parallel_for:
   case OMPD_parallel_for_simd:
   case OMPD_parallel_master:
+  case OMPD_parallel_masked:
   case OMPD_parallel_sections:
   case OMPD_distribute_parallel_for:
   case OMPD_distribute_parallel_for_simd:

diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 43a9919c66add..2412c91d16fbb 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -408,6 +408,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs) {
   case Stmt::OMPTargetParallelGenericLoopDirectiveClass:
     llvm_unreachable("target parallel loop directive not supported yet.");
     break;
+  case Stmt::OMPParallelMaskedDirectiveClass:
+    llvm_unreachable("parallel masked directive not supported yet.");
+    break;
   }
 }
 

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index e8d0c1528b526..4641721d97e27 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -180,6 +180,7 @@ static OpenMPDirectiveKindExWrapper parseOpenMPDirectiveKind(Parser &P) {
       {OMPD_master, OMPD_taskloop, OMPD_master_taskloop},
       {OMPD_master_taskloop, OMPD_simd, OMPD_master_taskloop_simd},
       {OMPD_parallel, OMPD_master, OMPD_parallel_master},
+      {OMPD_parallel, OMPD_masked, OMPD_parallel_masked},
       {OMPD_parallel_master, OMPD_taskloop, OMPD_parallel_master_taskloop},
       {OMPD_parallel_master_taskloop, OMPD_simd,
        OMPD_parallel_master_taskloop_simd}};
@@ -2367,6 +2368,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
   case OMPD_parallel_for_simd:
   case OMPD_parallel_sections:
   case OMPD_parallel_master:
+  case OMPD_parallel_masked:
   case OMPD_atomic:
   case OMPD_target:
   case OMPD_teams:
@@ -2762,6 +2764,7 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
   case OMPD_parallel_for_simd:
   case OMPD_parallel_sections:
   case OMPD_parallel_master:
+  case OMPD_parallel_masked:
   case OMPD_task:
   case OMPD_ordered:
   case OMPD_atomic:

diff  --git a/clang/lib/Sema/SemaExceptionSpec.cpp b/clang/lib/Sema/SemaExceptionSpec.cpp
index 207bde0b05440..eee283d74ae01 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -1460,6 +1460,7 @@ CanThrowResult Sema::canThrow(const Stmt *S) {
   case Stmt::OMPParallelForDirectiveClass:
   case Stmt::OMPParallelForSimdDirectiveClass:
   case Stmt::OMPParallelMasterDirectiveClass:
+  case Stmt::OMPParallelMaskedDirectiveClass:
   case Stmt::OMPParallelMasterTaskLoopDirectiveClass:
   case Stmt::OMPParallelMasterTaskLoopSimdDirectiveClass:
   case Stmt::OMPParallelSectionsDirectiveClass:

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 0615c81bff4ae..4c61782e065bb 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -3971,6 +3971,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) {
   case OMPD_parallel_for_simd:
   case OMPD_parallel_sections:
   case OMPD_parallel_master:
+  case OMPD_parallel_masked:
   case OMPD_parallel_loop:
   case OMPD_teams:
   case OMPD_teams_distribute:
@@ -4912,6 +4913,7 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
           isOpenMPTaskingDirective(ParentRegion) ||
           ParentRegion == OMPD_master || ParentRegion == OMPD_masked ||
           ParentRegion == OMPD_parallel_master ||
+          ParentRegion == OMPD_parallel_masked ||
           ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered;
     } else if (isOpenMPWorksharingDirective(CurrentRegion) &&
                !isOpenMPParallelDirective(CurrentRegion) &&
@@ -4926,6 +4928,7 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
           isOpenMPTaskingDirective(ParentRegion) ||
           ParentRegion == OMPD_master || ParentRegion == OMPD_masked ||
           ParentRegion == OMPD_parallel_master ||
+          ParentRegion == OMPD_parallel_masked ||
           ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered;
       Recommend = ShouldBeInParallelRegion;
     } else if (CurrentRegion == OMPD_ordered) {
@@ -6116,6 +6119,11 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
                                              StartLoc, EndLoc);
     AllowedNameModifiers.push_back(OMPD_parallel);
     break;
+  case OMPD_parallel_masked:
+    Res = ActOnOpenMPParallelMaskedDirective(ClausesWithImplicit, AStmt,
+                                             StartLoc, EndLoc);
+    AllowedNameModifiers.push_back(OMPD_parallel);
+    break;
   case OMPD_parallel_sections:
     Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt,
                                                StartLoc, EndLoc);
@@ -10697,6 +10705,29 @@ Sema::ActOnOpenMPParallelMasterDirective(ArrayRef<OMPClause *> Clauses,
       DSAStack->getTaskgroupReductionRef());
 }
 
+StmtResult
+Sema::ActOnOpenMPParallelMaskedDirective(ArrayRef<OMPClause *> Clauses,
+                                         Stmt *AStmt, SourceLocation StartLoc,
+                                         SourceLocation EndLoc) {
+  if (!AStmt)
+    return StmtError();
+
+  assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
+  auto *CS = cast<CapturedStmt>(AStmt);
+  // 1.2.2 OpenMP Language Terminology
+  // Structured block - An executable statement with a single entry at the
+  // top and a single exit at the bottom.
+  // The point of exit cannot be a branch out of the structured block.
+  // longjmp() and throw() must not violate the entry/exit criteria.
+  CS->getCapturedDecl()->setNothrow();
+
+  setFunctionHasBranchProtectedScope();
+
+  return OMPParallelMaskedDirective::Create(
+      Context, StartLoc, EndLoc, Clauses, AStmt,
+      DSAStack->getTaskgroupReductionRef());
+}
+
 StmtResult
 Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses,
                                            Stmt *AStmt, SourceLocation StartLoc,
@@ -14823,6 +14854,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
     case OMPD_cancel:
     case OMPD_parallel:
     case OMPD_parallel_master:
+    case OMPD_parallel_masked:
     case OMPD_parallel_sections:
     case OMPD_parallel_for:
     case OMPD_parallel_loop:
@@ -14898,6 +14930,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
       break;
     case OMPD_parallel:
     case OMPD_parallel_master:
+    case OMPD_parallel_masked:
     case OMPD_parallel_sections:
     case OMPD_parallel_for:
     case OMPD_parallel_for_simd:
@@ -15004,6 +15037,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
     case OMPD_cancel:
     case OMPD_parallel:
     case OMPD_parallel_master:
+    case OMPD_parallel_masked:
     case OMPD_parallel_sections:
     case OMPD_parallel_for:
     case OMPD_parallel_for_simd:
@@ -15090,6 +15124,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
     case OMPD_cancel:
     case OMPD_parallel:
     case OMPD_parallel_master:
+    case OMPD_parallel_masked:
     case OMPD_parallel_sections:
     case OMPD_parallel_for:
     case OMPD_parallel_for_simd:
@@ -15182,6 +15217,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
     case OMPD_cancel:
     case OMPD_parallel:
     case OMPD_parallel_master:
+    case OMPD_parallel_masked:
     case OMPD_parallel_sections:
     case OMPD_threadprivate:
     case OMPD_allocate:
@@ -15268,6 +15304,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
     case OMPD_cancel:
     case OMPD_parallel:
     case OMPD_parallel_master:
+    case OMPD_parallel_masked:
     case OMPD_parallel_sections:
     case OMPD_threadprivate:
     case OMPD_allocate:
@@ -15355,6 +15392,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
     case OMPD_cancel:
     case OMPD_parallel:
     case OMPD_parallel_master:
+    case OMPD_parallel_masked:
     case OMPD_parallel_sections:
     case OMPD_parallel_for:
     case OMPD_parallel_for_simd:
@@ -15441,6 +15479,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause(
     case OMPD_cancel:
     case OMPD_parallel:
     case OMPD_parallel_master:
+    case OMPD_parallel_masked:
     case OMPD_parallel_sections:
     case OMPD_parallel_for:
     case OMPD_parallel_for_simd:

diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index fae712e04db86..03f147480421a 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -8772,6 +8772,17 @@ StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective(
   return Res;
 }
 
+template <typename Derived>
+StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedDirective(
+    OMPParallelMaskedDirective *D) {
+  DeclarationNameInfo DirName;
+  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_masked, DirName,
+                                             nullptr, D->getBeginLoc());
+  StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
+  getDerived().getSema().EndOpenMPDSABlock(Res.get());
+  return Res;
+}
+
 template <typename Derived>
 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
     OMPParallelSectionsDirective *D) {

diff  --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index bb324a76020c7..d7980c2c69482 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2371,6 +2371,12 @@ void ASTStmtReader::VisitOMPParallelMasterDirective(
   VisitOMPExecutableDirective(D);
 }
 
+void ASTStmtReader::VisitOMPParallelMaskedDirective(
+    OMPParallelMaskedDirective *D) {
+  VisitStmt(D);
+  VisitOMPExecutableDirective(D);
+}
+
 void ASTStmtReader::VisitOMPParallelSectionsDirective(
     OMPParallelSectionsDirective *D) {
   VisitStmt(D);
@@ -3297,6 +3303,11 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
           Context, Record[ASTStmtReader::NumStmtFields], Empty);
       break;
 
+    case STMT_OMP_PARALLEL_MASKED_DIRECTIVE:
+      S = OMPParallelMaskedDirective::CreateEmpty(
+          Context, Record[ASTStmtReader::NumStmtFields], Empty);
+      break;
+
     case STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE:
       S = OMPParallelSectionsDirective::CreateEmpty(
           Context, Record[ASTStmtReader::NumStmtFields], Empty);

diff  --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index cd4b84421a28c..f734998e6e495 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -2298,6 +2298,13 @@ void ASTStmtWriter::VisitOMPParallelMasterDirective(
   Code = serialization::STMT_OMP_PARALLEL_MASTER_DIRECTIVE;
 }
 
+void ASTStmtWriter::VisitOMPParallelMaskedDirective(
+    OMPParallelMaskedDirective *D) {
+  VisitStmt(D);
+  VisitOMPExecutableDirective(D);
+  Code = serialization::STMT_OMP_PARALLEL_MASKED_DIRECTIVE;
+}
+
 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
     OMPParallelSectionsDirective *D) {
   VisitStmt(D);

diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 9e97d711d46ad..a0c7dda896ef2 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1238,6 +1238,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
     case Stmt::OMPParallelForSimdDirectiveClass:
     case Stmt::OMPParallelSectionsDirectiveClass:
     case Stmt::OMPParallelMasterDirectiveClass:
+    case Stmt::OMPParallelMaskedDirectiveClass:
     case Stmt::OMPTaskDirectiveClass:
     case Stmt::OMPTaskyieldDirectiveClass:
     case Stmt::OMPBarrierDirectiveClass:

diff  --git a/clang/test/Analysis/cfg-openmp.cpp b/clang/test/Analysis/cfg-openmp.cpp
index 4a6923a855ca0..7a263463c0919 100644
--- a/clang/test/Analysis/cfg-openmp.cpp
+++ b/clang/test/Analysis/cfg-openmp.cpp
@@ -893,4 +893,18 @@ void targetparallelloop(int argc) {
     argc = x;
 }
 
+// CHECK-LABEL:  void parallelmasked(int argc)
+void parallelmasked(int argc) {
+  int x = 0;
+// CHECK:        [B1]
+// CHECK-NEXT:   1: 0
+// CHECK-NEXT:   2: int x = 0;
+// CHECK-NEXT:   [[#MASKED:]]: x
+// CHECK-NEXT:   [[#MASKED+1]]: [B1.[[#MASKED]]] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   [[#MASKED+2]]: argc
+// CHECK-NEXT:   [[#MASKED+3]]: [B1.[[#MASKED+2]]] = [B1.[[#MASKED+1]]]
+// CHECK-NEXT:   [[#MASKED+4]]: #pragma omp parallel masked
+#pragma omp parallel masked
+  argc = x;
+}
 #endif  // _OPENMP

diff  --git a/clang/test/OpenMP/nesting_of_regions.cpp b/clang/test/OpenMP/nesting_of_regions.cpp
index 3581b05e3a043..6973f63bd9567 100644
--- a/clang/test/OpenMP/nesting_of_regions.cpp
+++ b/clang/test/OpenMP/nesting_of_regions.cpp
@@ -69,6 +69,11 @@ void foo() {
     bar();
   }
 #pragma omp parallel
+#pragma omp parallel masked
+  {
+    bar();
+  }
+#pragma omp parallel
 #pragma omp task
   {
     bar();
@@ -321,6 +326,13 @@ void foo() {
   }
 #pragma omp simd
   for (int i = 0; i < 10; ++i) {
+#pragma omp parallel masked // 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();
@@ -595,6 +607,13 @@ void foo() {
   }
 #pragma omp for
   for (int i = 0; i < 10; ++i) {
+#pragma omp parallel masked
+    {
+      bar();
+    }
+  }
+#pragma omp for
+  for (int i = 0; i < 10; ++i) {
 #pragma omp parallel sections
     {
       bar();
@@ -853,6 +872,13 @@ void foo() {
   }
 #pragma omp for simd
   for (int i = 0; i < 10; ++i) {
+#pragma omp parallel masked // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp 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();
@@ -1101,6 +1127,13 @@ void foo() {
   }
 #pragma omp sections
   {
+#pragma omp parallel masked
+    {
+      bar();
+    }
+  }
+#pragma omp sections
+  {
 #pragma omp parallel
     {
 #pragma omp master // OK
@@ -1391,6 +1424,16 @@ void foo() {
   {
 #pragma omp section
     {
+#pragma omp parallel masked
+      bar();
+#pragma omp critical
+      bar();
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
 #pragma omp single // expected-error {{region cannot be closely nested inside 'section' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}}
       bar();
 #pragma omp master // expected-error {{region cannot be closely nested inside 'section' region}}
@@ -1718,6 +1761,13 @@ void foo() {
   }
 #pragma omp single
   {
+#pragma omp parallel masked
+    {
+      bar();
+    }
+  }
+#pragma omp single
+  {
 #pragma omp critical
     {
       bar();
@@ -2299,6 +2349,13 @@ void foo() {
   }
 #pragma omp critical
   {
+#pragma omp parallel masked
+    {
+      bar();
+    }
+  }
+#pragma omp critical
+  {
 #pragma omp parallel for
     for (int i = 0; i < 10; ++i)
       ;
@@ -3327,6 +3384,285 @@ void foo() {
       ;
   }
 
+// PARALLEL MASKED DIRECTIVE
+#pragma omp parallel masked
+  {
+#pragma omp for // expected-error {{region cannot be closely nested inside 'parallel masked' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel masked
+  {
+#pragma omp simd
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel masked
+  {
+#pragma omp for simd // expected-error {{region cannot be closely nested inside 'parallel masked' region; perhaps you forget to enclose 'omp for simd' directive into a parallel region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel masked
+  {
+#pragma omp parallel
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel masked
+  {
+#pragma omp single // expected-error {{region cannot be closely nested inside 'parallel masked' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}}
+    {
+      bar();
+    }
+  }
+#pragma omp parallel masked
+  {
+#pragma omp master // OK, though second 'master' is redundant
+    {
+      bar();
+    }
+  }
+#pragma omp parallel masked
+  {
+#pragma omp critical
+    {
+      bar();
+    }
+  }
+#pragma omp parallel masked
+  {
+#pragma omp sections // expected-error {{region cannot be closely nested inside 'parallel masked' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}}
+    {
+      bar();
+    }
+  }
+#pragma omp parallel master
+  {
+#pragma omp parallel
+    {
+#pragma omp parallel master // OK
+      {
+        bar();
+      }
+#pragma omp for // OK
+      for (int i = 0; i < 10; ++i)
+        ;
+#pragma omp for simd // OK
+      for (int i = 0; i < 10; ++i)
+        ;
+#pragma omp sections // OK
+      {
+        bar();
+      }
+    }
+  }
+#pragma omp parallel master
+  {
+#pragma omp parallel master // OK
+      {
+        bar();
+      }
+#pragma omp parallel
+    {
+#pragma omp for // OK
+      for (int i = 0; i < 10; ++i)
+        ;
+#pragma omp for simd // OK
+      for (int i = 0; i < 10; ++i)
+        ;
+#pragma omp sections // OK
+      {
+        bar();
+      }
+    }
+  }
+#pragma omp parallel master
+  {
+#pragma omp parallel for
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel master
+  {
+#pragma omp parallel for simd
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel master
+  {
+#pragma omp parallel sections
+    {
+      bar();
+    }
+  }
+#pragma omp parallel master
+  {
+#pragma omp task
+    {
+      bar();
+    }
+  }
+#pragma omp parallel master
+  {
+#pragma omp taskyield
+    bar();
+  }
+#pragma omp parallel master
+  {
+#pragma omp barrier // expected-error {{region cannot be closely nested inside 'parallel master' region}}
+    bar();
+  }
+#pragma omp parallel master
+  {
+#pragma omp scan // expected-error {{region cannot be closely nested inside 'parallel master' region}}
+    bar();
+  }
+#pragma omp parallel master
+  {
+#pragma omp taskwait
+    bar();
+  }
+#pragma omp parallel master
+  {
+#pragma omp flush
+    bar();
+  }
+#pragma omp parallel master
+  {
+#pragma omp ordered // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
+    bar();
+  }
+#pragma omp parallel master
+  {
+#pragma omp atomic
+    ++a;
+  }
+#pragma omp parallel master
+  {
+#pragma omp target
+    ++a;
+  }
+#pragma omp parallel master
+  {
+#pragma omp target parallel
+    ++a;
+  }
+#pragma omp parallel master
+  {
+#pragma omp target parallel for
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel master
+  {
+#pragma omp target enter data map(to: a)
+    ++a;
+  }
+#pragma omp parallel master
+  {
+#pragma omp target exit data map(from: a)
+    ++a;
+  }
+#pragma omp parallel master
+  {
+#pragma omp teams // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp teams' directive into a target region?}}
+    ++a;
+  }
+#pragma omp parallel master
+  {
+#pragma omp taskloop
+  for (int i = 0; i < 10; ++i)
+    ++a;
+  }
+#pragma omp parallel master
+  {
+#pragma omp distribute // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp distribute' directive into a teams region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel master
+  {
+#pragma omp target update to(a)
+    bar();
+  }
+#pragma omp parallel master
+  {
+#pragma omp distribute parallel for // expected-error {{region cannot be closely nested inside 'parallel master' 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 master
+  {
+#pragma omp distribute parallel for simd // expected-error {{region cannot be closely nested inside 'parallel master' 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 master
+  {
+#pragma omp distribute simd // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp distribute simd' directive into a teams region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel master
+  {
+#pragma omp target simd // OK
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel master
+  {
+#pragma omp teams distribute // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp teams distribute' directive into a target region?}}
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel master
+  {
+#pragma omp teams distribute simd // expected-error {{region cannot be closely nested inside 'parallel master' 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 master
+  {
+#pragma omp teams distribute parallel for simd // expected-error {{region cannot be closely nested inside 'parallel master' 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 master
+  {
+#pragma omp teams distribute parallel for // expected-error {{region cannot be closely nested inside 'parallel master' 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 master
+  {
+#pragma omp target teams // OK
+    a++;
+  }
+#pragma omp parallel master
+  {
+#pragma omp target teams distribute // OK
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel master
+  {
+#pragma omp target teams distribute parallel for // OK
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel master
+  {
+#pragma omp target teams distribute parallel for simd // OK
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+#pragma omp parallel master
+  {
+#pragma omp target teams distribute simd // OK
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
 // PARALLEL SECTIONS DIRECTIVE
 #pragma omp parallel sections
   {
@@ -4162,6 +4498,15 @@ void foo() {
   // 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 parallel masked // expected-error {{OpenMP constructs may not be nested inside an atomic region}}
+    {
+      bar();
+    }
+  }
+#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 critical // expected-error {{OpenMP constructs may not be nested inside an atomic region}}
     {
       bar();
@@ -4694,6 +5039,11 @@ void foo() {
   {
     bar();
   }
+#pragma omp target
+#pragma omp parallel masked
+  {
+    bar();
+  }
 #pragma omp target parallel
 #pragma omp critical
   {
@@ -9591,6 +9941,8 @@ void foo() {
   bar();
 #pragma omp parallel master
   bar();
+#pragma omp parallel masked
+  bar();
 #pragma omp parallel
 #pragma omp critical
   bar();

diff  --git a/clang/test/OpenMP/parallel_masked_ast_print.cpp b/clang/test/OpenMP/parallel_masked_ast_print.cpp
new file mode 100644
index 0000000000000..3532cf61ec25f
--- /dev/null
+++ b/clang/test/OpenMP/parallel_masked_ast_print.cpp
@@ -0,0 +1,224 @@
+// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+void foo() {}
+
+struct S1 {
+  S1(): a(0) {}
+  S1(int v) : a(v) {}
+  int a;
+  typedef int type;
+  S1& operator +(const S1&);
+  S1& operator *(const S1&);
+  S1& operator &&(const S1&);
+  S1& operator ^(const S1&);
+};
+
+template <typename T>
+class S7 : public T {
+protected:
+  T a;
+  T b[100];
+  S7() : a(0) {}
+
+public:
+  S7(typename T::type v) : a(v) {
+    int tid = 0;
+// CHECK: #pragma omp parallel masked filter(tid) private(this->a) private(this->a) private(T::a)
+#pragma omp parallel masked filter(tid) private(a) private(this->a) private(T::a)
+    for (int k = 0; k < a.a; ++k)
+      ++this->a.a;
+// CHECK: #pragma omp parallel masked filter(tid) firstprivate(this->a) firstprivate(this->a) firstprivate(T::a)
+#pragma omp parallel masked filter(tid) firstprivate(a) firstprivate(this->a) firstprivate(T::a)
+    for (int k = 0; k < a.a; ++k)
+      ++this->a.a;
+// CHECK: #pragma omp parallel masked filter(tid) shared(this->a) shared(this->a) shared(T::a)
+#pragma omp parallel masked filter(tid) shared(a) shared(this->a) shared(T::a)
+    for (int k = 0; k < a.a; ++k)
+      ++this->a.a;
+// CHECK: #pragma omp parallel masked filter(tid) reduction(+: this->a) reduction(*: this->b[:])
+#pragma omp parallel masked filter(tid) reduction(+ : a) reduction(*: b[:])
+    for (int k = 0; k < a.a; ++k)
+      ++this->a.a;
+  }
+  S7 &operator=(S7 &s) {
+    int tid = 0;
+// CHECK: #pragma omp parallel masked filter(tid) private(this->a) private(this->a)
+#pragma omp parallel masked filter(tid) private(a) private(this->a)
+    for (int k = 0; k < s.a.a; ++k)
+      ++s.a.a;
+// CHECK: #pragma omp parallel masked filter(tid) firstprivate(this->a) firstprivate(this->a)
+#pragma omp parallel masked filter(tid) firstprivate(a) firstprivate(this->a)
+    for (int k = 0; k < s.a.a; ++k)
+      ++s.a.a;
+// CHECK: #pragma omp parallel masked filter(tid) shared(this->a) shared(this->a)
+#pragma omp parallel masked filter(tid) shared(a) shared(this->a)
+    for (int k = 0; k < s.a.a; ++k)
+      ++s.a.a;
+// CHECK: #pragma omp parallel masked filter(tid) reduction(&&: this->a) reduction(^: this->b[s.a.a])
+#pragma omp parallel masked filter(tid) reduction(&& : this->a) reduction(^: b[s.a.a])
+    for (int k = 0; k < s.a.a; ++k)
+      ++s.a.a;
+    return *this;
+  }
+};
+
+// CHECK: #pragma omp parallel masked filter(tid) private(this->a) private(this->a) private(this->S1::a)
+// CHECK: #pragma omp parallel masked filter(tid) firstprivate(this->a) firstprivate(this->a) firstprivate(this->S1::a)
+// CHECK: #pragma omp parallel masked filter(tid) shared(this->a) shared(this->a) shared(this->S1::a)
+// CHECK: #pragma omp parallel masked filter(tid) reduction(+: this->a) reduction(*: this->b[:])
+
+class S8 : public S7<S1> {
+  S8() {}
+
+public:
+  S8(int v) : S7<S1>(v){
+// CHECK: #pragma omp parallel masked private(this->a) private(this->a) private(this->S7<S1>::a)
+#pragma omp parallel masked private(a) private(this->a) private(S7 < S1 > ::a)
+    for (int k = 0; k < a.a; ++k)
+      ++this->a.a;
+// CHECK: #pragma omp parallel masked firstprivate(this->a) firstprivate(this->a) firstprivate(this->S7<S1>::a)
+#pragma omp parallel masked firstprivate(a) firstprivate(this->a) firstprivate(S7 < S1 > ::a)
+    for (int k = 0; k < a.a; ++k)
+      ++this->a.a;
+// CHECK: #pragma omp parallel masked shared(this->a) shared(this->a) shared(this->S7<S1>::a)
+#pragma omp parallel masked shared(a) shared(this->a) shared(S7 < S1 > ::a)
+    for (int k = 0; k < a.a; ++k)
+      ++this->a.a;
+// CHECK: #pragma omp parallel masked reduction(^: this->S7<S1>::a) reduction(+: this->S7<S1>::b[:this->S7<S1>::a.a])
+#pragma omp parallel masked reduction(^ : S7 < S1 > ::a) reduction(+ : S7 < S1 > ::b[ : S7 < S1 > ::a.a])
+    for (int k = 0; k < a.a; ++k)
+      ++this->a.a;
+  }
+  S8 &operator=(S8 &s) {
+// CHECK: #pragma omp parallel masked private(this->a) private(this->a)
+#pragma omp parallel masked private(a) private(this->a)
+    for (int k = 0; k < s.a.a; ++k)
+      ++s.a.a;
+// CHECK: #pragma omp parallel masked firstprivate(this->a) firstprivate(this->a)
+#pragma omp parallel masked firstprivate(a) firstprivate(this->a)
+    for (int k = 0; k < s.a.a; ++k)
+      ++s.a.a;
+// CHECK: #pragma omp parallel masked shared(this->a) shared(this->a)
+#pragma omp parallel masked shared(a) shared(this->a)
+    for (int k = 0; k < s.a.a; ++k)
+      ++s.a.a;
+// CHECK: #pragma omp parallel masked reduction(*: this->a) reduction(&&: this->b[this->a.a:])
+#pragma omp parallel masked reduction(* : this->a) reduction(&&:this->b[a.a:])
+    for (int k = 0; k < s.a.a; ++k)
+      ++s.a.a;
+    return *this;
+  }
+};
+
+
+template <class T>
+struct S {
+  operator T() {return T();}
+  static T TS;
+  #pragma omp threadprivate(TS)
+};
+
+// CHECK:      template <class T> struct S {
+// CHECK:        static T TS;
+// CHECK-NEXT:   #pragma omp threadprivate(S::TS)
+// CHECK:      };
+// CHECK:      template<> struct S<int> {
+// CHECK:        static int TS;
+// CHECK-NEXT:   #pragma omp threadprivate(S<int>::TS)
+// CHECK-NEXT: }
+// CHECK:      template<> struct S<long> {
+// CHECK:        static long TS;
+// CHECK-NEXT:   #pragma omp threadprivate(S<long>::TS)
+// CHECK-NEXT: }
+
+int thrp;
+#pragma omp threadprivate(thrp)
+
+template <typename T, int C>
+T tmain(T argc, T *argv) {
+  T b = argc, c, d, e, f, g;
+  static T a;
+  S<T> s;
+  T arr[C][10], arr1[C];
+#pragma omp parallel masked
+  a=2;
+#pragma omp parallel masked default(none), private(argc,b) firstprivate(argv) shared (d) if (parallel:argc > 0) num_threads(C) copyin(S<T>::TS, thrp) proc_bind(master) reduction(+:c, arr1[argc]) reduction(max:e, arr[:C][0:10])
+  foo();
+#pragma omp parallel masked if (C) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:C][:argc]) reduction(task, && : g)
+  foo();
+  return 0;
+}
+
+// CHECK: template <typename T, int C> T tmain(T argc, T *argv) {
+// CHECK-NEXT: T b = argc, c, d, e, f, g;
+// CHECK-NEXT: static T a;
+// CHECK-NEXT: S<T> s;
+// CHECK-NEXT: T arr[C][10], arr1[C];
+// CHECK-NEXT: #pragma omp parallel masked
+// CHECK-NEXT: a = 2;
+// CHECK-NEXT: #pragma omp parallel masked default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(C) copyin(S<T>::TS,thrp) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:C][0:10])
+// CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp parallel masked if(C) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:C][:argc]) reduction(task, &&: g)
+// CHECK-NEXT: foo()
+// CHECK: template<> int tmain<int, 5>(int argc, int *argv) {
+// CHECK-NEXT: int b = argc, c, d, e, f, g;
+// CHECK-NEXT: static int a;
+// CHECK-NEXT: S<int> s;
+// CHECK-NEXT: int arr[5][10], arr1[5];
+// CHECK-NEXT: #pragma omp parallel masked
+// CHECK-NEXT: a = 2;
+// CHECK-NEXT: #pragma omp parallel masked default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(5) copyin(S<int>::TS,thrp) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:5][0:10])
+// CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp parallel masked if(5) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:5][:argc]) reduction(task, &&: g)
+// CHECK-NEXT: foo()
+// CHECK: template<> long tmain<long, 1>(long argc, long *argv) {
+// CHECK-NEXT: long b = argc, c, d, e, f, g;
+// CHECK-NEXT: static long a;
+// CHECK-NEXT: S<long> s;
+// CHECK-NEXT: long arr[1][10], arr1[1];
+// CHECK-NEXT: #pragma omp parallel masked
+// CHECK-NEXT: a = 2;
+// CHECK-NEXT: #pragma omp parallel masked default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(1) copyin(S<long>::TS,thrp) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:1][0:10])
+// CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp parallel masked if(1) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:1][:argc]) reduction(task, &&: g)
+// CHECK-NEXT: foo()
+
+enum Enum { };
+
+int main (int argc, char **argv) {
+  long x;
+  int b = argc, c, d, e, f, g;
+  static int a;
+  #pragma omp threadprivate(a)
+  int arr[10][argc], arr1[2];
+  Enum ee;
+// CHECK: Enum ee;
+#pragma omp parallel masked
+// CHECK-NEXT: #pragma omp parallel masked
+  a=2;
+// CHECK-NEXT: a = 2;
+#pragma omp parallel masked default(none), private(argc,b) firstprivate(argv) if (parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(| : c, d, arr1[argc]) reduction(* : e, arr[:10][0:argc]) allocate(e)
+// CHECK-NEXT: #pragma omp parallel masked default(none) private(argc,b) firstprivate(argv) if(parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(|: c,d,arr1[argc]) reduction(*: e,arr[:10][0:argc]) allocate(e)
+  foo();
+// CHECK-NEXT: foo();
+// CHECK-NEXT: #pragma omp parallel masked allocate(e) if(b) num_threads(c) proc_bind(close) reduction(^: e,f) reduction(&&: g,arr[0:argc][:10])
+// CHECK-NEXT: foo()
+#pragma omp parallel masked allocate(e) if (b) num_threads(c) proc_bind(close) reduction(^:e, f) reduction(&& : g, arr[0:argc][:10])
+  foo();
+  return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);
+}
+
+template<typename T>
+T S<T>::TS = 0;
+
+#endif

diff  --git a/clang/test/OpenMP/parallel_masked_copyin_messages.cpp b/clang/test/OpenMP/parallel_masked_copyin_messages.cpp
new file mode 100644
index 0000000000000..81b6d07c3e62d
--- /dev/null
+++ b/clang/test/OpenMP/parallel_masked_copyin_messages.cpp
@@ -0,0 +1,115 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized
+
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+struct S1; // expected-note {{declared here}}
+class S2 {
+  mutable int a;
+
+public:
+  S2() : a(0) {}
+  S2 &operator=(S2 &s2) { return *this; }
+};
+class S3 {
+  int a;
+
+public:
+  S3() : a(0) {}
+  S3 &operator=(S3 &s3) { return *this; }
+};
+class S4 {
+  int a;
+  S4();
+  S4 &operator=(const S4 &s4); // expected-note {{implicitly declared private here}}
+
+public:
+  S4(int v) : a(v) {}
+};
+class S5 {
+  int a;
+  S5() : a(0) {}
+  S5 &operator=(const S5 &s5) { return *this; } // expected-note {{implicitly declared private here}}
+
+public:
+  S5(int v) : a(v) {}
+};
+template <class T>
+class ST {
+public:
+  static T s;
+};
+
+S2 k;
+S3 h;
+S4 l(3);
+S5 m(4);
+#pragma omp threadprivate(h, k, l, m)
+
+namespace A {
+double x;
+#pragma omp threadprivate(x)
+}
+namespace B {
+using A::x;
+}
+
+int main(int argc, char **argv) {
+  int i;
+#pragma omp parallel masked copyin // expected-error {{expected '(' after 'copyin'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyin( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyin() // expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyin(k // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyin(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyin(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyin(l) // expected-error {{'operator=' is a private member of 'S4'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyin(S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyin(argv[1]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyin(i) // expected-error {{copyin variable must be threadprivate}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyin(m) // expected-error {{'operator=' is a private member of 'S5'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyin(ST < int > ::s, B::x) // expected-error {{copyin variable must be threadprivate}}
+  {
+    foo();
+  }
+
+  return 0;
+}

diff  --git a/clang/test/OpenMP/parallel_masked_default_messages.cpp b/clang/test/OpenMP/parallel_masked_default_messages.cpp
new file mode 100644
index 0000000000000..66dfc935d2ed5
--- /dev/null
+++ b/clang/test/OpenMP/parallel_masked_default_messages.cpp
@@ -0,0 +1,63 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp -ferror-limit 100 -o - %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized
+
+void foo();
+
+namespace {
+static int y = 0;
+}
+static int x = 0;
+
+int main(int argc, char **argv) {
+#pragma omp parallel masked default // expected-error {{expected '(' after 'default'}}
+  {
+#pragma omp parallel masked default( // expected-error {{expected 'none', 'shared', 'private' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+      {
+#pragma omp parallel masked default() // expected-error {{expected 'none', 'shared', 'private' or 'firstprivate' in OpenMP clause 'default'}}
+          {
+#pragma omp parallel masked default(none // expected-error {{expected ')'}} expected-note {{to match this '('}}
+              {
+#pragma omp parallel masked default(shared), default(shared) // expected-error {{directive '#pragma omp parallel masked' cannot contain more than one 'default' clause}}
+                  {
+#pragma omp parallel masked default(x) // expected-error {{expected 'none', 'shared', 'private' or 'firstprivate' in OpenMP clause 'default'}}
+                      {foo();
+            }
+          }
+        }
+      }
+    }
+  }
+
+#pragma omp parallel masked default(none) // expected-note {{explicit data sharing attribute requested here}}
+  {
+    ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
+  }
+
+#pragma omp parallel masked default(none) // expected-note {{explicit data sharing attribute requested here}}
+  {
+#pragma omp parallel masked default(shared)
+    {
+      ++argc;  // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
+    }
+  }
+
+#ifdef OMP51
+#pragma omp parallel masked default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}}
+  {
+    ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}}
+    ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}}
+  }
+#pragma omp parallel masked default(private) // expected-note 2 {{explicit data sharing attribute requested here}}
+  {
+    ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}}
+    ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}}
+  }
+#endif
+
+  return 0;
+}

diff  --git a/clang/test/OpenMP/parallel_masked_firstprivate_messages.cpp b/clang/test/OpenMP/parallel_masked_firstprivate_messages.cpp
new file mode 100644
index 0000000000000..26ad93d6953a9
--- /dev/null
+++ b/clang/test/OpenMP/parallel_masked_firstprivate_messages.cpp
@@ -0,0 +1,320 @@
+// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
+
+extern int omp_default_mem_alloc;
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+void xxx(int argc) {
+  int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}
+#pragma omp parallel masked firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}}
+  {
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
+}
+
+struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
+extern S1 a;
+class S2 {
+  mutable int a;
+
+public:
+  S2() : a(0) {}
+  S2(const S2 &s2) : a(s2.a) {}
+  static float S2s;
+  static const float S2sc;
+};
+const float S2::S2sc = 0;
+const S2 b;
+const S2 ba[5];
+class S3 {
+  int a;
+  S3 &operator=(const S3 &s3);
+
+public:
+  S3() : a(0) {}
+  S3(const S3 &s3) : a(s3.a) {}
+};
+const S3 c;
+const S3 ca[5];
+extern const int f;
+class S4 {
+  int a;
+  S4();
+  S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
+
+public:
+  S4(int v) : a(v) {}
+};
+class S5 {
+  int a;
+  S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
+
+public:
+  S5() : a(0) {}
+  S5(int v) : a(v) {}
+};
+class S6 {
+  int a;
+  S6() : a(0) {}
+
+public:
+  S6(const S6 &s6) : a(s6.a) {}
+  S6(int v) : a(v) {}
+};
+
+S3 h;
+#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
+
+template <class I, class C>
+int foomain(int argc, char **argv) {
+  I e(4);
+  C g(5);
+  int i, z;
+  int &j = i;
+#pragma omp parallel masked firstprivate // expected-error {{expected '(' after 'firstprivate'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate() // expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(z, a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(argv[1]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
+  {
+    foo();
+  }
+#pragma omp parallel masked linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel masked'}}
+  {
+    foo();
+  }
+#pragma omp parallel
+  {
+    int v = 0;
+    int i;
+#pragma omp parallel masked firstprivate(i)
+    {
+      foo();
+    }
+    v += i;
+  }
+#pragma omp parallel shared(i)
+#pragma omp parallel private(i)
+#pragma omp parallel masked firstprivate(j)
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(i)
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
+  {
+    foo();
+  }
+#pragma omp parallel private(i)
+#pragma omp parallel masked firstprivate(i)
+  {
+    foo();
+  }
+#pragma omp parallel reduction(+ : i)
+#pragma omp parallel masked firstprivate(i)
+  {
+    foo();
+  }
+  return 0;
+}
+
+namespace A {
+double x;
+#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
+}
+namespace B {
+using A::x;
+}
+
+int main(int argc, char **argv) {
+  const int d = 5;
+  const int da[5] = {0};
+  S4 e(4);
+  S5 g(5);
+  S3 m;
+  S6 n(2);
+  int i, z;
+  int &j = i;
+#pragma omp parallel masked firstprivate // expected-error {{expected '(' after 'firstprivate'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate() // expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(argc, z)
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(argv[1]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(2 * 2) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(ba) // OK
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(ca) // OK
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(da) // OK
+  {
+    foo();
+  }
+  int xa;
+#pragma omp parallel masked firstprivate(xa) // OK
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(S2::S2s) // OK
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(S2::S2sc) // OK
+  {
+    foo();
+  }
+#pragma omp parallel masked safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp parallel masked'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(m) // OK
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
+  {
+    foo();
+  }
+#pragma omp parallel shared(xa)
+#pragma omp parallel masked firstprivate(xa) // OK: may be firstprivate
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(j)
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked firstprivate(n) // OK
+  {
+    foo();
+  }
+#pragma omp parallel
+  {
+    int v = 0;
+    int i;
+#pragma omp parallel masked firstprivate(i)
+    {
+      foo();
+    }
+    v += i;
+  }
+#pragma omp parallel private(i)
+#pragma omp parallel masked firstprivate(i)
+  {
+    foo();
+  }
+#pragma omp parallel reduction(+ : i)
+#pragma omp parallel masked firstprivate(i)
+  {
+    foo();
+  }
+  static int r;
+#pragma omp parallel masked firstprivate(r) // OK
+  {
+    foo();
+  }
+
+  return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
+}

diff  --git a/clang/test/OpenMP/parallel_masked_if_messages.cpp b/clang/test/OpenMP/parallel_masked_if_messages.cpp
new file mode 100644
index 0000000000000..27c5f381d9590
--- /dev/null
+++ b/clang/test/OpenMP/parallel_masked_if_messages.cpp
@@ -0,0 +1,176 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -ferror-limit 100 %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -ferror-limit 100 %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
+
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+void xxx(int argc) {
+  int cond; // expected-note {{initialize the variable 'cond' to silence this warning}}
+#pragma omp parallel masked if(cond) // expected-warning {{variable 'cond' is uninitialized when used here}}
+  {
+    ;
+  }
+}
+
+struct S1; // expected-note {{declared here}}
+
+template <class T, class S> // expected-note {{declared here}}
+int tmain(T argc, S **argv) {
+  T z;
+  #pragma omp parallel masked if // expected-error {{expected '(' after 'if'}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if () // expected-error {{expected expression}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (argc > 0 ? argv[1] : argv[2])
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp parallel masked' cannot contain more than one 'if' clause}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (S) // expected-error {{'S' does not refer to a value}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(argc + z)
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(parallel : // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(parallel : argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(parallel : argc)
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(parallel : argc) if (for:argc) // expected-error {{directive name modifier 'for' is not allowed for '#pragma omp parallel masked'}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(parallel : argc) if (parallel:argc) // expected-error {{directive '#pragma omp parallel masked' cannot contain more than one 'if' clause with 'parallel' name modifier}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(parallel : argc) if (argc) // expected-error {{no more 'if' clause is allowed}} expected-note {{previous clause with directive name modifier specified here}}
+  {
+    foo();
+  }
+
+  return 0;
+}
+
+int main(int argc, char **argv) {
+  int z;
+  #pragma omp parallel masked if // expected-error {{expected '(' after 'if'}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if () // expected-error {{expected expression}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (argc > 0 ? argv[1] : argv[2] + z)
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp parallel masked' cannot contain more than one 'if' clause}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if (1 0) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(if(tmain(argc, argv) // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(parallel : // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(parallel : argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(parallel : argc)
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(parallel : argc) if (for:argc) // expected-error {{directive name modifier 'for' is not allowed for '#pragma omp parallel masked'}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(parallel : argc) if (parallel:argc) // expected-error {{directive '#pragma omp parallel masked' cannot contain more than one 'if' clause with 'parallel' name modifier}}
+  {
+    foo();
+  }
+  #pragma omp parallel masked if(parallel : argc) if (argc) // expected-error {{no more 'if' clause is allowed}} expected-note {{previous clause with directive name modifier specified here}}
+  {
+    foo();
+  }
+
+  return tmain(argc, argv);
+}

diff  --git a/clang/test/OpenMP/parallel_masked_message.cpp b/clang/test/OpenMP/parallel_masked_message.cpp
new file mode 100644
index 0000000000000..1b3eef09db6db
--- /dev/null
+++ b/clang/test/OpenMP/parallel_masked_message.cpp
@@ -0,0 +1,89 @@
+// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
+
+void xxx(int argc) {
+  int x; // expected-note {{initialize the variable 'x' to silence this warning}}
+#pragma omp parallel masked
+  argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
+}
+
+#pragma omp parallel masked // expected-error {{unexpected OpenMP directive '#pragma omp parallel masked'}}
+
+int foo() { 
+  return 0;
+}
+
+int a;
+struct S;
+S& bar();
+int main(int argc, char **argv) {
+  #pragma omp parallel masked nowait // expected-error {{unexpected OpenMP clause 'nowait' in directive '#pragma omp parallel masked'}}
+  #pragma omp parallel masked unknown // expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  foo();
+  {
+    #pragma omp masked
+  } // expected-error {{expected statement}}
+  {
+    #pragma omp parallel masked
+  } // expected-error {{expected statement}}
+
+  S &s = bar();
+  int tid = 0;
+  #pragma omp parallel masked filter(tid)
+  (void)&s;
+  #pragma omp parallel masked { // expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  foo();
+  #pragma omp parallel masked ( // expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  foo();
+  #pragma omp parallel masked [ // expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  foo();
+  #pragma omp parallel masked ] // expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  foo();
+  #pragma omp parallel masked ) // expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  foo();
+  #pragma omp parallel masked } // expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  foo();
+  #pragma omp parallel masked
+  // expected-warning at +1 {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  #pragma omp parallel masked unknown()
+  foo();
+  L1:
+    foo();
+  #pragma omp parallel masked
+  ;
+  #pragma omp parallel masked
+  {
+
+  for (int i = 0; i < 10; ++i) {
+    switch(argc) {
+     case (0):
+      #pragma omp parallel masked
+      {
+        foo();
+        break; // expected-error {{'break' statement not in loop or switch statement}}
+        continue; // expected-error {{'continue' statement not in loop statement}}
+      }
+      default:
+       break;
+    }
+  }
+    goto L1; // expected-error {{use of undeclared label 'L1'}}
+    argc++;
+  }
+#pragma omp parallel masked default(none) // expected-note 2 {{explicit data sharing attribute requested here}}
+  {
+    ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
+    ++a;    // expected-error {{variable 'a' must have explicitly specified data sharing attributes}}
+  }
+
+  goto L2; // expected-error {{use of undeclared label 'L2'}}
+  #pragma omp parallel masked
+  L2:
+  foo();
+  #pragma omp parallel masked
+  {
+    return 1; // expected-error {{cannot return from OpenMP region}}
+  }
+  return 0;
+}

diff  --git a/clang/test/OpenMP/parallel_masked_num_threads_messages.cpp b/clang/test/OpenMP/parallel_masked_num_threads_messages.cpp
new file mode 100644
index 0000000000000..928c07c5610e1
--- /dev/null
+++ b/clang/test/OpenMP/parallel_masked_num_threads_messages.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
+
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+struct S1; // expected-note {{declared here}}
+
+template <class T, typename S, int N> // expected-note {{declared here}}
+T tmain(T argc, S **argv) {
+  T z;
+  #pragma omp parallel masked num_threads // expected-error {{expected '(' after 'num_threads'}}
+  {foo();}
+  #pragma omp parallel masked num_threads ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {foo();}
+  #pragma omp parallel masked num_threads () // expected-error {{expected expression}}
+  {foo();}
+  #pragma omp parallel masked num_threads (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {foo();}
+  #pragma omp parallel masked num_threads (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  {foo();}
+  #pragma omp parallel masked num_threads ((argc > 0) ? argv[1] : argv[2]) // expected-error 2 {{expression must have integral or unscoped enumeration type, not 'char *'}}
+  {foo();}
+  #pragma omp parallel masked num_threads (foobool(argc)), num_threads (true), num_threads (-5) // expected-error 2 {{directive '#pragma omp parallel masked' cannot contain more than one 'num_threads' clause}} expected-error {{argument to 'num_threads' clause must be a strictly positive integer value}}
+  {foo();}
+  #pragma omp parallel masked num_threads (S) // expected-error {{'S' does not refer to a value}}
+  {foo();}
+  #pragma omp parallel masked num_threads (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error 2 {{expression must have integral or unscoped enumeration type, not 'char *'}}
+  {foo();}
+  #pragma omp parallel masked num_threads (argc + z)
+  {foo();}
+  #pragma omp parallel masked num_threads (N) // expected-error {{argument to 'num_threads' clause must be a strictly positive integer value}}
+  {foo();}
+
+  return argc;
+}
+
+int main(int argc, char **argv) {
+  int z;
+  #pragma omp parallel masked num_threads // expected-error {{expected '(' after 'num_threads'}}
+  {foo();}
+  #pragma omp parallel masked num_threads ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {foo();}
+  #pragma omp parallel masked num_threads () // expected-error {{expected expression}}
+  {foo();}
+  #pragma omp parallel masked num_threads (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {foo();}
+  #pragma omp parallel masked num_threads (argc / z)) // expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  {foo();}
+  #pragma omp parallel masked num_threads (argc > 0 ? argv[1] : argv[2]) // expected-error {{integral }}
+  {foo();}
+  #pragma omp parallel masked num_threads (foobool(argc)), num_threads (true), num_threads (-5) // expected-error 2 {{directive '#pragma omp parallel masked' cannot contain more than one 'num_threads' clause}} expected-error {{argument to 'num_threads' clause must be a strictly positive integer value}}
+  {foo();}
+  #pragma omp parallel masked num_threads (S1) // expected-error {{'S1' does not refer to a value}}
+  {foo();}
+  #pragma omp parallel masked num_threads (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expression must have integral or unscoped enumeration type, not 'char *'}}
+  {foo();}
+  #pragma omp parallel masked num_threads (num_threads(tmain<int, char, -1>(argc, argv) // expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}} expected-note {{in instantiation of function template specialization 'tmain<int, char, -1>' requested here}}
+  {foo();}
+
+  return tmain<int, char, 3>(argc, argv); // expected-note {{in instantiation of function template specialization 'tmain<int, char, 3>' requested here}}
+}

diff  --git a/clang/test/OpenMP/parallel_masked_private_messages.cpp b/clang/test/OpenMP/parallel_masked_private_messages.cpp
new file mode 100644
index 0000000000000..cb26cfee7ba18
--- /dev/null
+++ b/clang/test/OpenMP/parallel_masked_private_messages.cpp
@@ -0,0 +1,284 @@
+// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
+
+extern int omp_default_mem_alloc;
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
+extern S1 a;
+class S2 {
+  mutable int a;
+
+public:
+  S2() : a(0) {}
+};
+const S2 b;
+const S2 ba[5];
+class S3 {
+  int a;
+
+public:
+  S3() : a(0) {}
+};
+const S3 ca[5];
+class S4 {
+  int a;
+  S4(); // expected-note {{implicitly declared private here}}
+
+public:
+  S4(int v) : a(v) {
+#pragma omp parallel masked private(a) private(this->a)
+    {
+      for (int k = 0; k < v; ++k)
+        ++this->a;
+    }
+  }
+};
+class S5 {
+  int a;
+  S5() : a(0) {} // expected-note {{implicitly declared private here}}
+
+public:
+  S5(int v) : a(v) {}
+  S5 &operator=(S5 &s) {
+#pragma omp parallel masked private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
+    {
+      for (int k = 0; k < s.a; ++k)
+        ++s.a;
+    }
+    return *this;
+  }
+};
+
+template <typename T>
+class S6 {
+public:
+  T a;
+
+  S6() : a(0) {}
+  S6(T v) : a(v) {
+#pragma omp parallel masked private(a) private(this->a)
+    {
+      for (int k = 0; k < v; ++k)
+        ++this->a;
+    }
+  }
+  S6 &operator=(S6 &s) {
+#pragma omp parallel masked private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
+    {
+      for (int k = 0; k < s.a; ++k)
+        ++s.a;
+    }
+    return *this;
+  }
+};
+
+template <typename T>
+class S7 : public T {
+  T a;
+  S7() : a(0) {}
+
+public:
+  S7(T v) : a(v) {
+#pragma omp parallel masked private(a) private(this->a) private(T::a)
+    {
+      for (int k = 0; k < a.a; ++k)
+        ++this->a.a;
+    }
+  }
+  S7 &operator=(S7 &s) {
+#pragma omp parallel masked private(a) private(this->a) private(s.a) private(s.T::a) // expected-error 2 {{expected variable name or data member of current class}}
+    {
+      for (int k = 0; k < s.a.a; ++k)
+        ++s.a.a;
+    }
+    return *this;
+  }
+};
+
+S3 h;
+#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
+
+template <class I, class C>
+int foomain(I argc, C **argv) {
+  I e(4);
+  I g(5);
+  int i, z;
+  int &j = i;
+#pragma omp parallel masked private // expected-error {{expected '(' after 'private'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private() // expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(argv[1]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(e, g, z)
+  {
+    foo();
+  }
+#pragma omp parallel masked private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyprivate(h) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel masked'}}
+  {
+    foo();
+  }
+#pragma omp parallel
+  {
+    int v = 0;
+    int i;
+#pragma omp parallel masked private(i)
+    {
+      foo();
+    }
+    v += i;
+  }
+#pragma omp parallel shared(i)
+#pragma omp parallel private(i)
+#pragma omp parallel masked private(j)
+  {
+    foo();
+  }
+#pragma omp parallel masked private(i)
+  {
+    foo();
+  }
+  return 0;
+}
+
+namespace A {
+double x;
+#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
+}
+namespace B {
+using A::x;
+}
+
+int main(int argc, char **argv) {
+  S4 e(4);
+  S5 g(5);
+  S6<float> s6(0.0) , s6_0(1.0);
+  S7<S6<float> > s7(0.0) , s7_0(1.0);
+  int i, z;
+  int &j = i;
+#pragma omp parallel masked private // expected-error {{expected '(' after 'private'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private() // expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(argc, z)
+  {
+    foo();
+  }
+#pragma omp parallel masked private(S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(argv[1]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}}
+  {
+    foo();
+  }
+#pragma omp parallel masked copyprivate(h) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel masked'}}
+  {
+    foo();
+  }
+#pragma omp parallel
+  {
+    int i;
+#pragma omp parallel masked private(i)
+    {
+      foo();
+    }
+  }
+#pragma omp parallel shared(i)
+#pragma omp parallel private(i)
+#pragma omp parallel masked private(j)
+  {
+    foo();
+  }
+#pragma omp parallel masked private(i)
+  {
+    foo();
+  }
+  static int m;
+#pragma omp parallel masked private(m)
+  {
+    foo();
+  }
+
+  s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}}
+  s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float>>::operator=' requested here}}
+  return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
+}
+

diff  --git a/clang/test/OpenMP/parallel_masked_proc_bind_messages.cpp b/clang/test/OpenMP/parallel_masked_proc_bind_messages.cpp
new file mode 100644
index 0000000000000..2afda0665e98c
--- /dev/null
+++ b/clang/test/OpenMP/parallel_masked_proc_bind_messages.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized
+
+void foo();
+
+int main(int argc, char **argv) {
+#pragma omp parallel masked proc_bind // expected-error {{expected '(' after 'proc_bind'}}
+  { foo(); }
+#pragma omp parallel masked proc_bind( // expected-error {{expected 'master', 'close' or 'spread' in OpenMP clause 'proc_bind'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  { foo(); }
+#pragma omp parallel masked proc_bind() // expected-error {{expected 'master', 'close' or 'spread' in OpenMP clause 'proc_bind'}}
+  { foo(); }
+#pragma omp parallel masked proc_bind(master // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  { foo(); }
+#pragma omp parallel masked proc_bind(close), proc_bind(spread) // expected-error {{directive '#pragma omp parallel masked' cannot contain more than one 'proc_bind' clause}}
+  { foo(); }
+#pragma omp parallel masked proc_bind(x) // expected-error {{expected 'master', 'close' or 'spread' in OpenMP clause 'proc_bind'}}
+  { foo(); }
+
+#pragma omp parallel masked proc_bind(master)
+  { ++argc; }
+
+#pragma omp parallel masked proc_bind(close)
+  {
+#pragma omp parallel masked proc_bind(spread)
+    { ++argc; }
+  }
+  return 0;
+}

diff  --git a/clang/test/OpenMP/parallel_masked_reduction_messages.cpp b/clang/test/OpenMP/parallel_masked_reduction_messages.cpp
new file mode 100644
index 0000000000000..f83062324d1a5
--- /dev/null
+++ b/clang/test/OpenMP/parallel_masked_reduction_messages.cpp
@@ -0,0 +1,408 @@
+// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp -fopenmp-version=45 -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp -fopenmp-version=45 -std=c++98 -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp -fopenmp-version=45 -std=c++11 -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp -std=c++98 -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp -std=c++11 -ferror-limit 150 -o - %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-simd -fopenmp-version=45 -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-simd -fopenmp-version=45 -std=c++98 -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-simd -fopenmp-version=45 -std=c++11 -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-simd -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-simd -std=c++98 -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-simd -std=c++11 -ferror-limit 150 -o - %s -Wuninitialized
+
+extern int omp_default_mem_alloc;
+void xxx(int argc) {
+  int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}
+#pragma omp parallel masked reduction(+:fp) // expected-warning {{variable 'fp' is uninitialized when used here}}
+{
+  for (int i = 0; i < 10; ++i)
+    ;
+}
+}
+
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+void foobar(int &ref) {
+#pragma omp parallel masked reduction(+:ref)
+  {
+    foo();
+  }
+}
+
+struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
+extern S1 a;
+class S2 {
+  mutable int a;
+  S2 &operator+(const S2 &arg) { return (*this); } // expected-note 3 {{implicitly declared private here}}
+
+public:
+  S2() : a(0) {}
+  S2(S2 &s2) : a(s2.a) {}
+  static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
+  static const float S2sc; // expected-note 2 {{'S2sc' declared here}}
+};
+const float S2::S2sc = 0;
+S2 b;                     // expected-note 3 {{'b' defined here}}
+const S2 ba[5];           // expected-note 2 {{'ba' defined here}}
+class S3 {
+  int a;
+
+public:
+  int b;
+  S3() : a(0) {}
+  S3(const S3 &s3) : a(s3.a) {}
+  S3 operator+(const S3 &arg1) { return arg1; }
+};
+int operator+(const S3 &arg1, const S3 &arg2) { return 5; }
+S3 c;               // expected-note 3 {{'c' defined here}}
+const S3 ca[5];     // expected-note 2 {{'ca' defined here}}
+extern const int f; // expected-note 4 {{'f' declared here}}
+class S4 {
+  int a;
+  S4(); // expected-note {{implicitly declared private here}}
+  S4(const S4 &s4);
+  S4 &operator+(const S4 &arg) { return (*this); }
+
+public:
+  S4(int v) : a(v) {}
+};
+S4 &operator&=(S4 &arg1, S4 &arg2) { return arg1; }
+class S5 {
+  int a;
+  S5() : a(0) {} // expected-note {{implicitly declared private here}}
+  S5(const S5 &s5) : a(s5.a) {}
+  S5 &operator+(const S5 &arg);
+
+public:
+  S5(int v) : a(v) {}
+};
+class S6 { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const S6' for 1st argument}}
+#if __cplusplus >= 201103L // C++11 or later
+// expected-note at -2 3 {{candidate function (the implicit move assignment operator) not viable}}
+#endif
+  int a;
+
+public:
+  S6() : a(6) {}
+  operator int() { return 6; }
+} o;
+
+S3 h, k;
+#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
+
+template <class T>       // expected-note {{declared here}}
+T tmain(T argc) {
+  const T d = T();       // expected-note 4 {{'d' defined here}}
+  const T da[5] = {T()}; // expected-note 2 {{'da' defined here}}
+  T qa[5] = {T()};
+  T i, z;
+  T &j = i;                             // expected-note 4 {{'j' defined here}}
+  S3 &p = k;                            // expected-note 2 {{'p' defined here}}
+  const T &r = da[(int)i];              // expected-note 2 {{'r' defined here}}
+  T &q = qa[(int)i];                    // expected-note 2 {{'q' defined here}}
+  T fl;
+#pragma omp parallel masked reduction // expected-error {{expected '(' after 'reduction'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name, array element or array section}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(foo : argc) //expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'float'}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'int'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(&& : argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(^ : T) // expected-error {{'T' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(+ : z, a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 3 {{const-qualified variable cannot be reduction}} expected-error 2 {{'operator+' is a private member of 'S2'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(min : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 4 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 3 {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(+ : ba) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(* : ca) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(- : da) // expected-error {{const-qualified variable cannot be reduction}} expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(+ : o) // expected-error 2 {{no viable overloaded '='}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(i), reduction(+ : j), reduction(+ : q) // expected-error 4 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
+  {
+    foo();
+  }
+#pragma omp parallel private(k)
+#pragma omp parallel masked reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(+ : p), reduction(+ : p) // expected-error 2 {{variable can appear only once in OpenMP 'reduction' clause}} expected-note 2 {{previously referenced here}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(+ : r) // expected-error 2 {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel shared(i)
+#pragma omp parallel reduction(min : i)
+#pragma omp parallel masked reduction(max : j) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
+  {
+    foo();
+  }
+#pragma omp parallel private(fl)
+#pragma omp parallel masked reduction(+ : fl)
+  {
+    foo();
+  }
+#pragma omp parallel reduction(* : fl)
+#pragma omp parallel masked reduction(+ : fl)
+  {
+    foo();
+  }
+
+  return T();
+}
+
+namespace A {
+double x;
+#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
+}
+namespace B {
+using A::x;
+}
+
+int main(int argc, char **argv) {
+  const int d = 5;       // expected-note 2 {{'d' defined here}}
+  const int da[5] = {0}; // expected-note {{'da' defined here}}
+  int qa[5] = {0};
+  S4 e(4);
+  S5 g(5);
+  int i, z;
+  int &j = i;                           // expected-note 2 {{'j' defined here}}
+  S3 &p = k;                            // expected-note 2 {{'p' defined here}}
+  const int &r = da[i];                 // expected-note {{'r' defined here}}
+  int &q = qa[i];                       // expected-note {{'q' defined here}}
+  float fl;
+#pragma omp parallel masked reduction // expected-error {{expected '(' after 'reduction'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp parallel masked' are ignored}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name, array element or array section}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(~ : argc) // expected-error {{expected unqualified-id}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(&& : argc)
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(^ : S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(+ : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{const-qualified variable cannot be reduction}} expected-error {{'operator+' is a private member of 'S2'}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(min : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 2 {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(+ : ba) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(* : ca) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(- : da) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(& : e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} expected-error {{invalid operands to binary expression ('S5' and 'S5')}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(+ : h, k, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(+ : o, z) // expected-error {{no viable overloaded '='}}
+  {
+    foo();
+  }
+#pragma omp parallel masked private(i), reduction(+ : j), reduction(+ : q) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
+  {
+    foo();
+  }
+#pragma omp parallel private(k)
+#pragma omp parallel masked reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(+ : p), reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'reduction' clause}} expected-note {{previously referenced here}}
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(+ : r) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel shared(i)
+#pragma omp parallel reduction(min : i)
+#pragma omp parallel masked reduction(max : j) // expected-error {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
+  {
+    foo();
+  }
+#pragma omp parallel private(fl)
+#pragma omp parallel masked reduction(+ : fl)
+  {
+    foo();
+  }
+#pragma omp parallel reduction(* : fl)
+#pragma omp parallel masked reduction(+ : fl)
+  {
+    foo();
+  }
+  static int m;
+#pragma omp parallel masked reduction(+ : m) // OK
+  {
+    foo();
+  }
+#pragma omp parallel masked reduction(task, + : m) // omp45-error 2 {{expected expression}} omp45-warning {{missing ':' after reduction identifier - ignoring}}
+  {
+    foo();
+  }
+
+  return tmain(argc) + tmain(fl); // expected-note {{in instantiation of function template specialization 'tmain<int>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<float>' requested here}}
+}

diff  --git a/clang/test/OpenMP/parallel_masked_shared_messages.cpp b/clang/test/OpenMP/parallel_masked_shared_messages.cpp
new file mode 100644
index 0000000000000..5e4f1ecdd2728
--- /dev/null
+++ b/clang/test/OpenMP/parallel_masked_shared_messages.cpp
@@ -0,0 +1,120 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
+
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+struct S1; // expected-note {{declared here}}
+extern S1 a;
+class S2 {
+  mutable int a;
+
+public:
+  S2() : a(0) {}
+  S2(S2 &s2) : a(s2.a) {}
+};
+const S2 b;
+const S2 ba[5];
+class S3 {
+  int a;
+
+public:
+  S3() : a(0) {}
+  S3(S3 &s3) : a(s3.a) {}
+};
+const S3 c;
+const S3 ca[5];
+extern const int f;
+class S4 {
+  int a;
+  S4();
+  S4(const S4 &s4);
+
+public:
+  S4(int v) : a(v) {}
+};
+class S5 {
+  int a;
+  S5() : a(0) {}
+  S5(const S5 &s5) : a(s5.a) {}
+
+public:
+  S5(int v) : a(v) {}
+};
+
+S3 h;
+#pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}}
+
+namespace A {
+double x;
+#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
+}
+namespace B {
+using A::x;
+}
+
+int main(int argc, char **argv) {
+  const int d = 5;
+  const int da[5] = {0};
+  S4 e(4);
+  S5 g(5);
+  int i, k;
+  int &j = i;
+#pragma omp parallel masked shared // expected-error {{expected '(' after 'shared'}}
+  { foo(); }
+#pragma omp parallel masked shared( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  { foo(); }
+#pragma omp parallel masked shared() // expected-error {{expected expression}}
+  { foo(); }
+#pragma omp parallel masked shared(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  { foo(); }
+#pragma omp parallel masked shared(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  { foo(); }
+#pragma omp parallel masked shared(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  { foo(); }
+#pragma omp parallel masked shared(argc)
+  { foo(); }
+#pragma omp parallel masked shared(S1) // expected-error {{'S1' does not refer to a value}}
+  { foo(); }
+#pragma omp parallel masked shared(a, b, c, d, f, k)
+  { foo(); }
+#pragma omp parallel masked shared(argv[1]) // expected-error {{expected variable name}}
+  { foo(); }
+#pragma omp parallel masked shared(ba)
+  { foo(); }
+#pragma omp parallel masked shared(ca)
+  { foo(); }
+#pragma omp parallel masked shared(da)
+  { foo(); }
+#pragma omp parallel masked shared(e, g)
+  { foo(); }
+#pragma omp parallel masked shared(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be shared}}
+  { foo(); }
+#pragma omp parallel masked private(i), shared(i) // expected-error {{private variable cannot be shared}} expected-note {{defined as private}}
+  { foo(); }
+#pragma omp parallel masked firstprivate(i), shared(i) // expected-error {{firstprivate variable cannot be shared}} expected-note {{defined as firstprivate}}
+  { foo(); }
+#pragma omp parallel masked private(i)
+  {
+#pragma omp parallel masked shared(i)
+    {
+#pragma omp parallel masked shared(j)
+      { foo(); }
+    }
+  }
+#pragma omp parallel masked firstprivate(i)
+  {
+#pragma omp parallel masked shared(i)
+    {
+#pragma omp parallel masked shared(j)
+      { foo(); }
+    }
+  }
+
+  return 0;
+}

diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 85dabac7e778a..d2a267bc86426 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -2152,6 +2152,7 @@ class EnqueueVisitor : public ConstStmtVisitor<EnqueueVisitor, void> {
   void VisitOMPParallelForDirective(const OMPParallelForDirective *D);
   void VisitOMPParallelForSimdDirective(const OMPParallelForSimdDirective *D);
   void VisitOMPParallelMasterDirective(const OMPParallelMasterDirective *D);
+  void VisitOMPParallelMaskedDirective(const OMPParallelMaskedDirective *D);
   void VisitOMPParallelSectionsDirective(const OMPParallelSectionsDirective *D);
   void VisitOMPTaskDirective(const OMPTaskDirective *D);
   void VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D);
@@ -3073,6 +3074,11 @@ void EnqueueVisitor::VisitOMPParallelMasterDirective(
   VisitOMPExecutableDirective(D);
 }
 
+void EnqueueVisitor::VisitOMPParallelMaskedDirective(
+    const OMPParallelMaskedDirective *D) {
+  VisitOMPExecutableDirective(D);
+}
+
 void EnqueueVisitor::VisitOMPParallelSectionsDirective(
     const OMPParallelSectionsDirective *D) {
   VisitOMPExecutableDirective(D);
@@ -5766,6 +5772,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
     return cxstring::createRef("OMPParallelForSimdDirective");
   case CXCursor_OMPParallelMasterDirective:
     return cxstring::createRef("OMPParallelMasterDirective");
+  case CXCursor_OMPParallelMaskedDirective:
+    return cxstring::createRef("OMPParallelMaskedDirective");
   case CXCursor_OMPParallelSectionsDirective:
     return cxstring::createRef("OMPParallelSectionsDirective");
   case CXCursor_OMPTaskDirective:

diff  --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp
index 1de76ab5d6b6f..afaa594ef17e0 100644
--- a/clang/tools/libclang/CXCursor.cpp
+++ b/clang/tools/libclang/CXCursor.cpp
@@ -694,6 +694,9 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
   case Stmt::OMPParallelMasterDirectiveClass:
     K = CXCursor_OMPParallelMasterDirective;
     break;
+  case Stmt::OMPParallelMaskedDirectiveClass:
+    K = CXCursor_OMPParallelMaskedDirective;
+    break;
   case Stmt::OMPParallelSectionsDirectiveClass:
     K = CXCursor_OMPParallelSectionsDirective;
     break;

diff  --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td
index ba33b6c95f7a2..cd8668be9b8d4 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -862,6 +862,21 @@ def OMP_ParallelMaster : Directive<"parallel master"> {
     VersionedClause<OMPC_Allocate>
   ];
 }
+def OMP_ParallelMasked : Directive<"parallel masked"> {
+  let allowedClauses = [
+    VersionedClause<OMPC_If>,
+    VersionedClause<OMPC_NumThreads>,
+    VersionedClause<OMPC_Default>,
+    VersionedClause<OMPC_Private>,
+    VersionedClause<OMPC_FirstPrivate>,
+    VersionedClause<OMPC_Shared>,
+    VersionedClause<OMPC_Copyin>,
+    VersionedClause<OMPC_Reduction>,
+    VersionedClause<OMPC_ProcBind>,
+    VersionedClause<OMPC_Allocate>,
+    VersionedClause<OMPC_Filter>
+  ];
+}
 def OMP_ParallelSections : Directive<"parallel sections"> {
   let allowedClauses = [
     VersionedClause<OMPC_If>,


        


More information about the cfe-commits mailing list