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 9void foo() {} 10 11struct S1 { 12 S1(): a(0) {} 13 S1(int v) : a(v) {} 14 int a; 15 typedef int type; 16 S1& operator +(const S1&); 17 S1& operator *(const S1&); 18 S1& operator &&(const S1&); 19 S1& operator ^(const S1&); 20}; 21 22template <typename T> 23class S7 : public T { 24protected: 25 T a; 26 T b[100]; 27 S7() : a(0) {} 28 29public: 30 S7(typename T::type v) : a(v) { 31#pragma omp parallel private(a) private(this->a) private(T::a) 32 for (int k = 0; k < a.a; ++k) 33 ++this->a.a; 34#pragma omp parallel firstprivate(a) firstprivate(this->a) firstprivate(T::a) 35 for (int k = 0; k < a.a; ++k) 36 ++this->a.a; 37#pragma omp parallel shared(a) shared(this->a) shared(T::a) 38 for (int k = 0; k < a.a; ++k) 39 ++this->a.a; 40#pragma omp parallel reduction(+ : a) reduction(*: b[:]) 41 for (int k = 0; k < a.a; ++k) 42 ++this->a.a; 43 } 44 S7 &operator=(S7 &s) { 45#pragma omp parallel private(a) private(this->a) 46 for (int k = 0; k < s.a.a; ++k) 47 ++s.a.a; 48#pragma omp parallel firstprivate(a) firstprivate(this->a) 49 for (int k = 0; k < s.a.a; ++k) 50 ++s.a.a; 51#pragma omp parallel shared(a) shared(this->a) 52 for (int k = 0; k < s.a.a; ++k) 53 ++s.a.a; 54#pragma omp parallel reduction(&& : this->a) reduction(^: b[s.a.a]) 55 for (int k = 0; k < s.a.a; ++k) 56 ++s.a.a; 57 return *this; 58 } 59}; 60 61// CHECK: #pragma omp parallel private(this->a) private(this->a) private(this->S1::a) 62// CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a) firstprivate(this->S1::a) 63// CHECK: #pragma omp parallel shared(this->a) shared(this->a) shared(this->S1::a) 64// CHECK: #pragma omp parallel reduction(+: this->a) reduction(*: this->b[:]) 65// CHECK: #pragma omp parallel private(this->a) private(this->a) private(T::a) 66// CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a) firstprivate(T::a) 67// CHECK: #pragma omp parallel shared(this->a) shared(this->a) shared(T::a) 68// CHECK: #pragma omp parallel reduction(+: this->a) reduction(*: this->b[:]) 69// CHECK: #pragma omp parallel private(this->a) private(this->a) 70// CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a) 71// CHECK: #pragma omp parallel shared(this->a) shared(this->a) 72// CHECK: #pragma omp parallel reduction(&&: this->a) reduction(^: this->b[s.a.a]) 73 74class S8 : public S7<S1> { 75 S8() {} 76 77public: 78 S8(int v) : S7<S1>(v){ 79#pragma omp parallel private(a) private(this->a) private(S7 < S1 > ::a) 80 for (int k = 0; k < a.a; ++k) 81 ++this->a.a; 82#pragma omp parallel firstprivate(a) firstprivate(this->a) firstprivate(S7 < S1 > ::a) 83 for (int k = 0; k < a.a; ++k) 84 ++this->a.a; 85#pragma omp parallel shared(a) shared(this->a) shared(S7 < S1 > ::a) 86 for (int k = 0; k < a.a; ++k) 87 ++this->a.a; 88#pragma omp parallel reduction(^ : S7 < S1 > ::a) reduction(+ : S7 < S1 > ::b[ : S7 < S1 > ::a.a]) 89 for (int k = 0; k < a.a; ++k) 90 ++this->a.a; 91 } 92 S8 &operator=(S8 &s) { 93#pragma omp parallel private(a) private(this->a) 94 for (int k = 0; k < s.a.a; ++k) 95 ++s.a.a; 96#pragma omp parallel firstprivate(a) firstprivate(this->a) 97 for (int k = 0; k < s.a.a; ++k) 98 ++s.a.a; 99#pragma omp parallel shared(a) shared(this->a) 100 for (int k = 0; k < s.a.a; ++k) 101 ++s.a.a; 102#pragma omp parallel reduction(* : this->a) reduction(&&:this->b[a.a:]) 103 for (int k = 0; k < s.a.a; ++k) 104 ++s.a.a; 105 return *this; 106 } 107}; 108 109// CHECK: #pragma omp parallel private(this->a) private(this->a) private(this->S7<S1>::a) 110// CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a) firstprivate(this->S7<S1>::a) 111// CHECK: #pragma omp parallel shared(this->a) shared(this->a) shared(this->S7<S1>::a) 112// CHECK: #pragma omp parallel reduction(^: this->S7<S1>::a) reduction(+: this->S7<S1>::b[:this->S7<S1>::a.a]) 113// CHECK: #pragma omp parallel private(this->a) private(this->a) 114// CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a) 115// CHECK: #pragma omp parallel shared(this->a) shared(this->a) 116// CHECK: #pragma omp parallel reduction(*: this->a) reduction(&&: this->b[this->a.a:]) 117 118template <class T> 119struct S { 120 operator T() {return T();} 121 static T TS; 122 #pragma omp threadprivate(TS) 123}; 124 125// CHECK: template <class T = int> struct S { 126// CHECK: static int TS; 127// CHECK-NEXT: #pragma omp threadprivate(S<int>::TS) 128// CHECK-NEXT: } 129// CHECK: template <class T = long> struct S { 130// CHECK: static long TS; 131// CHECK-NEXT: #pragma omp threadprivate(S<long>::TS) 132// CHECK-NEXT: } 133// CHECK: template <class T> struct S { 134// CHECK: static T TS; 135// CHECK-NEXT: #pragma omp threadprivate(S::TS) 136// CHECK: }; 137 138template <typename T, int C> 139T tmain(T argc, T *argv) { 140 T b = argc, c, d, e, f, g; 141 static T a; 142 S<T> s; 143 T arr[C][10], arr1[C]; 144#pragma omp parallel 145 a=2; 146#pragma omp parallel default(none), private(argc,b) firstprivate(argv) shared (d) if (parallel:argc > 0) num_threads(C) copyin(S<T>::TS) proc_bind(master) reduction(+:c, arr1[argc]) reduction(max:e, arr[:C][0:10]) 147 foo(); 148#pragma omp parallel if (C) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:C][:argc]) reduction(&& : g) 149 foo(); 150 return 0; 151} 152 153// CHECK: template <typename T = int, int C = 5> int tmain(int argc, int *argv) { 154// CHECK-NEXT: int b = argc, c, d, e, f, g; 155// CHECK-NEXT: static int a; 156// CHECK-NEXT: S<int> s; 157// CHECK-NEXT: int arr[5][10], arr1[5]; 158// CHECK-NEXT: #pragma omp parallel 159// CHECK-NEXT: a = 2; 160// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(5) copyin(S<int>::TS) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:5][0:10]) 161// CHECK-NEXT: foo() 162// CHECK-NEXT: #pragma omp parallel if(5) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:5][:argc]) reduction(&&: g) 163// CHECK-NEXT: foo() 164// CHECK: template <typename T = long, int C = 1> long tmain(long argc, long *argv) { 165// CHECK-NEXT: long b = argc, c, d, e, f, g; 166// CHECK-NEXT: static long a; 167// CHECK-NEXT: S<long> s; 168// CHECK-NEXT: long arr[1][10], arr1[1]; 169// CHECK-NEXT: #pragma omp parallel 170// CHECK-NEXT: a = 2; 171// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(1) copyin(S<long>::TS) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:1][0:10]) 172// CHECK-NEXT: foo() 173// CHECK-NEXT: #pragma omp parallel if(1) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:1][:argc]) reduction(&&: g) 174// CHECK-NEXT: foo() 175// CHECK: template <typename T, int C> T tmain(T argc, T *argv) { 176// CHECK-NEXT: T b = argc, c, d, e, f, g; 177// CHECK-NEXT: static T a; 178// CHECK-NEXT: S<T> s; 179// CHECK-NEXT: T arr[C][10], arr1[C]; 180// CHECK-NEXT: #pragma omp parallel 181// CHECK-NEXT: a = 2; 182// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(C) copyin(S<T>::TS) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:C][0:10]) 183// CHECK-NEXT: foo() 184// CHECK-NEXT: #pragma omp parallel if(C) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:C][:argc]) reduction(&&: g) 185// CHECK-NEXT: foo() 186 187enum Enum { }; 188 189int main (int argc, char **argv) { 190 long x; 191 int b = argc, c, d, e, f, g; 192 static int a; 193 #pragma omp threadprivate(a) 194 int arr[10][argc], arr1[2]; 195 Enum ee; 196// CHECK: Enum ee; 197#pragma omp parallel 198// CHECK-NEXT: #pragma omp parallel 199 a=2; 200// CHECK-NEXT: a = 2; 201#pragma omp parallel default(none), private(argc,b) firstprivate(argv) if (parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(| : c, d, arr1[argc]) reduction(* : e, arr[:10][0:argc]) 202// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) if(parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(|: c,d,arr1[argc]) reduction(*: e,arr[:10][0:argc]) 203 foo(); 204// CHECK-NEXT: foo(); 205// CHECK-NEXT: #pragma omp parallel if(b) num_threads(c) proc_bind(close) reduction(^: e,f) reduction(&&: g,arr[0:argc][:10]) 206// CHECK-NEXT: foo() 207#pragma omp parallel if (b) num_threads(c) proc_bind(close) reduction(^:e, f) reduction(&& : g, arr[0:argc][:10]) 208 foo(); 209 return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x); 210} 211 212template <class T> 213struct Foo { 214 int foo; 215}; 216 217void foo(const Foo<int> &arg) { 218// CHECK: #pragma omp parallel 219#pragma omp parallel 220 { 221// CHECK: #pragma omp for schedule(static) 222#pragma omp for schedule(static) 223 for (int idx = 0; idx < 1234; ++idx) { 224 //arg.foo = idx; 225 idx = arg.foo; 226 } 227 } 228} 229 230template<typename T> 231T S<T>::TS = 0; 232 233#endif 234