1 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s 2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s 3 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s 4 // expected-no-diagnostics 5 6 #ifndef HEADER 7 #define HEADER 8 9 struct S { 10 S(): a(0) {} 11 S(int v) : a(v) {} 12 int a; 13 typedef int type; 14 }; 15 16 template <typename T> 17 class S7 : public T { 18 protected: 19 T a; 20 S7() : a(0) {} 21 22 public: 23 S7(typename T::type v) : a(v) { 24 #pragma omp target 25 #pragma omp teams 26 #pragma omp distribute parallel for private(a) private(this->a) private(T::a) 27 for (int k = 0; k < a.a; ++k) 28 ++this->a.a; 29 } 30 S7 &operator=(S7 &s) { 31 #pragma omp target 32 #pragma omp teams 33 #pragma omp distribute parallel for private(a) private(this->a) 34 for (int k = 0; k < s.a.a; ++k) 35 ++s.a.a; 36 return *this; 37 } 38 }; 39 40 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a) private(this->S::a) 41 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a) private(T::a) 42 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a) 43 44 class S8 : public S7<S> { 45 S8() {} 46 47 public: 48 S8(int v) : S7<S>(v){ 49 #pragma omp target 50 #pragma omp teams 51 #pragma omp distribute parallel for private(a) private(this->a) private(S7<S>::a) 52 for (int k = 0; k < a.a; ++k) 53 ++this->a.a; 54 } 55 S8 &operator=(S8 &s) { 56 #pragma omp target 57 #pragma omp teams 58 #pragma omp distribute parallel for private(a) private(this->a) 59 for (int k = 0; k < s.a.a; ++k) 60 ++s.a.a; 61 return *this; 62 } 63 }; 64 65 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a) private(this->S7<S>::a) 66 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a) 67 68 template <class T, int N> 69 T tmain(T argc) { 70 T b = argc, c, d, e, f, h; 71 static T a; 72 // CHECK: static T a; 73 static T g; 74 #pragma omp threadprivate(g) 75 #pragma omp target 76 #pragma omp teams 77 #pragma omp distribute parallel for dist_schedule(static, a) schedule(dynamic) default(none) copyin(g) firstprivate(a) 78 // CHECK: #pragma omp distribute parallel for dist_schedule(static, a) schedule(dynamic) default(none) copyin(g) 79 for (int i = 0; i < 2; ++i) 80 a = 2; 81 // CHECK-NEXT: for (int i = 0; i < 2; ++i) 82 // CHECK-NEXT: a = 2; 83 #pragma omp target 84 #pragma omp teams 85 #pragma omp distribute parallel for private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h) dist_schedule(static,N) 86 for (int i = 0; i < 2; ++i) 87 for (int j = 0; j < 2; ++j) 88 for (int j = 0; j < 2; ++j) 89 for (int j = 0; j < 2; ++j) 90 for (int j = 0; j < 2; ++j) 91 for (int i = 0; i < 2; ++i) 92 for (int j = 0; j < 2; ++j) 93 for (int j = 0; j < 2; ++j) 94 for (int j = 0; j < 2; ++j) 95 for (int j = 0; j < 2; ++j) 96 a++; 97 // CHECK: #pragma omp distribute parallel for private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h) dist_schedule(static, N) 98 // CHECK-NEXT: for (int i = 0; i < 2; ++i) 99 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 100 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 101 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 102 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 103 // CHECK-NEXT: for (int i = 0; i < 2; ++i) 104 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 105 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 106 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 107 // CHECK-NEXT: for (int j = 0; j < 2; ++j) 108 // CHECK-NEXT: a++; 109 return T(); 110 } 111 112 int main(int argc, char **argv) { 113 int b = argc, c, d, e, f, h; 114 static int a; 115 // CHECK: static int a; 116 static float g; 117 #pragma omp threadprivate(g) 118 #pragma omp target 119 #pragma omp teams 120 #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) 121 // CHECK: #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) 122 for (int i = 0; i < 2; ++i) 123 a = 2; 124 // CHECK-NEXT: for (int i = 0; i < 2; ++i) 125 // CHECK-NEXT: a = 2; 126 #pragma omp target 127 #pragma omp teams 128 #pragma omp distribute parallel for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) if (argc) num_threads(a) default(shared) shared(e) reduction(+ : h) dist_schedule(static, b) 129 for (int i = 0; i < 10; ++i) 130 for (int j = 0; j < 10; ++j) 131 a++; 132 // CHECK: #pragma omp distribute parallel for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) if(argc) num_threads(a) default(shared) shared(e) reduction(+: h) dist_schedule(static, b) 133 // CHECK-NEXT: for (int i = 0; i < 10; ++i) 134 // CHECK-NEXT: for (int j = 0; j < 10; ++j) 135 // CHECK-NEXT: a++; 136 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0])); 137 } 138 139 #endif 140