cchen created this revision.
cchen added a reviewer: ABataev.
Herald added subscribers: cfe-commits, jfb, arphaman, guansong, jholewinski.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70726

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/OpenMPKinds.def
  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/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/OpenMP/nesting_of_regions.cpp
  clang/test/OpenMP/parallel_master_ast_print.cpp
  clang/test/OpenMP/parallel_master_codegen.cpp
  clang/test/OpenMP/parallel_master_copyin_messages.cpp
  clang/test/OpenMP/parallel_master_default_messages.cpp
  clang/test/OpenMP/parallel_master_firstprivate_messages.cpp
  clang/test/OpenMP/parallel_master_if_messages.cpp
  clang/test/OpenMP/parallel_master_message.cpp
  clang/test/OpenMP/parallel_master_num_threads_messages.cpp
  clang/test/OpenMP/parallel_master_private_messages.cpp
  clang/test/OpenMP/parallel_master_proc_bind_messages.cpp
  clang/test/OpenMP/parallel_master_reduction_messages.cpp
  clang/test/OpenMP/parallel_master_shared_messages.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===================================================================
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -610,6 +610,9 @@
   case Stmt::OMPParallelForSimdDirectiveClass:
     K = CXCursor_OMPParallelForSimdDirective;
     break;
+  case Stmt::OMPParallelMasterDirectiveClass:
+    K = CXCursor_OMPParallelMasterDirective;
+    break;
   case Stmt::OMPParallelSectionsDirectiveClass:
     K = CXCursor_OMPParallelSectionsDirective;
     break;
Index: clang/tools/libclang/CIndex.cpp
===================================================================
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2030,6 +2030,7 @@
   void VisitOMPCriticalDirective(const OMPCriticalDirective *D);
   void VisitOMPParallelForDirective(const OMPParallelForDirective *D);
   void VisitOMPParallelForSimdDirective(const OMPParallelForSimdDirective *D);
+  void VisitOMPParallelMasterDirective(const OMPParallelMasterDirective *D);
   void VisitOMPParallelSectionsDirective(const OMPParallelSectionsDirective *D);
   void VisitOMPTaskDirective(const OMPTaskDirective *D);
   void VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D);
@@ -2811,6 +2812,11 @@
   VisitOMPLoopDirective(D);
 }
 
