| 1 |
// RUN: %clang_cc1 -verify -Wno-vla -fopenmp -ast-print %s | FileCheck %s |
| 2 |
// RUN: %clang_cc1 -verify -Wno-vla -fopenmp -fopenmp-version=60 -DOMP60 -ast-print %s | FileCheck %s --check-prefix=CHECK60 |
| 3 |
// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s |
| 4 |
// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -verify -Wno-vla %s -ast-print | FileCheck %s |
| 5 |
|
| 6 |
// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -ast-print %s | FileCheck %s |
| 7 |
// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -fopenmp-version=60 -DOMP60 -ast-print %s | FileCheck %s --check-prefix=CHECK60 |
| 8 |
// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s |
| 9 |
// RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify -Wno-vla %s -ast-print | FileCheck %s |
| 10 |
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -ast-dump %s | FileCheck %s --check-prefix=DUMP |
| 11 |
// expected-no-diagnostics |
| 12 |
|
| 13 |
#ifndef HEADER |
| 14 |
#define HEADER |
| 15 |
|
| 16 |
typedef void *omp_depend_t; |
| 17 |
typedef unsigned long omp_event_handle_t; |
| 18 |
|
| 19 |
void foo() {} |
| 20 |
|
| 21 |
struct S1 { |
| 22 |
S1(): a(0) {} |
| 23 |
S1(int v) : a(v) {} |
| 24 |
int a; |
| 25 |
typedef int type; |
| 26 |
S1 operator +(const S1&); |
| 27 |
}; |
| 28 |
|
| 29 |
template <typename T> |
| 30 |
class S7 : public T { |
| 31 |
protected: |
| 32 |
T a, b, c[10], d[10]; |
| 33 |
S7() : a(0) {} |
| 34 |
|
| 35 |
public: |
| 36 |
S7(typename T::type v) : a(v) { |
| 37 |
omp_depend_t x; |
| 38 |
omp_event_handle_t evt; |
| 39 |
#pragma omp taskgroup allocate(b) task_reduction(+:b) |
| 40 |
#pragma omp task private(a) private(this->a) private(T::a) in_reduction(+:this->b) allocate(b) depend(depobj:x) detach(evt) depend(iterator(i=0:10:1, T *k = &a:&b), in: c[i], d[(int)(k-&a)]) affinity(iterator(i=0:10:1, T *k = &a:&b): c[i], d[(int)(k-&a)]) |
| 41 |
for (int k = 0; k < a.a; ++k) |
| 42 |
++this->a.a; |
| 43 |
} |
| 44 |
S7 &operator=(S7 &s) { |
| 45 |
#pragma omp task private(a) private(this->a) |
| 46 |
for (int k = 0; k < s.a.a; ++k) |
| 47 |
++s.a.a; |
| 48 |
return *this; |
| 49 |
} |
| 50 |
}; |
| 51 |
|
| 52 |
// CHECK: #pragma omp taskgroup allocate(this->b) task_reduction(+: this->b) |
| 53 |
// CHECK: #pragma omp task private(this->a) private(this->a) private(T::a) in_reduction(+: this->b) allocate(this->b) depend(depobj : x) detach(evt) depend(iterator(int i = 0:10:1, T * k = &this->a:&this->b), in : this->c[i],this->d[(int)(k - &this->a)]) affinity(iterator(int i = 0:10:1, T * k = &this->a:&this->b) : this->c[i],this->d[(int)(k - &this->a)]){{$}} |
| 54 |
// CHECK: #pragma omp task private(this->a) private(this->a) |
| 55 |
// CHECK: #pragma omp task private(this->a) private(this->a) private(this->S1::a) in_reduction(+: this->b) allocate(this->b) depend(depobj : x) detach(evt) depend(iterator(int i = 0:10:1, S1 * k = &this->a:&this->b), in : this->c[i],this->d[(int)(k - &this->a)]) affinity(iterator(int i = 0:10:1, S1 * k = &this->a:&this->b) : this->c[i],this->d[(int)(k - &this->a)]) |
| 56 |
|
| 57 |
class S8 : public S7<S1> { |
| 58 |
S8() {} |
| 59 |
|
| 60 |
public: |
| 61 |
S8(int v) : S7<S1>(v){ |
| 62 |
#pragma omp task private(a) private(this->a) private(S7<S1>::a) |
| 63 |
for (int k = 0; k < a.a; ++k) |
| 64 |
++this->a.a; |
| 65 |
} |
| 66 |
S8 &operator=(S8 &s) { |
| 67 |
#pragma omp task private(a) private(this->a) |
| 68 |
for (int k = 0; k < s.a.a; ++k) |
| 69 |
++s.a.a; |
| 70 |
return *this; |
| 71 |
} |
| 72 |
}; |
| 73 |
|
| 74 |
// CHECK: #pragma omp task private(this->a) private(this->a) private(this->S7<S1>::a) |
| 75 |
// CHECK: #pragma omp task private(this->a) private(this->a) |
| 76 |
|
| 77 |
template <class T> |
| 78 |
struct S { |
| 79 |
operator T() { return T(); } |
| 80 |
static T TS; |
| 81 |
#pragma omp threadprivate(TS) |
| 82 |
}; |
| 83 |
|
| 84 |
// CHECK: template <class T> struct S { |
| 85 |
// CHECK: static T TS; |
| 86 |
// CHECK-NEXT: #pragma omp threadprivate(S::TS) |
| 87 |
// CHECK: }; |
| 88 |
// CHECK: template<> struct S<int> { |
| 89 |
// CHECK: static int TS; |
| 90 |
// CHECK-NEXT: #pragma omp threadprivate(S<int>::TS) |
| 91 |
// CHECK-NEXT: } |
| 92 |
|
| 93 |
template <typename T, int C> |
| 94 |
T tmain(T argc, T *argv) { |
| 95 |
T b = argc, c, d, e, f, g; |
| 96 |
static T a; |
| 97 |
S<T> s; |
| 98 |
T arr[argc]; |
| 99 |
omp_depend_t x; |
| 100 |
omp_event_handle_t evt; |
| 101 |
double *arr_double; |
| 102 |
#pragma omp task untied depend(in : argc, argv[b:argc], arr[:], ([argc][sizeof(T)])argv, arr_double[argc]) if (task : argc > 0) depend(depobj: x) detach(evt) |
| 103 |
a = 2; |
| 104 |
#pragma omp task default(none), private(argc, b) firstprivate(argv) shared(d) if (argc > 0) final(S<T>::TS > 0) priority(argc) affinity(argc, argv[b:argc], arr[:], ([argc][sizeof(T)])argv) |
| 105 |
foo(); |
| 106 |
#pragma omp taskgroup task_reduction(+: argc) |
| 107 |
#pragma omp task if (C) mergeable priority(C) in_reduction(+: argc) |
| 108 |
foo(); |
| 109 |
return 0; |
| 110 |
} |
| 111 |
|
| 112 |
// CHECK: template <typename T, int C> T tmain(T argc, T *argv) { |
| 113 |
// CHECK-NEXT: T b = argc, c, d, e, f, g; |
| 114 |
// CHECK-NEXT: static T a; |
| 115 |
// CHECK-NEXT: S<T> s; |
| 116 |
// CHECK-NEXT: T arr[argc]; |
| 117 |
// CHECK-NEXT: omp_depend_t x; |
| 118 |
// CHECK-NEXT: omp_event_handle_t evt; |
| 119 |
// CHECK-NEXT: double *arr_double; |
| 120 |
// CHECK-NEXT: #pragma omp task untied depend(in : argc,argv[b:argc],arr[:],([argc][sizeof(T)])argv,arr_double[argc]) if(task: argc > 0) depend(depobj : x) detach(evt) |
| 121 |
// CHECK-NEXT: a = 2; |
| 122 |
// CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) final(S<T>::TS > 0) priority(argc) affinity(argc,argv[b:argc],arr[:],([argc][sizeof(T)])argv) |
| 123 |
// CHECK-NEXT: foo() |
| 124 |
// CHECK-NEXT: #pragma omp taskgroup task_reduction(+: argc) |
| 125 |
// CHECK-NEXT: #pragma omp task if(C) mergeable priority(C) in_reduction(+: argc) |
| 126 |
// CHECK-NEXT: foo() |
| 127 |
// CHECK: template<> int tmain<int, 5>(int argc, int *argv) { |
| 128 |
// CHECK-NEXT: int b = argc, c, d, e, f, g; |
| 129 |
// CHECK-NEXT: static int a; |
| 130 |
// CHECK-NEXT: S<int> s; |
| 131 |
// CHECK-NEXT: int arr[argc]; |
| 132 |
// CHECK-NEXT: omp_depend_t x; |
| 133 |
// CHECK-NEXT: omp_event_handle_t evt; |
| 134 |
// CHECK-NEXT: double *arr_double; |
| 135 |
// CHECK-NEXT: #pragma omp task untied depend(in : argc,argv[b:argc],arr[:],([argc][sizeof(int)])argv,arr_double[argc]) if(task: argc > 0) depend(depobj : x) detach(evt) |
| 136 |
// CHECK-NEXT: a = 2; |
| 137 |
// CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) final(S<int>::TS > 0) priority(argc) affinity(argc,argv[b:argc],arr[:],([argc][sizeof(int)])argv) |
| 138 |
// CHECK-NEXT: foo() |
| 139 |
// CHECK-NEXT: #pragma omp taskgroup task_reduction(+: argc) |
| 140 |
// CHECK-NEXT: #pragma omp task if(5) mergeable priority(5) in_reduction(+: argc) |
| 141 |
// CHECK-NEXT: foo() |
| 142 |
// CHECK: template<> long tmain<long, 1>(long argc, long *argv) { |
| 143 |
// CHECK-NEXT: long b = argc, c, d, e, f, g; |
| 144 |
// CHECK-NEXT: static long a; |
| 145 |
// CHECK-NEXT: S<long> s; |
| 146 |
// CHECK-NEXT: long arr[argc]; |
| 147 |
// CHECK-NEXT: omp_depend_t x; |
| 148 |
// CHECK-NEXT: omp_event_handle_t evt; |
| 149 |
// CHECK-NEXT: double *arr_double; |
| 150 |
// CHECK-NEXT: #pragma omp task untied depend(in : argc,argv[b:argc],arr[:],([argc][sizeof(long)])argv,arr_double[argc]) if(task: argc > 0) depend(depobj : x) detach(evt) |
| 151 |
// CHECK-NEXT: a = 2; |
| 152 |
// CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) final(S<long>::TS > 0) priority(argc) affinity(argc,argv[b:argc],arr[:],([argc][sizeof(long)])argv) |
| 153 |
// CHECK-NEXT: foo() |
| 154 |
// CHECK-NEXT: #pragma omp taskgroup task_reduction(+: argc) |
| 155 |
// CHECK-NEXT: #pragma omp task if(1) mergeable priority(1) in_reduction(+: argc) |
| 156 |
// CHECK-NEXT: foo() |
| 157 |
|
| 158 |
enum Enum {}; |
| 159 |
|
| 160 |
int main(int argc, char **argv) { |
| 161 |
long x; |
| 162 |
int b = argc, c, d, e, f, g; |
| 163 |
static int a; |
| 164 |
int arr[10], arr1[argc]; |
| 165 |
omp_depend_t y; |
| 166 |
omp_event_handle_t evt; |
| 167 |
#pragma omp threadprivate(a) |
| 168 |
Enum ee; |
| 169 |
// CHECK: Enum ee; |
| 170 |
#pragma omp task untied mergeable depend(out:argv[:a][1], (arr)[0:],([argc][10])argv,b) if(task: argc > 0) priority(f) depend(depobj:y) |
| 171 |
// CHECK-NEXT: #pragma omp task untied mergeable depend(out : argv[:a][1],(arr)[0:],([argc][10])argv,b) if(task: argc > 0) priority(f) depend(depobj : y) |
| 172 |
a = 2; |
| 173 |
// CHECK-NEXT: a = 2; |
| 174 |
#pragma omp taskgroup task_reduction(min: arr1) |
| 175 |
#pragma omp task default(none), private(argc, b) firstprivate(argv, evt) if (argc > 0) final(a > 0) depend(inout : a, argv[:argc],arr[:a], ([10][argc])argv) priority(23) in_reduction(min: arr1), detach(evt) |
| 176 |
// CHECK-NEXT: #pragma omp taskgroup task_reduction(min: arr1) |
| 177 |
// CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv,evt) if(argc > 0) final(a > 0) depend(inout : a,argv[:argc],arr[:a],([10][argc])argv) priority(23) in_reduction(min: arr1) detach(evt) |
| 178 |
foo(); |
| 179 |
// CHECK-NEXT: foo(); |
| 180 |
#pragma omp taskgroup task_reduction(min: arr1) |
| 181 |
#pragma omp parallel reduction(+:arr1) |
| 182 |
#pragma omp task in_reduction(min: arr1) depend(iterator(i=0:argc, unsigned j=argc:0:a), out: argv[i][j]) |
| 183 |
// CHECK-NEXT: #pragma omp taskgroup task_reduction(min: arr1) |
| 184 |
// CHECK-NEXT: #pragma omp parallel reduction(+: arr1) |
| 185 |
// CHECK-NEXT: #pragma omp task in_reduction(min: arr1) depend(iterator(int i = 0:argc, unsigned int j = argc:0:a), out : argv[i][j]) |
| 186 |
foo(); |
| 187 |
// CHECK-NEXT: foo(); |
| 188 |
// CHECK-NEXT: #pragma omp task in_reduction(+: arr1) |
| 189 |
#pragma omp task in_reduction(+: arr1) |
| 190 |
foo(); |
| 191 |
// CHECK-NEXT: foo(); |
| 192 |
// CHECK-NEXT: #pragma omp task depend(out : arr,omp_all_memory) |
| 193 |
#pragma omp task depend(out: omp_all_memory, arr) |
| 194 |
foo(); |
| 195 |
// CHECK-NEXT: foo(); |
| 196 |
// CHECK-NEXT: #pragma omp task depend(inout : b,arr,a,x,omp_all_memory) |
| 197 |
#pragma omp task depend(inout: b, arr, omp_all_memory, a, x) |
| 198 |
foo(); |
| 199 |
// CHECK-NEXT: foo(); |
| 200 |
// CHECK-NEXT: #pragma omp task depend(inout : omp_all_memory) |
| 201 |
#pragma omp task depend(inout: omp_all_memory) |
| 202 |
foo(); |
| 203 |
// CHECK-NEXT: foo(); |
| 204 |
#ifdef OMP60 |
| 205 |
#pragma omp task threadset(omp_pool) |
| 206 |
#pragma omp task threadset(omp_team) |
| 207 |
foo(); |
| 208 |
#endif |
| 209 |
// CHECK60: #pragma omp task threadset(omp_pool) |
| 210 |
// CHECK60: #pragma omp task threadset(omp_team) |
| 211 |
// CHECK60-NEXT: foo(); |
| 212 |
return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x); |
| 213 |
} |
| 214 |
|
| 215 |
extern template int S<int>::TS; |
| 216 |
extern template long S<long>::TS; |
| 217 |
|
| 218 |
// DUMP-LABEL: FunctionDecl {{.*}} implicit_firstprivate |
| 219 |
void |
| 220 |
implicit_firstprivate() { |
| 221 |
|
| 222 |
#pragma omp parallel num_threads(1) |
| 223 |
{ |
| 224 |
int i = 0; |
| 225 |
// DUMP: OMPTaskDirective |
| 226 |
// DUMP-NEXT: OMPFirstprivateClause |
| 227 |
// DUMP-NOT: DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated |
| 228 |
// DUMP: DeclRefExpr {{.+}} 'i' 'int' refers_to_enclosing_variable_or_capture |
| 229 |
// DUMP: CapturedStmt |
| 230 |
// DUMP: BinaryOperator {{.+}} 'int' lvalue '=' |
| 231 |
// DUMP-NEXT: DeclRefExpr {{.+}} 'j' 'int' |
| 232 |
// DUMP: DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated |
| 233 |
#pragma omp task |
| 234 |
{ |
| 235 |
int j = sizeof(i); |
| 236 |
j = i; |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
// DUMP-LABEL: FunctionDecl {{.*}} no_implicit_firstprivate |
| 242 |
void |
| 243 |
no_implicit_firstprivate() { |
| 244 |
|
| 245 |
#pragma omp parallel num_threads(1) |
| 246 |
{ |
| 247 |
int i = 0; |
| 248 |
// DUMP: OMPTaskDirective |
| 249 |
// DUMP-NEXT: CapturedStmt |
| 250 |
// DUMP: DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated refers_to_enclosing_variable_or_capture |
| 251 |
#pragma omp task |
| 252 |
{ |
| 253 |
int j = sizeof(i); |
| 254 |
} |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
#endif |