1 // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-version=45 -fopenmp -ferror-limit 200 -std=c++11 -o - %s -Wuninitialized 2 // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-version=50 -fopenmp -ferror-limit 200 -std=c++11 -o - %s -Wuninitialized 3 4 // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-version=45 -fopenmp-simd -ferror-limit 200 -std=c++11 -o - %s -Wuninitialized 5 // RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-version=50 -fopenmp-simd -ferror-limit 200 -std=c++11 -o - %s -Wuninitialized 6 7 void xxx(int argc) { 8 int x; // expected-note {{initialize the variable 'x' to silence this warning}} 9 #pragma omp task 10 argc = x; // expected-warning {{variable 'x' is uninitialized when used here}} 11 } 12 13 void foo() { 14 #pragma omp task detach(0) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{'omp_event_handle_t' type not found; include <omp.h>}} 15 ; 16 } 17 18 typedef unsigned long omp_event_handle_t; 19 20 #pragma omp task // expected-error {{unexpected OpenMP directive '#pragma omp task'}} 21 22 class S { 23 S(const S &s) { a = s.a + 12; } // expected-note 16 {{implicitly declared private here}} 24 int a; 25 26 public: 27 S() : a(0) {} 28 S(int a) : a(a) {} 29 operator int() { return a; } 30 S &operator++() { return *this; } 31 S operator+(const S &) { return *this; } 32 }; 33 34 class S1 { 35 int a; 36 37 public: 38 S1() : a(0) {} 39 S1 &operator++() { return *this; } 40 S1(const S1 &) = delete; // expected-note 2 {{'S1' has been explicitly marked deleted here}} 41 }; 42 43 template <class T> 44 int foo() { 45 T a; 46 T &b = a; 47 int r; 48 S1 s1; 49 // expected-error@+1 2 {{call to deleted constructor of 'S1'}} 50 #pragma omp task 51 ++s1; 52 #pragma omp task default(none) // expected-note 2 {{explicit data sharing attribute requested here}} 53 #pragma omp task default(shared) 54 ++a; // expected-error 2 {{variable 'a' must have explicitly specified data sharing attributes}} 55 #pragma omp task default(none) // expected-note 2 {{explicit data sharing attribute requested here}} 56 #pragma omp task 57 // expected-error@+1 {{calling a private constructor of class 'S'}} 58 ++a; // expected-error 2 {{variable 'a' must have explicitly specified data sharing attributes}} 59 #pragma omp task 60 #pragma omp task 61 // expected-error@+1 {{calling a private constructor of class 'S'}} 62 ++a; // expected-error {{calling a private constructor of class 'S'}} 63 #pragma omp task default(shared) 64 #pragma omp task 65 // expected-error@+1 {{calling a private constructor of class 'S'}} 66 ++a; 67 #pragma omp parallel shared(a) 68 #pragma omp task 69 #pragma omp task 70 ++a; 71 #pragma omp parallel shared(a) 72 #pragma omp task default(shared) 73 #pragma omp task 74 ++a; 75 #pragma omp task 76 #pragma omp parallel 77 ++a; // expected-error {{calling a private constructor of class 'S'}} 78 // expected-error@+2 {{calling a private constructor of class 'S'}} 79 #pragma omp task 80 ++b; 81 #pragma omp task 82 // expected-error@+1 2 {{calling a private constructor of class 'S'}} 83 #pragma omp parallel shared(a, b) 84 ++a, ++b; 85 // expected-note@+1 2 {{defined as reduction}} 86 #pragma omp parallel reduction(+ : r) 87 // expected-error@+1 2 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}} 88 #pragma omp task firstprivate(r) 89 ++r; 90 // expected-note@+1 2 {{defined as reduction}} 91 #pragma omp parallel reduction(+ : r) 92 #pragma omp task default(shared) 93 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}} 94 ++r; 95 // expected-note@+1 2 {{defined as reduction}} 96 #pragma omp parallel reduction(+ : r) 97 #pragma omp task 98 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}} 99 ++r; 100 #pragma omp parallel 101 // expected-note@+1 2 {{defined as reduction}} 102 #pragma omp for reduction(+ : r) 103 for (int i = 0; i < 10; ++i) 104 // expected-error@+1 2 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}} 105 #pragma omp task firstprivate(r) 106 ++r; 107 #pragma omp parallel 108 // expected-note@+1 2 {{defined as reduction}} 109 #pragma omp for reduction(+ : r) 110 for (int i = 0; i < 10; ++i) 111 #pragma omp task default(shared) 112 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}} 113 ++r; 114 #pragma omp parallel 115 // expected-note@+1 2 {{defined as reduction}} 116 #pragma omp for reduction(+ : r) 117 for (int i = 0; i < 10; ++i) 118 #pragma omp task 119 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}} 120 ++r; 121 // expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}} 122 #pragma omp task 123 // expected-error@+2 {{reduction variable must be shared}} 124 // expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} 125 #pragma omp for reduction(+ : r) 126 ++r; 127 // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}} 128 #pragma omp task untied untied 129 ++r; 130 // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}} 131 #pragma omp task mergeable mergeable 132 ++r; 133 volatile omp_event_handle_t evt; 134 const omp_event_handle_t cevt = 0; 135 omp_event_handle_t sevt; 136 omp_event_handle_t &revt = sevt; 137 #pragma omp task detach // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{expected '(' after 'detach'}} 138 #pragma omp task detach( // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 139 #pragma omp task detach() // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{expected expression}} 140 #pragma omp task detach(a) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{expected variable of the 'omp_event_handle_t' type, not 'int'}} omp50-error {{expected variable of the 'omp_event_handle_t' type, not 'S'}} 141 ; 142 #pragma omp task detach(evt) detach(evt) // omp45-error 2 {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{directive '#pragma omp task' cannot contain more than one 'detach' clause}} 143 #pragma omp task detach(cevt) detach(revt) // omp45-error 2 {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{directive '#pragma omp task' cannot contain more than one 'detach' clause}} omp50-error {{expected variable of the 'omp_event_handle_t' type, not 'const omp_event_handle_t' (aka 'const unsigned long')}} omp50-error {{expected variable of the 'omp_event_handle_t' type, not 'omp_event_handle_t &' (aka 'unsigned long &')}} 144 #pragma omp task detach(evt) mergeable // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{'mergeable' and 'detach' clause are mutually exclusive and may not appear on the same directive}} omp50-note {{'detach' clause is specified here}} 145 ; 146 #pragma omp task mergeable detach(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{'detach' and 'mergeable' clause are mutually exclusive and may not appear on the same directive}} omp50-note {{'mergeable' clause is specified here}} 147 #pragma omp task detach(-evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{expected variable of the 'omp_event_handle_t' type}} 148 ; 149 #pragma omp task detach(evt) shared(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} 150 #pragma omp task detach(evt) firstprivate(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} 151 ; 152 return a + b; 153 } 154 155 int main(int argc, char **argv) { 156 int a; 157 int &b = a; 158 S sa; 159 S &sb = sa; 160 int r; 161 #pragma omp task { // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}} 162 foo(); 163 #pragma omp task( // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}} 164 foo(); 165 #pragma omp task[ // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}} 166 foo(); 167 #pragma omp task] // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}} 168 foo(); 169 #pragma omp task) // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}} 170 foo(); 171 #pragma omp task } // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}} 172 foo(); 173 #pragma omp task 174 // expected-warning@+1 {{extra tokens at the end of '#pragma omp task' are ignored}} 175 #pragma omp task unknown() 176 foo(); 177 L1: 178 foo(); 179 #pragma omp task 180 ; 181 #pragma omp task 182 { 183 goto L1; // expected-error {{use of undeclared label 'L1'}} 184 argc++; 185 } 186 187 for (int i = 0; i < 10; ++i) { 188 switch (argc) { 189 case (0): 190 #pragma omp task 191 { 192 foo(); 193 break; // expected-error {{'break' statement not in loop or switch statement}} 194 continue; // expected-error {{'continue' statement not in loop statement}} 195 } 196 default: 197 break; 198 } 199 } 200 #pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}} 201 ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} 202 203 goto L2; // expected-error {{use of undeclared label 'L2'}} 204 #pragma omp task 205 L2: 206 foo(); 207 #pragma omp task 208 { 209 return 1; // expected-error {{cannot return from OpenMP region}} 210 } 211 212 [[]] // expected-error {{an attribute list cannot appear here}} 213 #pragma omp task 214 for (int n = 0; n < 100; ++n) { 215 } 216 217 #pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}} 218 #pragma omp task default(shared) 219 ++a; // expected-error {{variable 'a' must have explicitly specified data sharing attributes}} 220 #pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}} 221 #pragma omp task 222 ++a; // expected-error {{variable 'a' must have explicitly specified data sharing attributes}} 223 #pragma omp task default(shared) 224 #pragma omp task 225 ++a; 226 #pragma omp task 227 #pragma omp parallel 228 ++a; 229 #pragma omp task 230 ++b; 231 #pragma omp task 232 #pragma omp parallel shared(a, b) 233 ++a, ++b; 234 #pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}} 235 #pragma omp task default(shared) 236 ++sa; // expected-error {{variable 'sa' must have explicitly specified data sharing attributes}} 237 #pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}} 238 #pragma omp task 239 // expected-error@+1 {{calling a private constructor of class 'S'}} 240 ++sa; // expected-error {{variable 'sa' must have explicitly specified data sharing attributes}} 241 #pragma omp task 242 #pragma omp task 243 // expected-error@+1 {{calling a private constructor of class 'S'}} 244 ++sa; // expected-error {{calling a private constructor of class 'S'}} 245 #pragma omp task default(shared) 246 #pragma omp task 247 // expected-error@+1 {{calling a private constructor of class 'S'}} 248 ++sa; 249 #pragma omp parallel shared(sa) 250 #pragma omp task 251 #pragma omp task 252 ++sa; 253 #pragma omp parallel shared(sa) 254 #pragma omp task default(shared) 255 #pragma omp task 256 ++sa; 257 #pragma omp task 258 #pragma omp parallel 259 ++sa; // expected-error {{calling a private constructor of class 'S'}} 260 // expected-error@+2 {{calling a private constructor of class 'S'}} 261 #pragma omp task 262 ++sb; 263 // expected-error@+2 2 {{calling a private constructor of class 'S'}} 264 #pragma omp task 265 #pragma omp parallel shared(sa, sb) 266 ++sa, ++sb; 267 // expected-note@+1 2 {{defined as reduction}} 268 #pragma omp parallel reduction(+ : r) 269 // expected-error@+1 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}} 270 #pragma omp task firstprivate(r) 271 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}} 272 ++r; 273 // expected-note@+1 {{defined as reduction}} 274 #pragma omp parallel reduction(+ : r) 275 #pragma omp task default(shared) 276 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}} 277 ++r; 278 // expected-note@+1 {{defined as reduction}} 279 #pragma omp parallel reduction(+ : r) 280 #pragma omp task 281 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}} 282 ++r; 283 #pragma omp parallel 284 // expected-note@+1 2 {{defined as reduction}} 285 #pragma omp for reduction(+ : r) 286 for (int i = 0; i < 10; ++i) 287 // expected-error@+1 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}} 288 #pragma omp task firstprivate(r) 289 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}} 290 ++r; 291 #pragma omp parallel 292 // expected-note@+1 {{defined as reduction}} 293 #pragma omp for reduction(+ : r) 294 for (int i = 0; i < 10; ++i) 295 #pragma omp task default(shared) 296 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}} 297 ++r; 298 #pragma omp parallel 299 // expected-note@+1 {{defined as reduction}} 300 #pragma omp for reduction(+ : r) 301 for (int i = 0; i < 10; ++i) 302 #pragma omp task 303 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}} 304 ++r; 305 // expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}} 306 #pragma omp task 307 // expected-error@+2 {{reduction variable must be shared}} 308 // expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} 309 #pragma omp for reduction(+ : r) 310 ++r; 311 // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}} 312 #pragma omp task untied untied 313 ++r; 314 // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}} 315 #pragma omp task mergeable mergeable 316 ++r; 317 volatile omp_event_handle_t evt; 318 omp_event_handle_t sevt; 319 const omp_event_handle_t cevt = evt; 320 omp_event_handle_t &revt = sevt; 321 #pragma omp task detach // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{expected '(' after 'detach'}} 322 #pragma omp task detach( // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 323 #pragma omp task detach() // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{expected expression}} 324 #pragma omp task detach(a) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{expected variable of the 'omp_event_handle_t' type, not 'int'}} 325 #pragma omp task detach(evt) detach(evt) // omp45-error 2 {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{directive '#pragma omp task' cannot contain more than one 'detach' clause}} 326 #pragma omp task detach(cevt) detach(revt) // omp45-error 2 {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{directive '#pragma omp task' cannot contain more than one 'detach' clause}} omp50-error {{expected variable of the 'omp_event_handle_t' type, not 'const omp_event_handle_t' (aka 'const unsigned long')}} omp50-error {{expected variable of the 'omp_event_handle_t' type, not 'omp_event_handle_t &' (aka 'unsigned long &')}} 327 #pragma omp task detach(evt) mergeable // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{'mergeable' and 'detach' clause are mutually exclusive and may not appear on the same directive}} omp50-note {{'detach' clause is specified here}} 328 ; 329 #pragma omp task mergeable detach(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{'detach' and 'mergeable' clause are mutually exclusive and may not appear on the same directive}} omp50-note {{'mergeable' clause is specified here}} 330 #pragma omp task detach(-evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{expected variable of the 'omp_event_handle_t' type}} 331 ; 332 #pragma omp task detach(evt) shared(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} 333 #pragma omp task detach(evt) firstprivate(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} 334 ; 335 // expected-note@+2 {{in instantiation of function template specialization 'foo<int>' requested here}} 336 // expected-note@+1 {{in instantiation of function template specialization 'foo<S>' requested here}} 337 return foo<int>() + foo<S>(); 338 } 339 340