+void EnqueueVisitor::VisitOMPParallelMasterDirective(
+    const OMPParallelMasterDirective *D) {
+  VisitOMPExecutableDirective(D);
+}
+
 void EnqueueVisitor::VisitOMPParallelSectionsDirective(
     const OMPParallelSectionsDirective *D) {
   VisitOMPExecutableDirective(D);
@@ -5453,6 +5459,8 @@
     return cxstring::createRef("OMPParallelForDirective");
   case CXCursor_OMPParallelForSimdDirective:
     return cxstring::createRef("OMPParallelForSimdDirective");
+  case CXCursor_OMPParallelMasterDirective:
+    return cxstring::createRef("OMPParallelMasterDirective");
   case CXCursor_OMPParallelSectionsDirective:
     return cxstring::createRef("OMPParallelSectionsDirective");
   case CXCursor_OMPTaskDirective:
Index: clang/test/OpenMP/parallel_master_shared_messages.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/parallel_master_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 master shared // expected-error {{expected '(' after 'shared'}}
+  { foo(); }
+#pragma omp parallel master shared( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  { foo(); }
+#pragma omp parallel master shared() // expected-error {{expected expression}}
+  { foo(); }
+#pragma omp parallel master shared(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  { foo(); }
+#pragma omp parallel master shared(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  { foo(); }
+#pragma omp parallel master shared(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  { foo(); }
+#pragma omp parallel master shared(argc)
+  { foo(); }
+#pragma omp parallel master shared(S1) // expected-error {{'S1' does not refer to a value}}
+  { foo(); }
+#pragma omp parallel master shared(a, b, c, d, f, k)
+  { foo(); }
+#pragma omp parallel master shared(argv[1]) // expected-error {{expected variable name}}
+  { foo(); }
+#pragma omp parallel master shared(ba)
+  { foo(); }
+#pragma omp parallel master shared(ca)
+  { foo(); }
+#pragma omp parallel master shared(da)
+  { foo(); }
+#pragma omp parallel master shared(e, g)
+  { foo(); }
+#pragma omp parallel master shared(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be shared}}
+  { foo(); }
+#pragma omp parallel master private(i), shared(i) // expected-error {{private variable cannot be shared}} expected-note {{defined as private}}
+  { foo(); }
+#pragma omp parallel master firstprivate(i), shared(i) // expected-error {{firstprivate variable cannot be shared}} expected-note {{defined as firstprivate}}
+  { foo(); }
+#pragma omp parallel master private(i)
+  {
+#pragma omp parallel master shared(i)
+    {
+#pragma omp parallel master shared(j)
+      { foo(); }
+    }
+  }
+#pragma omp parallel master firstprivate(i)
+  {
+#pragma omp parallel master shared(i)
+    {
+#pragma omp parallel master shared(j)
+      { foo(); }
+    }
+  }
+
+  return 0;
+}
Index: clang/test/OpenMP/parallel_master_reduction_messages.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/parallel_master_reduction_messages.cpp
@@ -0,0 +1,398 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify -fopenmp -std=c++98 -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify -fopenmp -std=c++11 -ferror-limit 150 -o - %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify -fopenmp-simd -std=c++98 -ferror-limit 150 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify -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 master 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 master 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@-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 master reduction // expected-error {{expected '(' after 'reduction'}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name, array element or array section}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master 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 master reduction(^ : T) // expected-error {{'T' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master 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 master reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(+ : ba) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(* : ca) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(- : da) // expected-error {{const-qualified variable cannot be reduction}} expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(+ : o) // expected-error 2 {{no viable overloaded '='}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master 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 master 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 master reduction(+ : fl)
+  {
+    foo();
+  }
+#pragma omp parallel reduction(* : fl)
+#pragma omp parallel master 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 master reduction // expected-error {{expected '(' after 'reduction'}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name, array element or array section}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(~ : argc) // expected-error {{expected unqualified-id}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(&& : argc)
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(^ : S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master 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 master reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(+ : ba) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(* : ca) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(- : da) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(& : e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{invalid operands to binary expression ('S4' and 'S4')}} expected-error {{calling a private constructor of class 'S5'}} expected-error {{invalid operands to binary expression ('S5' and 'S5')}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(+ : h, k, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be reduction}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(+ : o, z) // expected-error {{no viable overloaded '='}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
+  {
+    foo();
+  }
+#pragma omp parallel master reduction(+ : p), reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'reduction' clause}} expected-note {{previously referenced here}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master 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 master reduction(+ : fl)
+  {
+    foo();
+  }
+#pragma omp parallel reduction(* : fl)
+#pragma omp parallel master reduction(+ : fl)
+  {
+    foo();
+  }
+  static int m;
+#pragma omp parallel master reduction(+ : m) // OK
+  {
+    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}}
+}
Index: clang/test/OpenMP/parallel_master_proc_bind_messages.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/parallel_master_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 master proc_bind // expected-error {{expected '(' after 'proc_bind'}}
+  { foo(); }
+#pragma omp parallel master 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 master proc_bind() // expected-error {{expected 'master', 'close' or 'spread' in OpenMP clause 'proc_bind'}}
+  { foo(); }
+#pragma omp parallel master proc_bind(master // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  { foo(); }
+#pragma omp parallel master proc_bind(close), proc_bind(spread) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'proc_bind' clause}}
+  { foo(); }
+#pragma omp parallel master proc_bind(x) // expected-error {{expected 'master', 'close' or 'spread' in OpenMP clause 'proc_bind'}}
+  { foo(); }
+
+#pragma omp parallel master proc_bind(master)
+  { ++argc; }
+
+#pragma omp parallel master proc_bind(close)
+  {
+#pragma omp parallel master proc_bind(spread)
+    { ++argc; }
+  }
+  return 0;
+}
Index: clang/test/OpenMP/parallel_master_private_messages.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/parallel_master_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 master 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 master 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 master private(a) private(this->a)
+    {
+      for (int k = 0; k < v; ++k)
+        ++this->a;
+    }
+  }
+  S6 &operator=(S6 &s) {
+#pragma omp parallel master 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 master 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 master 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 master private // expected-error {{expected '(' after 'private'}}
+  {
+    foo();
+  }
+#pragma omp parallel master private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master private() // expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel master private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master private(S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel master private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
+  {
+    foo();
+  }
+#pragma omp parallel master private(argv[1]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel master private(e, g, z)
+  {
+    foo();
+  }
+#pragma omp parallel master private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyprivate(h) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel master'}}
+  {
+    foo();
+  }
+#pragma omp parallel
+  {
+    int v = 0;
+    int i;
+#pragma omp parallel master private(i)
+    {
+      foo();
+    }
+    v += i;
+  }
+#pragma omp parallel shared(i)
+#pragma omp parallel private(i)
+#pragma omp parallel master private(j)
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master private // expected-error {{expected '(' after 'private'}}
+  {
+    foo();
+  }
+#pragma omp parallel master private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master private() // expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel master private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel master private(argc, z)
+  {
+    foo();
+  }
+#pragma omp parallel master private(S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel master private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
+  {
+    foo();
+  }
+#pragma omp parallel master private(argv[1]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master private(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyprivate(h) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel master'}}
+  {
+    foo();
+  }
+#pragma omp parallel
+  {
+    int i;
+#pragma omp parallel master private(i)
+    {
+      foo();
+    }
+  }
+#pragma omp parallel shared(i)
+#pragma omp parallel private(i)
+#pragma omp parallel master private(j)
+  {
+    foo();
+  }
+#pragma omp parallel master private(i)
+  {
+    foo();
+  }
+  static int m;
+#pragma omp parallel master 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}}
+}
+
Index: clang/test/OpenMP/parallel_master_num_threads_messages.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/parallel_master_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 master num_threads // expected-error {{expected '(' after 'num_threads'}}
+  {foo();}
+  #pragma omp parallel master num_threads ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {foo();}
+  #pragma omp parallel master num_threads () // expected-error {{expected expression}}
+  {foo();}
+  #pragma omp parallel master num_threads (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {foo();}
+  #pragma omp parallel master num_threads (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  {foo();}
+  #pragma omp parallel master 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 master num_threads (foobool(argc)), num_threads (true), num_threads (-5) // expected-error 2 {{directive '#pragma omp parallel master' 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 master num_threads (S) // expected-error {{'S' does not refer to a value}}
+  {foo();}
+  #pragma omp parallel master 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 master num_threads (argc + z)
+  {foo();}
+  #pragma omp parallel master 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 master num_threads // expected-error {{expected '(' after 'num_threads'}}
+  {foo();}
+  #pragma omp parallel master num_threads ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {foo();}
+  #pragma omp parallel master num_threads () // expected-error {{expected expression}}
+  {foo();}
+  #pragma omp parallel master num_threads (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {foo();}
+  #pragma omp parallel master num_threads (argc / z)) // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  {foo();}
+  #pragma omp parallel master num_threads (argc > 0 ? argv[1] : argv[2]) // expected-error {{integral }}
+  {foo();}
+  #pragma omp parallel master num_threads (foobool(argc)), num_threads (true), num_threads (-5) // expected-error 2 {{directive '#pragma omp parallel master' 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 master num_threads (S1) // expected-error {{'S1' does not refer to a value}}
+  {foo();}
+  #pragma omp parallel master 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 master 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}}
+}
Index: clang/test/OpenMP/parallel_master_message.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/parallel_master_message.cpp
@@ -0,0 +1,88 @@
+// 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 master
+  argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
+}
+
+#pragma omp parallel master // expected-error {{unexpected OpenMP directive '#pragma omp parallel master'}}
+
+int foo() { 
+  return 0;
+}
+
+int a;
+struct S;
+S& bar();
+int main(int argc, char **argv) {
+  #pragma omp parallel master nowait // expected-error {{unexpected OpenMP clause 'nowait' in directive '#pragma omp parallel master'}}
+  #pragma omp parallel master unknown // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  foo();
+  {
+    #pragma omp master
+  } // expected-error {{expected statement}}
+  {
+    #pragma omp parallel master
+  } // expected-error {{expected statement}}
+
+  S &s = bar();
+  #pragma omp parallel master
+  (void)&s;
+  #pragma omp parallel master { // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  foo();
+  #pragma omp parallel master ( // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  foo();
+  #pragma omp parallel master [ // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  foo();
+  #pragma omp parallel master ] // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  foo();
+  #pragma omp parallel master ) // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  foo();
+  #pragma omp parallel master } // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  foo();
+  #pragma omp parallel master
+  // expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  #pragma omp parallel master unknown()
+  foo();
+  L1:
+    foo();
+  #pragma omp parallel master
+  ;
+  #pragma omp parallel master
+  {
+
+  for (int i = 0; i < 10; ++i) {
+    switch(argc) {
+     case (0):
+      #pragma omp parallel master
+      {
+        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 master 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 master
+  L2:
+  foo();
+  #pragma omp parallel master
+  {
+    return 1; // expected-error {{cannot return from OpenMP region}}
+  }
+  return 0;
+}
Index: clang/test/OpenMP/parallel_master_if_messages.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/parallel_master_if_messages.cpp
@@ -0,0 +1,173 @@
+// 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
+
+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 master 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 master if // expected-error {{expected '(' after 'if'}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if () // expected-error {{expected expression}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (argc > 0 ? argv[1] : argv[2])
+  {
+    foo();
+  }
+  #pragma omp parallel master if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'if' clause}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (S) // expected-error {{'S' does not refer to a value}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if(argc + z)
+  {
+    foo();
+  }
+  #pragma omp parallel master if(parallel : // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if(parallel : argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if(parallel : argc)
+  {
+    foo();
+  }
+  #pragma omp parallel master if(parallel : argc) if (for:argc) // expected-error {{directive name modifier 'for' is not allowed for '#pragma omp parallel master'}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if(parallel : argc) if (parallel:argc) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'if' clause with 'parallel' name modifier}}
+  {
+    foo();
+  }
+  #pragma omp parallel master 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 master if // expected-error {{expected '(' after 'if'}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if () // expected-error {{expected expression}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (argc > 0 ? argv[1] : argv[2] + z)
+  {
+    foo();
+  }
+  #pragma omp parallel master if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'if' clause}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if (1 0) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if(if(tmain(argc, argv) // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if(parallel : // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if(parallel : argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if(parallel : argc)
+  {
+    foo();
+  }
+  #pragma omp parallel master if(parallel : argc) if (for:argc) // expected-error {{directive name modifier 'for' is not allowed for '#pragma omp parallel master'}}
+  {
+    foo();
+  }
+  #pragma omp parallel master if(parallel : argc) if (parallel:argc) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'if' clause with 'parallel' name modifier}}
+  {
+    foo();
+  }
+  #pragma omp parallel master 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);
+}
Index: clang/test/OpenMP/parallel_master_firstprivate_messages.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/parallel_master_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 master 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 master firstprivate // expected-error {{expected '(' after 'firstprivate'}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate() // expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(z, a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(argv[1]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
+  {
+    foo();
+  }
+#pragma omp parallel master linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel master'}}
+  {
+    foo();
+  }
+#pragma omp parallel
+  {
+    int v = 0;
+    int i;
+#pragma omp parallel master firstprivate(i)
+    {
+      foo();
+    }
+    v += i;
+  }
+#pragma omp parallel shared(i)
+#pragma omp parallel private(i)
+#pragma omp parallel master firstprivate(j)
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(i)
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
+  {
+    foo();
+  }
+#pragma omp parallel private(i)
+#pragma omp parallel master firstprivate(i)
+  {
+    foo();
+  }
+#pragma omp parallel reduction(+ : i)
+#pragma omp parallel master 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 master firstprivate // expected-error {{expected '(' after 'firstprivate'}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate() // expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(argc, z)
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(argv[1]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(2 * 2) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(ba) // OK
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(ca) // OK
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(da) // OK
+  {
+    foo();
+  }
+  int xa;
+#pragma omp parallel master firstprivate(xa) // OK
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(S2::S2s) // OK
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(S2::S2sc) // OK
+  {
+    foo();
+  }
+#pragma omp parallel master safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp parallel master'}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master firstprivate(m) // OK
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
+  {
+    foo();
+  }
+#pragma omp parallel master 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 master firstprivate(xa) // OK: may be firstprivate
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(j)
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
+  {
+    foo();
+  }
+#pragma omp parallel master firstprivate(n) // OK
+  {
+    foo();
+  }
+#pragma omp parallel
+  {
+    int v = 0;
+    int i;
+#pragma omp parallel master firstprivate(i)
+    {
+      foo();
+    }
+    v += i;
+  }
+#pragma omp parallel private(i)
+#pragma omp parallel master firstprivate(i)
+  {
+    foo();
+  }
+#pragma omp parallel reduction(+ : i)
+#pragma omp parallel master firstprivate(i)
+  {
+    foo();
+  }
+  static int r;
+#pragma omp parallel master firstprivate(r) // OK
+  {
+    foo();
+  }
+
+  return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
+}
Index: clang/test/OpenMP/parallel_master_default_messages.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/parallel_master_default_messages.cpp
@@ -0,0 +1,41 @@
+// 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 master default // expected-error {{expected '(' after 'default'}}
+  {
+#pragma omp parallel master default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+    {
+#pragma omp parallel master default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}}
+      {
+#pragma omp parallel master default(none // expected-error {{expected ')'}} expected-note {{to match this '('}}
+        {
+#pragma omp parallel master default(shared), default(shared) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'default' clause}}
+          {
+#pragma omp parallel master default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}}
+            {
+              foo();
+            }
+          }
+        }
+      }
+    }
+  }
+
+#pragma omp parallel master 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 master default(none) // expected-note {{explicit data sharing attribute requested here}}
+  {
+#pragma omp parallel master default(shared)
+    {
+      ++argc;  // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
+    }
+  }
+  return 0;
+}
Index: clang/test/OpenMP/parallel_master_copyin_messages.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/parallel_master_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 master copyin // expected-error {{expected '(' after 'copyin'}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyin( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyin() // expected-error {{expected expression}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyin(k // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyin(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyin(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyin(l) // expected-error {{'operator=' is a private member of 'S4'}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyin(S1) // expected-error {{'S1' does not refer to a value}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyin(argv[1]) // expected-error {{expected variable name}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyin(i) // expected-error {{copyin variable must be threadprivate}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyin(m) // expected-error {{'operator=' is a private member of 'S5'}}
+  {
+    foo();
+  }
+#pragma omp parallel master copyin(ST < int > ::s, B::x) // expected-error {{copyin variable must be threadprivate}}
+  {
+    foo();
+  }
+
+  return 0;
+}
Index: clang/test/OpenMP/parallel_master_codegen.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/parallel_master_codegen.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+void foo() {}
+
+// CHECK-LABEL: parallel_master
+void parallel_master() {
+#pragma omp parallel master
+  // CHECK-NOT: __kmpc_global_thread_num
+  // CHECK:     call i32 @__kmpc_master({{.+}})
+  // CHECK:     invoke void {{.*}}foo{{.*}}()
+  // CHECK-NOT: __kmpc_global_thread_num
+  // CHECK:     call void @__kmpc_end_master({{.+}})
+  // CHECK:     call void @__clang_call_terminate
+  // CHECK:     unreachable
+  foo();
+}
+
+#endif
Index: clang/test/OpenMP/parallel_master_ast_print.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/parallel_master_ast_print.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=50 -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+void foo() {}
+
+int main (int argc, char **argv) {
+  int b = argc, c, d, e, f, g;
+  static int a;
+// CHECK: static int a;
+#pragma omp parallel master
+{
+  a=2;
+}
+// CHECK-NEXT: #pragma omp parallel master{{$}}
+// CHECK-NEXT: {
+// CHECK-NEXT: a = 2;
+// CHECK-NEXT: }
+  return (0);
+}
+
+#endif
Index: clang/test/OpenMP/nesting_of_regions.cpp
===================================================================
--- clang/test/OpenMP/nesting_of_regions.cpp
+++ clang/test/OpenMP/nesting_of_regions.cpp
@@ -61,6 +61,11 @@
     bar();
   }
 #pragma omp parallel
