[OPENMP] Parsing and sema analysis for 'omp task' directive.

llvm-svn: 212804
diff --git a/clang/test/OpenMP/nesting_of_regions.cpp b/clang/test/OpenMP/nesting_of_regions.cpp
index 2c58e0b..f56cc0e 100644
--- a/clang/test/OpenMP/nesting_of_regions.cpp
+++ b/clang/test/OpenMP/nesting_of_regions.cpp
@@ -35,6 +35,11 @@
   {
     bar();
   }
+#pragma omp parallel
+#pragma omp task
+  {
+    bar();
+  }
 
 // SIMD DIRECTIVE
 #pragma omp simd
@@ -89,6 +94,13 @@
       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();
+    }
+  }
 
 // FOR DIRECTIVE
 #pragma omp for
@@ -160,6 +172,13 @@
       bar();
     }
   }
+#pragma omp for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp task
+    {
+      bar();
+    }
+  }
 
 // SECTIONS DIRECTIVE
 #pragma omp sections
@@ -232,12 +251,123 @@
       bar();
     }
   }
+#pragma omp sections
+  {
+#pragma omp task
+    {
+      bar();
+    }
+  }
 
 // SECTION DIRECTIVE
 #pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}}
   {
     bar();
   }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp for // expected-error {{region cannot be closely nested inside 'section' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
+      for (int i = 0; i < 10; ++i)
+        ;
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp simd
+      for (int i = 0; i < 10; ++i)
+        ;
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp parallel
+      for (int i = 0; i < 10; ++i)
+        ;
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp sections // expected-error {{region cannot be closely nested inside 'section' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}}
+      {
+        bar();
+      }
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a section region}}
+      {
+        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 sections
+  {
+#pragma omp section
+    {
+#pragma omp parallel
+      {
+#pragma omp single // OK
+        {
+          bar();
+        }
+#pragma omp for // OK
+        for (int i = 0; i < 10; ++i)
+          ;
+#pragma omp sections // OK
+        {
+          bar();
+        }
+      }
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp parallel for
+      for (int i = 0; i < 10; ++i)
+        ;
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp parallel sections
+      {
+        bar();
+      }
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp task
+      {
+        bar();
+      }
+    }
+  }
 
 // SINGLE DIRECTIVE
 #pragma omp single
@@ -302,6 +432,13 @@
       bar();
     }
   }
+#pragma omp single
+  {
+#pragma omp task
+    {
+      bar();
+    }
+  }
 
 // PARALLEL FOR DIRECTIVE
 #pragma omp parallel for
@@ -373,6 +510,13 @@
       bar();
     }
   }
+#pragma omp parallel for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp task
+    {
+      bar();
+    }
+  }
 
 // PARALLEL SECTIONS DIRECTIVE
 #pragma omp parallel sections
@@ -445,6 +589,50 @@
       bar();
     }
   }
+#pragma omp parallel sections
+  {
+#pragma omp task
+    {
+      bar();
+    }
+  }
+
+// TASK DIRECTIVE
+#pragma omp task
+#pragma omp for // expected-error {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp task
+#pragma omp simd
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp task
+#pragma omp sections // expected-error {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}}
+  {
+    bar();
+  }
+#pragma omp task
+#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a task region}}
+  {
+    bar();
+  }
+#pragma omp task
+#pragma omp single // expected-error {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}}
+  bar();
+#pragma omp task
+#pragma omp parallel for
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp task
+#pragma omp parallel sections
+  {
+    bar();
+  }
+#pragma omp task
+#pragma omp task
+  {
+    bar();
+  }
 }
 
 void foo() {
@@ -484,6 +672,11 @@
   {
     bar();
   }
+#pragma omp parallel
+#pragma omp task
+  {
+    bar();
+  }
 
 // SIMD DIRECTIVE
 #pragma omp simd
@@ -536,6 +729,13 @@
       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();
+    }
+  }
 
 // FOR DIRECTIVE
 #pragma omp for
