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