+#pragma omp parallel master
+  {
+    bar();
+  }
+#pragma omp parallel
 #pragma omp task
   {
     bar();
@@ -301,6 +306,13 @@
   }
 #pragma omp simd
   for (int i = 0; i < 10; ++i) {
+#pragma omp parallel master // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+    {
+      bar();
+    }
+  }
+#pragma omp simd
+  for (int i = 0; i < 10; ++i) {
 #pragma omp task // expected-error {{OpenMP constructs may not be nested inside a simd region}}
     {
       bar();
@@ -563,6 +575,13 @@
   }
 #pragma omp for
   for (int i = 0; i < 10; ++i) {
+#pragma omp parallel master
+    {
+      bar();
+    }
+  }
+#pragma omp for
+  for (int i = 0; i < 10; ++i) {
 #pragma omp parallel sections
     {
       bar();
@@ -809,6 +828,13 @@
   }
 #pragma omp for simd
   for (int i = 0; i < 10; ++i) {
+#pragma omp parallel master // 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();
@@ -1045,6 +1071,13 @@
   }
 #pragma omp sections
   {
+#pragma omp parallel master // OK
+    {
+      bar();
+    }
+  }
+#pragma omp sections
+  {
 #pragma omp parallel
     {
 #pragma omp master // OK
@@ -1321,6 +1354,16 @@
   {
 #pragma omp section
     {
+#pragma omp parallel master
+      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}}
@@ -1633,6 +1676,13 @@
   }
 #pragma omp single
   {
+#pragma omp parallel master
+    {
+      bar();
+    }
+  }
+#pragma omp single
+  {
 #pragma omp critical
     {
       bar();
@@ -1922,6 +1972,26 @@
   }
 #pragma omp 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 master
+  {
 #pragma omp parallel for
     for (int i = 0; i < 10; ++i)
       ;
@@ -2177,6 +2247,13 @@
   }
 #pragma omp critical
   {
+#pragma omp parallel master
+    {
+      bar();
+    }
+  }
+#pragma omp critical
+  {
 #pragma omp parallel for
     for (int i = 0; i < 10; ++i)
       ;
@@ -3722,6 +3799,15 @@
   // expected-error@+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 l-value expression with scalar type}}
   // expected-note@+1 {{expected an expression statement}}
   {
+#pragma omp parallel master // expected-error {{OpenMP constructs may not be nested inside an atomic region}}
+    {
+      bar();
+    }
+  }
+#pragma omp atomic
+  // expected-error@+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 l-value expression with scalar type}}
+  // expected-note@+1 {{expected an expression statement}}
+  {
 #pragma omp critical // expected-error {{OpenMP constructs may not be nested inside an atomic region}}
     {
       bar();
@@ -4237,6 +4323,11 @@
   {
     bar();
   }
+#pragma omp target
+#pragma omp parallel master
+  {
+    bar();
+  }
 #pragma omp target parallel
 #pragma omp critical
   {
@@ -9000,6 +9091,8 @@
 #pragma omp parallel
 #pragma omp master
   bar();
+#pragma omp parallel master
+  bar();
 #pragma omp parallel
 #pragma omp critical
   bar();
@@ -10760,6 +10853,11 @@
     for (int i = 0; i < 10; ++i)
       ;
   }
+#pragma omp parallel master
+  {
+    for (int i = 0; i < 10; ++i)
+      ;
+  }
 #pragma omp master
   {
 #pragma omp single // expected-error {{region cannot be closely nested inside 'master' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}}
@@ -10810,6 +10908,13 @@
   }
 #pragma omp master
   {
+#pragma omp parallel master
+    {
+      bar();
+    }
+  }
+#pragma omp master
+  {
 #pragma omp parallel for
     for (int i = 0; i < 10; ++i)
       ;
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1245,6 +1245,7 @@
     case Stmt::OMPParallelForDirectiveClass:
     case Stmt::OMPParallelForSimdDirectiveClass:
     case Stmt::OMPParallelSectionsDirectiveClass:
+    case Stmt::OMPParallelMasterDirectiveClass:
     case Stmt::OMPTaskDirectiveClass:
     case Stmt::OMPTaskyieldDirectiveClass:
     case Stmt::OMPBarrierDirectiveClass:
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===================================================================
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -2103,6 +2103,15 @@
   Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE;
 }
 
+void ASTStmtWriter::VisitOMPParallelMasterDirective(
+    OMPParallelMasterDirective *D) {
+  VisitStmt(D);
+  Record.push_back(D->getNumClauses());
+  VisitOMPExecutableDirective(D);
+  Record.push_back(D->hasCancel() ? 1 : 0);
+  Code = serialization::STMT_OMP_PARALLEL_MASTER_DIRECTIVE;
+}
+
 void ASTStmtWriter::VisitOMPParallelSectionsDirective(
     OMPParallelSectionsDirective *D) {
   VisitStmt(D);
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===================================================================
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2165,6 +2165,15 @@
   VisitOMPLoopDirective(D);
 }
 
+void ASTStmtReader::VisitOMPParallelMasterDirective(
+    OMPParallelMasterDirective *D) {
+  VisitStmt(D);
+  // The NumClauses field was read in ReadStmtFromStream.
+  Record.skipInts(1);
+  VisitOMPExecutableDirective(D);
+  D->setHasCancel(Record.readInt());
+}
+
 void ASTStmtReader::VisitOMPParallelSectionsDirective(
     OMPParallelSectionsDirective *D) {
   VisitStmt(D);
@@ -3003,6 +3012,11 @@
       break;
     }
 
+    case STMT_OMP_PARALLEL_MASTER_DIRECTIVE:
+      S = OMPParallelMasterDirective::CreateEmpty(
+          Context, Record[ASTStmtReader::NumStmtFields], Empty);
+      break;
+
     case STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE:
       S = OMPParallelSectionsDirective::CreateEmpty(
           Context, Record[ASTStmtReader::NumStmtFields], Empty);
Index: clang/lib/Sema/TreeTransform.h
===================================================================
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -8060,6 +8060,17 @@
   return Res;
 }
 
+template <typename Derived>
+StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective(
+    OMPParallelMasterDirective *D) {
+  DeclarationNameInfo DirName;
+  getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_master, 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) {
Index: clang/lib/Sema/SemaOpenMP.cpp
===================================================================
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -3242,6 +3242,7 @@
   case OMPD_parallel_for:
   case OMPD_parallel_for_simd:
   case OMPD_parallel_sections:
+  case OMPD_parallel_master:
   case OMPD_teams:
   case OMPD_teams_distribute:
   case OMPD_teams_distribute_simd: {
@@ -4531,6 +4532,11 @@
         ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA);
     AllowedNameModifiers.push_back(OMPD_parallel);
     break;
+  case OMPD_parallel_master:
+    Res = ActOnOpenMPParallelMasterDirective(ClausesWithImplicit, AStmt,
+                                               StartLoc, EndLoc);
+    AllowedNameModifiers.push_back(OMPD_parallel);
+    break;
   case OMPD_parallel_sections:
     Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt,
                                                StartLoc, EndLoc);
@@ -8213,6 +8219,28 @@
       Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B);
 }
 
+StmtResult
+Sema::ActOnOpenMPParallelMasterDirective(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 OMPParallelMasterDirective::Create(Context, StartLoc, EndLoc, Clauses,
+                                            AStmt, DSAStack->isCancelRegion());
+}
+
 StmtResult
 Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses,
                                            Stmt *AStmt, SourceLocation StartLoc,
@@ -10646,6 +10674,7 @@
     case OMPD_target_exit_data:
       CaptureRegion = OMPD_task;
       break;
+    case OMPD_parallel_master:
     case OMPD_parallel_master_taskloop:
     case OMPD_parallel_master_taskloop_simd:
       if (NameModifier == OMPD_unknown || NameModifier == OMPD_taskloop)
@@ -10720,6 +10749,7 @@
       CaptureRegion = OMPD_teams;
       break;
     case OMPD_parallel:
+    case OMPD_parallel_master:
     case OMPD_parallel_sections:
     case OMPD_parallel_for:
     case OMPD_parallel_for_simd:
@@ -10810,6 +10840,7 @@
     case OMPD_target_update:
     case OMPD_cancel:
     case OMPD_parallel:
+    case OMPD_parallel_master:
     case OMPD_parallel_sections:
     case OMPD_parallel_for:
     case OMPD_parallel_for_simd:
@@ -10881,6 +10912,7 @@
     case OMPD_target_update:
     case OMPD_cancel:
     case OMPD_parallel:
+    case OMPD_parallel_master:
     case OMPD_parallel_sections:
     case OMPD_parallel_for:
     case OMPD_parallel_for_simd:
@@ -10960,6 +10992,7 @@
     case OMPD_target_parallel:
     case OMPD_cancel:
     case OMPD_parallel:
+    case OMPD_parallel_master:
     case OMPD_parallel_sections:
     case OMPD_threadprivate:
     case OMPD_allocate:
@@ -11031,6 +11064,7 @@
     case OMPD_target_parallel:
     case OMPD_cancel:
     case OMPD_parallel:
+    case OMPD_parallel_master:
     case OMPD_parallel_sections:
     case OMPD_threadprivate:
     case OMPD_allocate:
@@ -11099,6 +11133,7 @@
     case OMPD_parallel_master_taskloop_simd:
     case OMPD_cancel:
     case OMPD_parallel:
+    case OMPD_parallel_master:
     case OMPD_parallel_sections:
     case OMPD_parallel_for:
     case OMPD_parallel_for_simd:
@@ -11172,6 +11207,7 @@
     case OMPD_distribute_parallel_for_simd:
     case OMPD_cancel:
     case OMPD_parallel:
+    case OMPD_parallel_master:
     case OMPD_parallel_sections:
     case OMPD_parallel_for:
     case OMPD_parallel_for_simd:
Index: clang/lib/Parse/ParseOpenMP.cpp
===================================================================
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -44,7 +44,6 @@
   OMPD_target_teams_distribute_parallel,
   OMPD_mapper,
   OMPD_variant,
-  OMPD_parallel_master,
 };
 
 class DeclDirectiveListParserHelper final {
@@ -1469,6 +1468,7 @@
   case OMPD_parallel_for:
   case OMPD_parallel_for_simd:
   case OMPD_parallel_sections:
+  case OMPD_parallel_master:
   case OMPD_atomic:
   case OMPD_target:
   case OMPD_teams:
@@ -1536,20 +1536,20 @@
 ///       executable-directive:
 ///         annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' |
 ///         'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] |
-///         'parallel for' | 'parallel sections' | 'task' | 'taskyield' |
-///         'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' |
-///         'for simd' | 'parallel for simd' | 'target' | 'target data' |
-///         'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' | 'master
-///         taskloop' | 'master taskloop simd' | 'parallel master taskloop' |
-///         'parallel master taskloop simd' | 'distribute' | 'target enter data'
-///         | 'target exit data' | 'target parallel' | 'target parallel for' |
-///         'target update' | 'distribute parallel for' | 'distribute paralle
-///         for simd' | 'distribute simd' | 'target parallel for simd' | 'target
-///         simd' | 'teams distribute' | 'teams distribute simd' | 'teams
-///         distribute parallel for simd' | 'teams distribute parallel for' |
-///         'target teams' | 'target teams distribute' | 'target teams
-///         distribute parallel for' | 'target teams distribute parallel for
-///         simd' | 'target teams distribute simd' {clause}
+///         'parallel for' | 'parallel sections' | 'parallel master' | 'task' |
+///         'taskyield' | 'barrier' | 'taskwait' | 'flush' | 'ordered' |
+///         'atomic' | 'for simd' | 'parallel for simd' | 'target' | 'target
+///         data' | 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' |
+///         'master taskloop' | 'master taskloop simd' | 'parallel master
+///         taskloop' | 'parallel master taskloop simd' | 'distribute' | 'target
+///         enter data' | 'target exit data' | 'target parallel' | 'target
+///         parallel for' | 'target update' | 'distribute parallel for' |
+///         'distribute paralle for simd' | 'distribute simd' | 'target parallel
+///         for simd' | 'target simd' | 'teams distribute' | 'teams distribute
+///         simd' | 'teams distribute parallel for simd' | 'teams distribute
+///         parallel for' | 'target teams' | 'target teams distribute' | 'target
+///         teams distribute parallel for' | 'target teams distribute parallel
+///         for simd' | 'target teams distribute simd' {clause}
 ///         annot_pragma_openmp_end
 ///
 StmtResult
@@ -1714,6 +1714,7 @@
   case OMPD_parallel_for:
   case OMPD_parallel_for_simd:
   case OMPD_parallel_sections:
+  case OMPD_parallel_master:
   case OMPD_task:
   case OMPD_ordered:
   case OMPD_atomic:
Index: clang/lib/CodeGen/CodeGenFunction.h
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -3145,6 +3145,7 @@
   void EmitOMPParallelForDirective(const OMPParallelForDirective &S);
   void EmitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &S);
   void EmitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &S);
+  void EmitOMPParallelMasterDirective(const OMPParallelMasterDirective &S);
   void EmitOMPTaskDirective(const OMPTaskDirective &S);
   void EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &S);
   void EmitOMPBarrierDirective(const OMPBarrierDirective &S);
@@ -3341,6 +3342,9 @@
   /// Emit code for sections directive.
   void EmitSections(const OMPExecutableDirective &S);
 
+  /// Emit code for master directive.
+  void EmitMaster(const OMPExecutableDirective &S);
+
 public:
 
   //===--------------------------------------------------------------------===//
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===================================================================
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -2869,15 +2869,19 @@
   }
 }
 