@@ -605,6 +805,13 @@
       bar();
     }
   }
+#pragma omp for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp task
+    {
+      bar();
+    }
+  }
 
 // SECTIONS DIRECTIVE
 #pragma omp sections
@@ -674,12 +881,123 @@
       bar();
     }
   }
+#pragma omp sections
+  {
+#pragma omp task
+    {
+      bar();
+    }
+  }
 
 // SECTION DIRECTIVE
 #pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}}
   {
     bar();
   }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp for // expected-error {{region cannot be closely nested inside 'section' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
+      for (int i = 0; i < 10; ++i)
+        ;
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp simd
+      for (int i = 0; i < 10; ++i)
+        ;
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp parallel
+      for (int i = 0; i < 10; ++i)
+        ;
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp sections // expected-error {{region cannot be closely nested inside 'section' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}}
+      {
+        bar();
+      }
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a section region}}
+      {
+        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 sections
+  {
+#pragma omp section
+    {
+#pragma omp parallel
+      {
+#pragma omp single // OK
+        {
+          bar();
+        }
+#pragma omp for // OK
+        for (int i = 0; i < 10; ++i)
+          ;
+#pragma omp sections // OK
+        {
+          bar();
+        }
+      }
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp parallel for
+      for (int i = 0; i < 10; ++i)
+        ;
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp parallel sections
+      {
+        bar();
+      }
+    }
+  }
+#pragma omp sections
+  {
+#pragma omp section
+    {
+#pragma omp task
+      {
+        bar();
+      }
+    }
+  }
 
 // SINGLE DIRECTIVE
 #pragma omp single
@@ -744,6 +1062,13 @@
       bar();
     }
   }
+#pragma omp single
+  {
+#pragma omp task
+    {
+      bar();
+    }
+  }
 
 // PARALLEL FOR DIRECTIVE
 #pragma omp parallel for
@@ -815,6 +1140,13 @@
       bar();
     }
   }
+#pragma omp parallel for
+  for (int i = 0; i < 10; ++i) {
+#pragma omp task
+    {
+      bar();
+    }
+  }
 
 // PARALLEL SECTIONS DIRECTIVE
 #pragma omp parallel sections
@@ -887,6 +1219,50 @@
       bar();
     }
   }
+#pragma omp parallel sections
+  {
+#pragma omp task
+    {
+      bar();
+    }
+  }
+
+// TASK DIRECTIVE
+#pragma omp task
+#pragma omp for // expected-error {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp task
+#pragma omp simd
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp task
+#pragma omp sections // expected-error {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}}
+  {
+    bar();
+  }
+#pragma omp task
+#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a task region}}
+  {
+    bar();
+  }
+#pragma omp task
+#pragma omp single // expected-error {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}}
+  bar();
+#pragma omp task
+#pragma omp parallel for
+  for (int i = 0; i < 10; ++i)
+    ;
+#pragma omp task
+#pragma omp parallel sections
+  {
+    bar();
+  }
+#pragma omp task
+#pragma omp task
+  {
+    bar();
+  }
   return foo<int>();
 }
 
diff --git a/clang/test/OpenMP/parallel_sections_private_messages.cpp b/clang/test/OpenMP/parallel_sections_private_messages.cpp
index 9bcae83..7d39c7e 100644
--- a/clang/test/OpenMP/parallel_sections_private_messages.cpp
+++ b/clang/test/OpenMP/parallel_sections_private_messages.cpp
@@ -96,7 +96,7 @@
   {
     foo();
   }
-#pragma omp parallel sections copyprivate(i) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel sections'}}
+#pragma omp parallel sections copyprivate(h) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel sections'}}
   {
     foo();
   }
@@ -176,7 +176,7 @@
   {
     foo();
   }
-#pragma omp parallel sections copyprivate(i) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel sections'}}
+#pragma omp parallel sections copyprivate(h) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel sections'}}
   {
     foo();
   }