-void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) {
+void CodeGenFunction::EmitMaster(const OMPExecutableDirective &S) {
   auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
     Action.Enter(CGF);
     CGF.EmitStmt(S.getInnermostCapturedStmt()->getCapturedStmt());
   };
-  OMPLexicalScope Scope(*this, S, OMPD_unknown);
   CGM.getOpenMPRuntime().emitMasterRegion(*this, CodeGen, S.getBeginLoc());
 }
 
+void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) {
+  OMPLexicalScope Scope(*this, S, OMPD_unknown);
+  EmitMaster(S);
+}
+
 void CodeGenFunction::EmitOMPCriticalDirective(const OMPCriticalDirective &S) {
   auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
     Action.Enter(CGF);
@@ -2919,6 +2923,18 @@
                                  emitEmptyBoundParameters);
 }
 
+void CodeGenFunction::EmitOMPParallelMasterDirective(
+    const OMPParallelMasterDirective &S) {
+  // Emit directive as a combined directive that consists of two implicit
+  // directives: 'parallel' with 'master' directive.
+  auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
+    Action.Enter(CGF);
+    CGF.EmitMaster(S);
+  };
+  emitCommonOMPParallelDirective(*this, S, OMPD_master, CodeGen,
+                                 emitEmptyBoundParameters);
+}
+
 void CodeGenFunction::EmitOMPParallelSectionsDirective(
     const OMPParallelSectionsDirective &S) {
   // Emit directive as a combined directive that consists of two implicit
Index: clang/lib/CodeGen/CGStmt.cpp
===================================================================
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -221,6 +221,9 @@
   case Stmt::OMPParallelForSimdDirectiveClass:
     EmitOMPParallelForSimdDirective(cast<OMPParallelForSimdDirective>(*S));
     break;
+  case Stmt::OMPParallelMasterDirectiveClass:
+    EmitOMPParallelMasterDirective(cast<OMPParallelMasterDirective>(*S));
+    break;
   case Stmt::OMPParallelSectionsDirectiveClass:
     EmitOMPParallelSectionsDirective(cast<OMPParallelSectionsDirective>(*S));
     break;
Index: clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -761,6 +761,7 @@
     case OMPD_parallel:
     case OMPD_for:
     case OMPD_parallel_for:
+    case OMPD_parallel_master:
     case OMPD_parallel_sections:
     case OMPD_for_simd:
     case OMPD_parallel_for_simd:
@@ -836,6 +837,7 @@
   case OMPD_parallel:
   case OMPD_for:
   case OMPD_parallel_for:
+  case OMPD_parallel_master:
   case OMPD_parallel_sections:
   case OMPD_for_simd:
   case OMPD_parallel_for_simd:
@@ -1004,6 +1006,7 @@
     case OMPD_parallel:
     case OMPD_for:
     case OMPD_parallel_for:
+    case OMPD_parallel_master:
     case OMPD_parallel_sections:
     case OMPD_for_simd:
     case OMPD_parallel_for_simd:
@@ -1085,6 +1088,7 @@
   case OMPD_parallel:
   case OMPD_for:
   case OMPD_parallel_for:
+  case OMPD_parallel_master:
   case OMPD_parallel_sections:
   case OMPD_for_simd:
   case OMPD_parallel_for_simd:
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6665,6 +6665,7 @@
   case OMPD_parallel:
   case OMPD_for:
   case OMPD_parallel_for:
+  case OMPD_parallel_master:
   case OMPD_parallel_sections:
   case OMPD_for_simd:
   case OMPD_parallel_for_simd:
@@ -6975,6 +6976,7 @@
   case OMPD_parallel:
   case OMPD_for:
   case OMPD_parallel_for:
+  case OMPD_parallel_master:
   case OMPD_parallel_sections:
   case OMPD_for_simd:
   case OMPD_parallel_for_simd:
@@ -8750,6 +8752,7 @@
     case OMPD_parallel:
     case OMPD_for:
     case OMPD_parallel_for:
+    case OMPD_parallel_master:
     case OMPD_parallel_sections:
     case OMPD_for_simd:
     case OMPD_parallel_for_simd:
@@ -9511,6 +9514,7 @@
     case OMPD_parallel:
     case OMPD_for:
     case OMPD_parallel_for:
+    case OMPD_parallel_master:
     case OMPD_parallel_sections:
     case OMPD_for_simd:
     case OMPD_parallel_for_simd:
@@ -10133,6 +10137,7 @@
     case OMPD_parallel:
     case OMPD_for:
     case OMPD_parallel_for:
+    case OMPD_parallel_master:
     case OMPD_parallel_sections:
     case OMPD_for_simd:
     case OMPD_parallel_for_simd:
Index: clang/lib/Basic/OpenMPKinds.cpp
===================================================================
--- clang/lib/Basic/OpenMPKinds.cpp
+++ clang/lib/Basic/OpenMPKinds.cpp
@@ -529,6 +529,16 @@
 #define OPENMP_PARALLEL_FOR_SIMD_CLAUSE(Name)                                  \
   case OMPC_##Name:                                                            \
     return true;
+#include "clang/Basic/OpenMPKinds.def"
+    default:
+      break;
+    }
+    break;
+  case OMPD_parallel_master:
+    switch (CKind) {
+#define OPENMP_PARALLEL_MASTER_CLAUSE(Name)                                    \
+    case OMPC_##Name:                                                          \
+      return true;
 #include "clang/Basic/OpenMPKinds.def"
     default:
       break;
@@ -1009,6 +1019,7 @@
          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_taskloop ||
          DKind == OMPD_parallel_master_taskloop_simd;
 }
@@ -1107,6 +1118,7 @@
   case OMPD_parallel:
   case OMPD_parallel_for:
   case OMPD_parallel_for_simd:
+  case OMPD_parallel_master:
   case OMPD_parallel_sections:
   case OMPD_distribute_parallel_for:
   case OMPD_distribute_parallel_for_simd:
Index: clang/lib/AST/StmtProfile.cpp
===================================================================
--- clang/lib/AST/StmtProfile.cpp
+++ clang/lib/AST/StmtProfile.cpp
@@ -833,6 +833,11 @@
   VisitOMPLoopDirective(S);
 }
 
+void StmtProfiler::VisitOMPParallelMasterDirective(
+    const OMPParallelMasterDirective *S) {
+  VisitOMPExecutableDirective(S);
+}
+
 void StmtProfiler::VisitOMPParallelSectionsDirective(
     const OMPParallelSectionsDirective *S) {
   VisitOMPExecutableDirective(S);
Index: clang/lib/AST/StmtPrinter.cpp
===================================================================
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -714,6 +714,12 @@
   PrintOMPExecutableDirective(Node);
 }
 
+void StmtPrinter::VisitOMPParallelMasterDirective(
+    OMPParallelMasterDirective *Node) {
+  Indent() << "#pragma omp parallel master";
+  PrintOMPExecutableDirective(Node);
+}
+
 void StmtPrinter::VisitOMPParallelSectionsDirective(
     OMPParallelSectionsDirective *Node) {
   Indent() << "#pragma omp parallel sections";
Index: clang/lib/AST/StmtOpenMP.cpp
===================================================================
--- clang/lib/AST/StmtOpenMP.cpp
+++ clang/lib/AST/StmtOpenMP.cpp
@@ -332,21 +332,6 @@
   return new (Mem) OMPForSimdDirective(CollapsedNum, NumClauses);
 }
 