diff --git a/clang/test/OpenMP/task_ast_print.cpp b/clang/test/OpenMP/task_ast_print.cpp
new file mode 100644
index 0000000..cf4198e
--- /dev/null
+++ b/clang/test/OpenMP/task_ast_print.cpp
@@ -0,0 +1,96 @@
+// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp=libiomp5 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+void foo() {}
+
+template <class T>
+struct S {
+  operator T() { return T(); }
+  static T TS;
+#pragma omp threadprivate(TS)
+};
+
+// CHECK:      template <class T = int> struct S {
+// CHECK:        static int TS;
+// CHECK-NEXT:   #pragma omp threadprivate(S<int>::TS)
+// CHECK-NEXT: }
+// CHECK:      template <class T = long> struct S {
+// CHECK:        static long TS;
+// CHECK-NEXT:   #pragma omp threadprivate(S<long>::TS)
+// CHECK-NEXT: }
+// CHECK:      template <class T> struct S {
+// CHECK:        static T TS;
+// CHECK-NEXT:   #pragma omp threadprivate(S::TS)
+// CHECK:      };
+
+template <typename T, int C>
+T tmain(T argc, T *argv) {
+  T b = argc, c, d, e, f, g;
+  static T a;
+  S<T> s;
+#pragma omp task
+  a = 2;
+#pragma omp task default(none), private(argc, b) firstprivate(argv) shared(d) if (argc > 0)
+  foo();
+#pragma omp task if (C)
+  foo();
+  return 0;
+}
+
+// CHECK: template <typename T = int, int C = 5> int tmain(int argc, int *argv) {
+// CHECK-NEXT: int b = argc, c, d, e, f, g;
+// CHECK-NEXT: static int a;
+// CHECK-NEXT: S<int> s;
+// CHECK-NEXT: #pragma omp task
+// CHECK-NEXT: a = 2;
+// CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0)
+// CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp task if(5)
+// CHECK-NEXT: foo()
+// CHECK: template <typename T = long, int C = 1> long tmain(long argc, long *argv) {
+// CHECK-NEXT: long b = argc, c, d, e, f, g;
+// CHECK-NEXT: static long a;
+// CHECK-NEXT: S<long> s;
+// CHECK-NEXT: #pragma omp task
+// CHECK-NEXT: a = 2;
+// CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0)
+// CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp task if(1)
+// CHECK-NEXT: foo()
+// CHECK: template <typename T, int C> T tmain(T argc, T *argv) {
+// CHECK-NEXT: T b = argc, c, d, e, f, g;
+// CHECK-NEXT: static T a;
+// CHECK-NEXT: S<T> s;
+// CHECK-NEXT: #pragma omp task
+// CHECK-NEXT: a = 2;
+// CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0)
+// CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp task if(C)
+// CHECK-NEXT: foo()
+
+enum Enum {};
+
+int main(int argc, char **argv) {
+  long x;
+  int b = argc, c, d, e, f, g;
+  static int a;
+#pragma omp threadprivate(a)
+  Enum ee;
+// CHECK: Enum ee;
+#pragma omp task
+  // CHECK-NEXT: #pragma omp task
+  a = 2;
+// CHECK-NEXT: a = 2;
+#pragma omp task default(none), private(argc, b) firstprivate(argv) if (argc > 0)
+  // CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) if(argc > 0)
+  foo();
+  // CHECK-NEXT: foo();
+  return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);
+}
+
+#endif
diff --git a/clang/test/OpenMP/task_default_messages.cpp b/clang/test/OpenMP/task_default_messages.cpp
new file mode 100644
index 0000000..8da6b1a
--- /dev/null
+++ b/clang/test/OpenMP/task_default_messages.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 -o - %s
+
+void foo();
+
+int main(int argc, char **argv) {
+#pragma omp task default                          // expected-error {{expected '(' after 'default'}}
+#pragma omp task default(                         // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+#pragma omp task default()                        // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}}
+#pragma omp task default(none                     // expected-error {{expected ')'}} expected-note {{to match this '('}}
+#pragma omp task default(shared), default(shared) // expected-error {{directive '#pragma omp task' cannot contain more than one 'default' clause}}
+#pragma omp task default(x)                       // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}}
+  foo();
+
+#pragma omp task default(none)
+  ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
+
+#pragma omp task default(none)
+#pragma omp task default(shared)
+  ++argc;
+  return 0;
+}
diff --git a/clang/test/OpenMP/task_firstprivate_messages.cpp b/clang/test/OpenMP/task_firstprivate_messages.cpp
new file mode 100644
index 0000000..85d3f9f
--- /dev/null
+++ b/clang/test/OpenMP/task_firstprivate_messages.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 %s
+
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
+extern S1 a;
+class S2 {
+  mutable int a;
+
+public:
+  S2() : a(0) {}
+  S2(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;
+
+public:
+  S3() : a(0) {}
+  S3(S3 &s3) : a(s3.a) {}
+};
+const S3 c;
+const S3 ca[5];
+extern const int f;
+class S4 { // expected-note {{'S4' declared here}}
+  int a;
+  S4();
+  S4(const S4 &s4);
+
+public:
+  S4(int v) : a(v) {}
+};
+class S5 { // expected-note {{'S5' declared here}}
+  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}}
+
+int main(int argc, char **argv) {
+  const int d = 5;
+  const int da[5] = {0};
+  S4 e(4); // expected-note {{'e' defined here}}
+  S5 g(5); // expected-note {{'g' defined here}}
+  int i;
+  int &j = i;                                               // expected-note {{'j' defined here}}
+#pragma omp task firstprivate                               // expected-error {{expected '(' after 'firstprivate'}}
+#pragma omp task firstprivate(                              // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+#pragma omp task firstprivate()                             // expected-error {{expected expression}}
+#pragma omp task firstprivate(argc                          // expected-error {{expected ')'}} expected-note {{to match this '('}}
+#pragma omp task firstprivate(argc,                         // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+#pragma omp task firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+#pragma omp task firstprivate(argc)
+#pragma omp task firstprivate(S1)            // expected-error {{'S1' does not refer to a value}}
+#pragma omp task firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
+#pragma omp task firstprivate(argv[1])       // expected-error {{expected variable name}}
+#pragma omp task firstprivate(ba)
+#pragma omp task firstprivate(ca)
+#pragma omp task firstprivate(da)
+#pragma omp task firstprivate(S2::S2s)
+#pragma omp task firstprivate(S2::S2sc)
+#pragma omp task firstprivate(e, g)          // expected-error 2 {{firstprivate variable must have an accessible, unambiguous copy constructor}}
+#pragma omp task firstprivate(h)             // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
+#pragma omp task private(i), firstprivate(i) // expected-error {{private variable cannot be firstprivate}} expected-note{{defined as private}}
+  foo();
+#pragma omp task shared(i)
+#pragma omp task firstprivate(i)
+#pragma omp task firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}}
+  foo();
+
+  return 0;
+}
diff --git a/clang/test/OpenMP/task_if_messages.cpp b/clang/test/OpenMP/task_if_messages.cpp
new file mode 100644
index 0000000..51900c0
--- /dev/null
+++ b/clang/test/OpenMP/task_if_messages.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 %s
+
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+struct S1; // expected-note {{declared here}}
+
+template <class T, class S> // expected-note {{declared here}}
+int tmain(T argc, S **argv) {
+  #pragma omp task if // expected-error {{expected '(' after 'if'}}
+  #pragma omp task if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  #pragma omp task if () // expected-error {{expected expression}}
+  #pragma omp task if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  #pragma omp task if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
+  #pragma omp task if (argc > 0 ? argv[1] : argv[2])
+  #pragma omp task if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp task' cannot contain more than one 'if' clause}}
+  #pragma omp task if (S) // expected-error {{'S' does not refer to a value}}
+  #pragma omp task if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  #pragma omp task if (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  #pragma omp task if(argc)
+  foo();
+
+  return 0;
+}
+
+int main(int argc, char **argv) {
+  #pragma omp task if // expected-error {{expected '(' after 'if'}}
+  #pragma omp task if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  #pragma omp task if () // expected-error {{expected expression}}
+  #pragma omp task if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  #pragma omp task if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
+  #pragma omp task if (argc > 0 ? argv[1] : argv[2])
+  #pragma omp task if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp task' cannot contain more than one 'if' clause}}
+  #pragma omp task if (S1) // expected-error {{'S1' does not refer to a value}}
+  #pragma omp task if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  #pragma omp task if (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  #pragma omp task if (1 0) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  #pragma omp task if(if(tmain(argc, argv) // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  foo();
+
+  return tmain(argc, argv);
+}
diff --git a/clang/test/OpenMP/task_messages.cpp b/clang/test/OpenMP/task_messages.cpp
new file mode 100644
index 0000000..3c89682
--- /dev/null
+++ b/clang/test/OpenMP/task_messages.cpp
@@ -0,0 +1,263 @@
+// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 -std=c++11 -o - %s
+
+void foo() {
+}
+
+#pragma omp task // expected-error {{unexpected OpenMP directive '#pragma omp task'}}
+
+class S { // expected-note 6 {{'S' declared here}}
+  S(const S &s) { a = s.a + 12; }
+  int a;
+
+public:
+  S() : a(0) {}
+  S(int a) : a(a) {}
+  operator int() { return a; }
+  S &operator++() { return *this; }
+  S operator+(const S &) { return *this; }
+};
+
+template <class T>
+int foo() {
+  T a; // expected-note 3 {{'a' defined here}}
+  T &b = a; // expected-note 4 {{'b' defined here}}
+  int r;
+#pragma omp task default(none)
+#pragma omp task default(shared)
+  ++a;
+// expected-error@+2 {{predetermined as a firstprivate in a task construct variable must have an accessible, unambiguous copy constructor}}
+#pragma omp task default(none)
+#pragma omp task
+// expected-note@+1 {{used here}}
+  ++a;
+#pragma omp task
+// expected-error@+1 {{predetermined as a firstprivate in a task construct variable must have an accessible, unambiguous copy constructor}}
+#pragma omp task
+  // expected-note@+1 {{used here}}
+  ++a;
+#pragma omp task default(shared)
+#pragma omp task
+  ++a;
+#pragma omp task
+#pragma omp parallel
+  ++a;
+// expected-error@+2 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'int &'}}
+// expected-error@+1 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'S &'}}
+#pragma omp task
+  // expected-note@+1 2 {{used here}}
+  ++b;
+// expected-error@+3 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'int &'}}
+// expected-error@+2 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'S &'}}
+// expected-error@+1 {{predetermined as a firstprivate in a task construct variable must have an accessible, unambiguous copy constructor}}
+#pragma omp task
+// expected-note@+1 3 {{used here}}
+#pragma omp parallel shared(a, b)
+  ++a, ++b;
+// expected-note@+1 3 {{defined as reduction}}
+#pragma omp parallel reduction(+ : r)
+// expected-error@+1 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}}
+#pragma omp task firstprivate(r)
+  // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
+  ++r;
+// expected-note@+1 2 {{defined as reduction}}
+#pragma omp parallel reduction(+ : r)
+#pragma omp task default(shared)
+  // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
+  ++r;
+// expected-note@+1 2 {{defined as reduction}}
+#pragma omp parallel reduction(+ : r)
+#pragma omp task
+  // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
+  ++r;
+#pragma omp parallel
+// expected-note@+1 3 {{defined as reduction}}
+#pragma omp for reduction(+ : r)
+  for (int i = 0; i < 10; ++i)
+// expected-error@+1 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}}
+#pragma omp task firstprivate(r)
+    // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
+    ++r;
+#pragma omp parallel
+// expected-note@+1 2 {{defined as reduction}}
+#pragma omp for reduction(+ : r)
+  for (int i = 0; i < 10; ++i)
+#pragma omp task default(shared)
+    // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
+    ++r;
+#pragma omp parallel
+// expected-note@+1 2 {{defined as reduction}}
+#pragma omp for reduction(+ : r)
+  for (int i = 0; i < 10; ++i)
+#pragma omp task
+    // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
+    ++r;
+// expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}}
+#pragma omp task
+// expected-error@+2 {{reduction variable must be shared}}
+// expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
+#pragma omp for reduction(+ : r)
+  ++r;
+  return a + b;
+}
+
+int main(int argc, char **argv) {
+  int a;
+  int &b = a; // expected-note 2 {{'b' defined here}}
+  S sa;       // expected-note 3 {{'sa' defined here}}
+  S &sb = sa; // expected-note 2 {{'sb' defined here}}
+  int r;
+#pragma omp task { // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
+  foo();
+#pragma omp task( // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
+  foo();
+#pragma omp task[ // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
+  foo();
+#pragma omp task] // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
+  foo();
+#pragma omp task) // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
+  foo();
+#pragma omp task } // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
+  foo();
+#pragma omp task
+// expected-warning@+1 {{extra tokens at the end of '#pragma omp task' are ignored}}
+#pragma omp task unknown()
+  foo();
+L1:
+  foo();
+#pragma omp task
+  ;
+#pragma omp task
+  {
+    goto L1; // expected-error {{use of undeclared label 'L1'}}
+    argc++;
+  }
+
+  for (int i = 0; i < 10; ++i) {
+    switch (argc) {
+    case (0):
+#pragma omp task
+    {
+      foo();
+      break;    // expected-error {{'break' statement not in loop or switch statement}}
+      continue; // expected-error {{'continue' statement not in loop statement}}
+    }
+    default:
+      break;
+    }
+  }
+#pragma omp task default(none)
+  ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
+
+  goto L2; // expected-error {{use of undeclared label 'L2'}}
+#pragma omp task
+L2:
+  foo();
+#pragma omp task
+  {
+    return 1; // expected-error {{cannot return from OpenMP region}}
+  }
+
+  [[]] // expected-error {{an attribute list cannot appear here}}
+#pragma omp task
+      for (int n = 0; n < 100; ++n) {
+  }
+
+#pragma omp task default(none)
+#pragma omp task default(shared)
+  ++a;
+#pragma omp task default(none)
+#pragma omp task
+  ++a;
+#pragma omp task default(shared)
+#pragma omp task
+  ++a;
+#pragma omp task
+#pragma omp parallel
+  ++a;
+// expected-error@+1 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'int &'}}
+#pragma omp task
+  // expected-note@+1 {{used here}}
+  ++b;
+// expected-error@+1 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'int &'}}
+#pragma omp task
+// expected-note@+1 {{used here}}
+#pragma omp parallel shared(a, b)
+  ++a, ++b;
+#pragma omp task default(none)
+#pragma omp task default(shared)
+  ++sa;
+#pragma omp task default(none)
+// expected-error@+1 {{predetermined as a firstprivate in a task construct variable must have an accessible, unambiguous copy constructor}}
+#pragma omp task
+// expected-note@+1 {{used here}}
+  ++sa;
+#pragma omp task
+// expected-error@+1 {{predetermined as a firstprivate in a task construct variable must have an accessible, unambiguous copy constructor}}
+#pragma omp task
+// expected-note@+1 {{used here}}
+  ++sa;
+#pragma omp task default(shared)
+#pragma omp task
+  ++sa;
+#pragma omp task
+#pragma omp parallel
+  ++sa;
+// expected-error@+1 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'S &'}}
+#pragma omp task
+  // expected-note@+1 {{used here}}
+  ++sb;
+// expected-error@+2 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'S &'}}
+// expected-error@+1 {{predetermined as a firstprivate in a task construct variable must have an accessible, unambiguous copy constructor}}
+#pragma omp task
+// expected-note@+1 2 {{used here}}
+#pragma omp parallel shared(sa, sb)
+  ++sa, ++sb;
+// expected-note@+1 2 {{defined as reduction}}
+#pragma omp parallel reduction(+ : r)
+// expected-error@+1 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}}
+#pragma omp task firstprivate(r)
+  // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
+  ++r;
+// expected-note@+1 {{defined as reduction}}
+#pragma omp parallel reduction(+ : r)
+#pragma omp task default(shared)
+  // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
+  ++r;
+// expected-note@+1 {{defined as reduction}}
+#pragma omp parallel reduction(+ : r)
+#pragma omp task
+  // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
+  ++r;
+#pragma omp parallel
+// expected-note@+1 2 {{defined as reduction}}
+#pragma omp for reduction(+ : r)
+  for (int i = 0; i < 10; ++i)
+// expected-error@+1 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}}
+#pragma omp task firstprivate(r)
+    // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
+    ++r;
+#pragma omp parallel
+// expected-note@+1 {{defined as reduction}}
+#pragma omp for reduction(+ : r)
+  for (int i = 0; i < 10; ++i)
+#pragma omp task default(shared)
+    // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
+    ++r;
+#pragma omp parallel
+// expected-note@+1 {{defined as reduction}}
+#pragma omp for reduction(+ : r)
+  for (int i = 0; i < 10; ++i)
+#pragma omp task
+    // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
+    ++r;
+// expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}}
+#pragma omp task
+// expected-error@+2 {{reduction variable must be shared}}
+// expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
+#pragma omp for reduction(+ : r)
+  ++r;
+  // expected-note@+2 {{in instantiation of function template specialization 'foo<int>' requested here}}
+  // expected-note@+1 {{in instantiation of function template specialization 'foo<S>' requested here}}
+  return foo<int>() + foo<S>();
+}
+
diff --git a/clang/test/OpenMP/task_private_messages.cpp b/clang/test/OpenMP/task_private_messages.cpp
new file mode 100644
index 0000000..0be238d
--- /dev/null
+++ b/clang/test/OpenMP/task_private_messages.cpp
@@ -0,0 +1,85 @@
+// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 %s
+
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
+extern S1 a;
+class S2 {
+  mutable int a;
+
+public:
+  S2() : a(0) {}
+  static float S2s; // expected-note {{static data member is predetermined as shared}}
+};
+const S2 b;
+const S2 ba[5];
+class S3 {
+  int a;
+
+public:
+  S3() : a(0) {}
+};
+const S3 c;         // expected-note {{global variable is predetermined as shared}}
+const S3 ca[5];     // expected-note {{global variable is predetermined as shared}}
+extern const int f; // expected-note {{global variable is predetermined as shared}}
+class S4 {          // expected-note {{'S4' declared here}}
+  int a;
+  S4();
+
+public:
+  S4(int v) : a(v) {}
+};
+class S5 { // expected-note {{'S5' declared here}}
+  int a;
+  S5() : a(0) {}
+
+public:
+  S5(int v) : a(v) {}
+};
+
+int threadvar;
+#pragma omp threadprivate(threadvar) // expected-note {{defined as threadprivate or thread local}}
+
+int main(int argc, char **argv) {
+  const int d = 5;       // expected-note {{constant variable is predetermined as shared}}
+  const int da[5] = {0}; // expected-note {{constant variable is predetermined as shared}}
+  S4 e(4);               // expected-note {{'e' defined here}}
+  S5 g(5);               // expected-note {{'g' defined here}}
+  int i;
+  int &j = i;                                          // expected-note {{'j' defined here}}
+#pragma omp task private                               // expected-error {{expected '(' after 'private'}}
+#pragma omp task private(                              // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+#pragma omp task private()                             // expected-error {{expected expression}}
+#pragma omp task private(argc                          // expected-error {{expected ')'}} expected-note {{to match this '('}}
+#pragma omp task private(argc,                         // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+#pragma omp task private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+#pragma omp task private(argc argv)                    // expected-error {{expected ',' or ')' in 'private' clause}}
+#pragma omp task private(S1)                           // expected-error {{'S1' does not refer to a value}}
+#pragma omp task private(a, b, c, d, f)                // expected-error {{a private variable with incomplete type 'S1'}} expected-error 3 {{shared variable cannot be private}}
+#pragma omp task private(argv[1])                      // expected-error {{expected variable name}}
+#pragma omp task private(ba)
+#pragma omp task private(ca)           // expected-error {{shared variable cannot be private}}
+#pragma omp task private(da)           // expected-error {{shared variable cannot be private}}
+#pragma omp task private(S2::S2s)      // expected-error {{shared variable cannot be private}}
+#pragma omp task private(e, g)         // expected-error 2 {{private variable must have an accessible, unambiguous default constructor}}
+#pragma omp task private(threadvar)    // expected-error {{threadprivate or thread local variable cannot be private}}
+#pragma omp task shared(i), private(i) // expected-error {{shared variable cannot be private}} expected-note {{defined as shared}}
+  foo();
+#pragma omp task firstprivate(i) private(i) // expected-error {{firstprivate variable cannot be private}} expected-note {{defined as firstprivate}}
+  foo();
+#pragma omp task private(i)
+#pragma omp task private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type 'int &'}}
+  foo();
+#pragma omp task firstprivate(i)
+  for (int k = 0; k < 10; ++k) {
+#pragma omp task private(i)
+    foo();
+  }
+
+  return 0;
+}
diff --git a/clang/test/OpenMP/task_shared_messages.cpp b/clang/test/OpenMP/task_shared_messages.cpp
new file mode 100644
index 0000000..7479237
--- /dev/null
+++ b/clang/test/OpenMP/task_shared_messages.cpp
@@ -0,0 +1,102 @@
+// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 %s
+
+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}}
+
+int main(int argc, char **argv) {
+  const int d = 5;
+  const int da[5] = {0};
+  S4 e(4);
+  S5 g(5);
+  int i;
+  int &j = i;
+#pragma omp task shared                               // expected-error {{expected '(' after 'shared'}}
+  foo();
+#pragma omp task shared(                              // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  foo();
+#pragma omp task shared()                             // expected-error {{expected expression}}
+  foo();
+#pragma omp task shared(argc                          // expected-error {{expected ')'}} expected-note {{to match this '('}}
+  foo();
+#pragma omp task shared(argc,                         // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+  foo();
+#pragma omp task shared(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
+  foo();
+#pragma omp task shared(argc)
+  foo();
+#pragma omp task shared(S1) // expected-error {{'S1' does not refer to a value}}
+  foo();
+#pragma omp task shared(a, b, c, d, f)
+  foo();
+#pragma omp task shared(argv[1]) // expected-error {{expected variable name}}
+  foo();
+#pragma omp task shared(ba)
+  foo();
+#pragma omp task shared(ca)
+  foo();
+#pragma omp task shared(da)
+  foo();
+#pragma omp task shared(e, g)
+  foo();
+#pragma omp task shared(h)             // expected-error {{threadprivate or thread local variable cannot be shared}}
+  foo();
+#pragma omp task private(i), shared(i) // expected-error {{private variable cannot be shared}} expected-note {{defined as private}}
+  foo();
+#pragma omp task firstprivate(i), shared(i) // expected-error {{firstprivate variable cannot be shared}} expected-note {{defined as firstprivate}}
+  foo();
+#pragma omp parallel private(i)
+#pragma omp task shared(i)
+#pragma omp task shared(j)
+  foo();
+#pragma omp parallel firstprivate(i)
+#pragma omp task shared(i)
+#pragma omp task shared(j)
+  foo();
+
+  return 0;
+}