-OMPSectionsDirective *OMPSectionsDirective::Create(
-    const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
-    ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, bool HasCancel) {
-  unsigned Size =
-      llvm::alignTo(sizeof(OMPSectionsDirective), alignof(OMPClause *));
-  void *Mem =
-      C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
-  OMPSectionsDirective *Dir =
-      new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size());
-  Dir->setClauses(Clauses);
-  Dir->setAssociatedStmt(AssociatedStmt);
-  Dir->setHasCancel(HasCancel);
-  return Dir;
-}
-
 OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C,
                                                         unsigned NumClauses,
                                                         EmptyShell) {
@@ -550,6 +535,47 @@
   return new (Mem) OMPParallelForSimdDirective(CollapsedNum, NumClauses);
 }
 
+OMPParallelMasterDirective *OMPParallelMasterDirective::Create(
+    const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
+    ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, bool HasCancel) {
+  unsigned Size =
+      llvm::alignTo(sizeof(OMPParallelMasterDirective), alignof(OMPClause *));
+  void *Mem =
+      C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
+  OMPParallelMasterDirective *Dir =
+      new (Mem) OMPParallelMasterDirective(StartLoc, EndLoc, Clauses.size());
+  Dir->setClauses(Clauses);
+  Dir->setAssociatedStmt(AssociatedStmt);
+  Dir->setHasCancel(HasCancel);
+  return Dir;
+}
+
+OMPParallelMasterDirective *OMPParallelMasterDirective::CreateEmpty(const ASTContext &C,
+                                                        unsigned NumClauses,
+                                                        EmptyShell) {
+  unsigned Size =
+      llvm::alignTo(sizeof(OMPParallelMasterDirective), alignof(OMPClause *));
+  void *Mem =
+      C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
+  return new (Mem) OMPParallelMasterDirective(NumClauses);
+}
+
+OMPSectionsDirective *OMPSectionsDirective::Create(
+    const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
+    ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, bool HasCancel) {
+  unsigned Size =
+      llvm::alignTo(sizeof(OMPSectionsDirective), alignof(OMPClause *));
+  void *Mem =
+      C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
+  OMPSectionsDirective *Dir =
+      new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size());
+  Dir->setClauses(Clauses);
+  Dir->setAssociatedStmt(AssociatedStmt);
+  Dir->setHasCancel(HasCancel);
+  return Dir;
+}
+
+
 OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create(
     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
     ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, bool HasCancel) {
Index: clang/include/clang/Serialization/ASTBitCodes.h
===================================================================
--- clang/include/clang/Serialization/ASTBitCodes.h
+++ clang/include/clang/Serialization/ASTBitCodes.h
@@ -1951,6 +1951,7 @@
       STMT_OMP_CRITICAL_DIRECTIVE,
       STMT_OMP_PARALLEL_FOR_DIRECTIVE,
       STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE,
+      STMT_OMP_PARALLEL_MASTER_DIRECTIVE,
       STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE,
       STMT_OMP_TASK_DIRECTIVE,
       STMT_OMP_TASKYIELD_DIRECTIVE,
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -9558,6 +9558,12 @@
   StmtResult ActOnOpenMPParallelForSimdDirective(
       ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
       SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA);
+  /// Called on well-formed '\#pragma omp parallel master' after
+  /// parsing of the  associated statement.
+  StmtResult ActOnOpenMPParallelMasterDirective(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,
Index: clang/include/clang/Basic/StmtNodes.td
===================================================================
--- clang/include/clang/Basic/StmtNodes.td
+++ clang/include/clang/Basic/StmtNodes.td
@@ -223,6 +223,7 @@
 def OMPCriticalDirective : StmtNode<OMPExecutableDirective>;
 def OMPParallelForDirective : StmtNode<OMPLoopDirective>;
 def OMPParallelForSimdDirective : StmtNode<OMPLoopDirective>;
+def OMPParallelMasterDirective : StmtNode<OMPExecutableDirective>;
 def OMPParallelSectionsDirective : StmtNode<OMPExecutableDirective>;
 def OMPTaskDirective : StmtNode<OMPExecutableDirective>;
 def OMPTaskyieldDirective : StmtNode<OMPExecutableDirective>;
Index: clang/include/clang/Basic/OpenMPKinds.def
===================================================================
--- clang/include/clang/Basic/OpenMPKinds.def
+++ clang/include/clang/Basic/OpenMPKinds.def
@@ -44,6 +44,9 @@
 #ifndef OPENMP_PARALLEL_FOR_SIMD_CLAUSE
 #  define OPENMP_PARALLEL_FOR_SIMD_CLAUSE(Name)
 #endif
+#ifndef OPENMP_PARALLEL_MASTER_CLAUSE
+#  define OPENMP_PARALLEL_MASTER_CLAUSE(Name)
+#endif
 #ifndef OPENMP_PARALLEL_SECTIONS_CLAUSE
 #  define OPENMP_PARALLEL_SECTIONS_CLAUSE(Name)
 #endif
@@ -255,6 +258,7 @@
 OPENMP_DIRECTIVE_EXT(target_update, "target update")
 OPENMP_DIRECTIVE_EXT(parallel_for, "parallel for")
 OPENMP_DIRECTIVE_EXT(parallel_for_simd, "parallel for simd")
+OPENMP_DIRECTIVE_EXT(parallel_master, "parallel master")
 OPENMP_DIRECTIVE_EXT(parallel_sections, "parallel sections")
 OPENMP_DIRECTIVE_EXT(for_simd, "for simd")
 OPENMP_DIRECTIVE_EXT(cancellation_point, "cancellation point")
@@ -498,6 +502,18 @@
 OPENMP_PARALLEL_FOR_SIMD_CLAUSE(ordered)
 OPENMP_PARALLEL_FOR_SIMD_CLAUSE(allocate)
 
+// Clauses allowed for OpenMP directive 'parallel master'.
+OPENMP_PARALLEL_MASTER_CLAUSE(if)
+OPENMP_PARALLEL_MASTER_CLAUSE(num_threads)
+OPENMP_PARALLEL_MASTER_CLAUSE(default)
+OPENMP_PARALLEL_MASTER_CLAUSE(private)
+OPENMP_PARALLEL_MASTER_CLAUSE(firstprivate)
+OPENMP_PARALLEL_MASTER_CLAUSE(shared)
+OPENMP_PARALLEL_MASTER_CLAUSE(copyin)
+OPENMP_PARALLEL_MASTER_CLAUSE(reduction)
+OPENMP_PARALLEL_MASTER_CLAUSE(proc_bind)
+OPENMP_PARALLEL_MASTER_CLAUSE(allocate)
+
 // Clauses allowed for OpenMP directive 'parallel sections'.
 OPENMP_PARALLEL_SECTIONS_CLAUSE(if)
 OPENMP_PARALLEL_SECTIONS_CLAUSE(num_threads)
@@ -1128,6 +1144,7 @@
 #undef OPENMP_PARALLEL_CLAUSE
 #undef OPENMP_PARALLEL_FOR_CLAUSE
 #undef OPENMP_PARALLEL_FOR_SIMD_CLAUSE
+#undef OPENMP_PARALLEL_MASTER_CLAUSE
 #undef OPENMP_PARALLEL_SECTIONS_CLAUSE
 #undef OPENMP_TASK_CLAUSE
 #undef OPENMP_ATOMIC_CLAUSE
Index: clang/include/clang/AST/StmtOpenMP.h
===================================================================
--- clang/include/clang/AST/StmtOpenMP.h
+++ clang/include/clang/AST/StmtOpenMP.h
@@ -1842,6 +1842,67 @@
   }
 };
 
+/// This represents '#pragma omp parallel master' directive.
+///
+/// \code
+/// #pragma omp parallel master private(a,b)
+/// \endcode
+/// In this example directive '#pragma omp parallel master' has clauses
+/// 'private' with the variables 'a' and 'b'
+///
+class OMPParallelMasterDirective : public OMPExecutableDirective {
+  friend class ASTStmtReader;
+
+  /// true if current directive has inner cancel directive.
+  bool HasCancel;
+
+  OMPParallelMasterDirective(SourceLocation StartLoc, SourceLocation EndLoc,
+                             unsigned NumClauses)
+      : OMPExecutableDirective(this, OMPParallelMasterDirectiveClass,
+                               OMPD_parallel_master, StartLoc, EndLoc,
+                               NumClauses, 1),
+        HasCancel(false) {}
+
+  explicit OMPParallelMasterDirective(unsigned NumClauses)
+      : OMPExecutableDirective(this, OMPParallelMasterDirectiveClass,
+                               OMPD_parallel_master, SourceLocation(),
+                               SourceLocation(), NumClauses, 1),
+        HasCancel(false) {}
+
+  /// Set cancel state.
+  void setHasCancel(bool Has) { HasCancel = Has; }
+
+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 HasCancel true if current directive has inner cancel directive.
+  ///
+  static OMPParallelMasterDirective *
+  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
+         ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, bool HasCancel);
+
+  /// Creates an empty directive with the place for \a NumClauses
+  /// clauses.
+  ///
+  /// \param C AST context.
+  /// \param NumClauses Number of clauses.
+  ///
+  static OMPParallelMasterDirective *
+  CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell);
+
+  /// Return true if current directive has inner cancel directive.
+  bool hasCancel() const { return HasCancel; }
+
+  static bool classof(const Stmt *T) {
+    return T->getStmtClass() == OMPParallelMasterDirectiveClass;
+  }
+};
+
 /// This represents '#pragma omp parallel sections' directive.
 ///
 /// \code
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===================================================================
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2752,6 +2752,9 @@
 DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
 
+DEF_TRAVERSE_STMT(OMPParallelMasterDirective,
+                  { TRY_TO(TraverseOMPExecutableDirective(S)); })
+
 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
 
Index: clang/include/clang-c/Index.h
===================================================================
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -2570,7 +2570,11 @@
    */
   CXCursor_OMPParallelMasterTaskLoopSimdDirective      = 284,
 
-  CXCursor_LastStmt = CXCursor_OMPParallelMasterTaskLoopSimdDirective,
+  /** OpenMP parallel master directive.
+   */
+  CXCursor_OMPParallelMasterDirective      = 285,
+
+  CXCursor_LastStmt = CXCursor_OMPParallelMasterDirective,
 
   /**
    * Cursor that represents the translation unit itself.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to