362 lines · cpp
1// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-version=45 -fopenmp -ferror-limit 200 -std=c++11 -o - %s -Wuninitialized2// RUN: %clang_cc1 -verify=expected,omp5 -fopenmp-version=50 -fopenmp -ferror-limit 200 -std=c++11 -o - %s -Wuninitialized3 4// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-version=45 -fopenmp-simd -ferror-limit 200 -std=c++11 -o - %s -Wuninitialized5// RUN: %clang_cc1 -verify=expected,omp5 -fopenmp-version=50 -fopenmp-simd -ferror-limit 200 -std=c++11 -o - %s -Wuninitialized6 7// RUN: %clang_cc1 -verify=expected,omp5 -DOMP51 -fopenmp -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized8// RUN: %clang_cc1 -verify=expected,omp5 -DOMP51 -fopenmp-simd -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized9 10void xxx(int argc) {11 int x; // expected-note {{initialize the variable 'x' to silence this warning}}12#pragma omp task13 argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}14}15 16void foo() {17#pragma omp task detach(0) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp5-error {{'omp_event_handle_t' type not found; include <omp.h>}}18 ;19}20 21typedef unsigned long omp_event_handle_t;22namespace {23static int y = 0;24}25static int x = 0;26 27#pragma omp task // expected-error {{unexpected OpenMP directive '#pragma omp task'}}28 29class S {30 S(const S &s) { a = s.a + 12; } // expected-note 16 {{implicitly declared private here}}31 int a;32 33public:34 S() : a(0) {}35 S(int a) : a(a) {}36 operator int() { return a; }37 S &operator++() { return *this; }38 S operator+(const S &) { return *this; }39};40 41class S1 {42 int a;43 44public:45 S1() : a(0) {}46 S1 &operator++() { return *this; }47 S1(const S1 &) = delete; // expected-note 2 {{'S1' has been explicitly marked deleted here}}48};49 50template <class T>51int foo() {52 T a;53 T &b = a;54 int r;55 S1 s1;56// expected-error@+1 2 {{call to deleted constructor of 'S1'}}57#pragma omp task58 ++s1;59#pragma omp task default(none) // expected-note 2 {{explicit data sharing attribute requested here}}60#pragma omp task default(shared)61 ++a; // expected-error 2 {{variable 'a' must have explicitly specified data sharing attributes}}62#ifdef OMP5163#pragma omp task default(firstprivate) // omp5-note 4 {{explicit data sharing attribute requested here}}64#pragma omp task65 {66 ++x; // omp5-error 2 {{variable 'x' must have explicitly specified data sharing attributes}}67 ++y; // omp5-error 2 {{variable 'y' must have explicitly specified data sharing attributes}}68 }69#endif70 71#pragma omp task default(none) // expected-note 2 {{explicit data sharing attribute requested here}}72#pragma omp task73 // expected-error@+1 {{calling a private constructor of class 'S'}}74 ++a; // expected-error 2 {{variable 'a' must have explicitly specified data sharing attributes}}75#pragma omp task76#pragma omp task77 // expected-error@+1 {{calling a private constructor of class 'S'}}78 ++a; // expected-error {{calling a private constructor of class 'S'}}79#pragma omp task default(shared)80#pragma omp task81 // expected-error@+1 {{calling a private constructor of class 'S'}}82 ++a;83#pragma omp parallel shared(a)84#pragma omp task85#pragma omp task86 ++a;87#pragma omp parallel shared(a)88#pragma omp task default(shared)89#pragma omp task90 ++a;91#pragma omp task92#pragma omp parallel93 ++a; // expected-error {{calling a private constructor of class 'S'}}94// expected-error@+2 {{calling a private constructor of class 'S'}}95#pragma omp task96 ++b;97#pragma omp task98// expected-error@+1 2 {{calling a private constructor of class 'S'}}99#pragma omp parallel shared(a, b)100 ++a, ++b;101// expected-note@+1 2 {{defined as reduction}}102#pragma omp parallel reduction(+ : r)103// expected-error@+1 2 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}}104#pragma omp task firstprivate(r)105 ++r;106// expected-note@+1 2 {{defined as reduction}}107#pragma omp parallel reduction(+ : r)108#pragma omp task default(shared)109 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}110 ++r;111// expected-note@+1 2 {{defined as reduction}}112#pragma omp parallel reduction(+ : r)113#pragma omp task114 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}115 ++r;116#pragma omp parallel117// expected-note@+1 2 {{defined as reduction}}118#pragma omp for reduction(+ : r)119 for (int i = 0; i < 10; ++i)120// expected-error@+1 2 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}}121#pragma omp task firstprivate(r)122 ++r;123#pragma omp parallel124// expected-note@+1 2 {{defined as reduction}}125#pragma omp for reduction(+ : r)126 for (int i = 0; i < 10; ++i)127#pragma omp task default(shared)128 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}129 ++r;130#pragma omp parallel131// expected-note@+1 2 {{defined as reduction}}132#pragma omp for reduction(+ : r)133 for (int i = 0; i < 10; ++i)134#pragma omp task135 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}136 ++r;137// expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}}138#pragma omp task139// expected-error@+2 {{reduction variable must be shared}}140// expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}141#pragma omp for reduction(+ : r)142 ++r;143// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}144#pragma omp task untied untied145 ++r;146// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}147#pragma omp task mergeable mergeable148 ++r;149 volatile omp_event_handle_t evt;150 const omp_event_handle_t cevt = 0;151 omp_event_handle_t sevt;152 omp_event_handle_t &revt = sevt;153#pragma omp task detach // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{expected '(' after 'detach'}}154#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 '('}}155#pragma omp task detach() // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{expected expression}}156#pragma omp task detach(a) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp5-error {{expected variable of the 'omp_event_handle_t' type, not 'int'}} omp5-error {{expected variable of the 'omp_event_handle_t' type, not 'S'}}157 ;158#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}}159#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}} omp5-error {{expected variable of the 'omp_event_handle_t' type, not 'const omp_event_handle_t' (aka 'const unsigned long')}} omp5-error {{expected variable of the 'omp_event_handle_t' type, not 'omp_event_handle_t &' (aka 'unsigned long &')}}160#pragma omp task detach(evt) mergeable // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp5-error {{'mergeable' and 'detach' clause are mutually exclusive and may not appear on the same directive}} omp5-note {{'detach' clause is specified here}}161 ;162#pragma omp task mergeable detach(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp5-error {{'detach' and 'mergeable' clause are mutually exclusive and may not appear on the same directive}} omp5-note {{'mergeable' clause is specified here}}163#pragma omp task detach(-evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp5-error {{expected variable of the 'omp_event_handle_t' type}}164 ;165#pragma omp task detach(evt) shared(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}}166#pragma omp task detach(evt) firstprivate(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}}167 ;168 return a + b;169}170 171int main(int argc, char **argv) {172 int a;173 int &b = a;174 S sa;175 S &sb = sa;176 int r; // expected-note {{declared here}}177#pragma omp task { // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}178 foo();179#pragma omp task( // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}180 foo();181#pragma omp task[ // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}182 foo();183#pragma omp task] // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}184 foo();185#pragma omp task) // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}186 foo();187#pragma omp task } // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}188 foo();189#pragma omp task190// expected-warning@+1 {{extra tokens at the end of '#pragma omp task' are ignored}}191#pragma omp task unknown()192 foo();193L1:194 foo();195#pragma omp task196 ;197#pragma omp task198 {199 goto L1; // expected-error {{use of undeclared label 'L1'}}200 argc++;201 }202 203 for (int i = 0; i < 10; ++i) {204 switch (argc) {205 case (0):206#pragma omp task207 {208 foo();209 break; // expected-error {{'break' statement not in loop or switch statement}}210 continue; // expected-error {{'continue' statement not in loop statement}}211 }212 default:213 break;214 }215 }216#pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}}217 ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}218 219 goto L2; // expected-error {{use of undeclared label 'L2'}}220#pragma omp task221L2:222 foo();223#pragma omp task224 {225 return 1; // expected-error {{cannot return from OpenMP region}}226 }227 228 [[]] // expected-error {{an attribute list cannot appear here}}229#pragma omp task230 for (int n = 0; n < 100; ++n) {231 }232 233#pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}}234#pragma omp task default(shared)235 ++a; // expected-error {{variable 'a' must have explicitly specified data sharing attributes}}236#pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}}237#pragma omp task238 ++a; // expected-error {{variable 'a' must have explicitly specified data sharing attributes}}239#pragma omp task default(shared)240#pragma omp task241 ++a;242#pragma omp task243#pragma omp parallel244 ++a;245#pragma omp task246 ++b;247#pragma omp task248#pragma omp parallel shared(a, b)249 ++a, ++b;250#pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}}251#pragma omp task default(shared)252 ++sa; // expected-error {{variable 'sa' must have explicitly specified data sharing attributes}}253#pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}}254#pragma omp task255 // expected-error@+1 {{calling a private constructor of class 'S'}}256 ++sa; // expected-error {{variable 'sa' must have explicitly specified data sharing attributes}}257#pragma omp task258#pragma omp task259 // expected-error@+1 {{calling a private constructor of class 'S'}}260 ++sa; // expected-error {{calling a private constructor of class 'S'}}261#pragma omp task default(shared)262#pragma omp task263 // expected-error@+1 {{calling a private constructor of class 'S'}}264 ++sa;265#pragma omp parallel shared(sa)266#pragma omp task267#pragma omp task268 ++sa;269#pragma omp parallel shared(sa)270#pragma omp task default(shared)271#pragma omp task272 ++sa;273#pragma omp task274#pragma omp parallel275 ++sa; // expected-error {{calling a private constructor of class 'S'}}276// expected-error@+2 {{calling a private constructor of class 'S'}}277#pragma omp task278 ++sb;279// expected-error@+2 2 {{calling a private constructor of class 'S'}}280#pragma omp task281#pragma omp parallel shared(sa, sb)282 ++sa, ++sb;283// expected-note@+1 2 {{defined as reduction}}284#pragma omp parallel reduction(+ : r)285// expected-error@+1 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}}286#pragma omp task firstprivate(r)287 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}288 ++r;289// expected-note@+1 {{defined as reduction}}290#pragma omp parallel reduction(+ : r)291#pragma omp task default(shared)292 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}293 ++r;294// expected-note@+1 {{defined as reduction}}295#pragma omp parallel reduction(+ : r)296#pragma omp task297 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}298 ++r;299#pragma omp parallel300// expected-note@+1 2 {{defined as reduction}}301#pragma omp for reduction(+ : r)302 for (int i = 0; i < 10; ++i)303// expected-error@+1 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}}304#pragma omp task firstprivate(r)305 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}306 ++r;307#pragma omp parallel308// expected-note@+1 {{defined as reduction}}309#pragma omp for reduction(+ : r)310 for (int i = 0; i < 10; ++i)311#pragma omp task default(shared)312 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}313 ++r;314#pragma omp parallel315// expected-note@+1 {{defined as reduction}}316#pragma omp for reduction(+ : r)317 for (int i = 0; i < 10; ++i)318#pragma omp task319 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}320 ++r;321// expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}}322#pragma omp task323// expected-error@+2 {{reduction variable must be shared}}324// expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}325#pragma omp for reduction(+ : r)326 ++r;327// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}328#pragma omp task untied untied329 ++r;330// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}331#pragma omp task mergeable mergeable332 ++r;333// expected-error@+4 {{variable length arrays are not supported in OpenMP tasking regions with 'untied' clause}}334// expected-note@+3 {{read of non-const variable 'r' is not allowed in a constant expression}}335#pragma omp task untied336 {337 int array[r];338 }339 volatile omp_event_handle_t evt;340 omp_event_handle_t sevt;341 const omp_event_handle_t cevt = evt;342 omp_event_handle_t &revt = sevt;343#pragma omp task detach // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{expected '(' after 'detach'}}344#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 '('}}345#pragma omp task detach() // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} expected-error {{expected expression}}346#pragma omp task detach(a) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp5-error {{expected variable of the 'omp_event_handle_t' type, not 'int'}}347#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}}348#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}} omp5-error {{expected variable of the 'omp_event_handle_t' type, not 'const omp_event_handle_t' (aka 'const unsigned long')}} omp5-error {{expected variable of the 'omp_event_handle_t' type, not 'omp_event_handle_t &' (aka 'unsigned long &')}}349#pragma omp task detach(evt) mergeable // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp5-error {{'mergeable' and 'detach' clause are mutually exclusive and may not appear on the same directive}} omp5-note {{'detach' clause is specified here}}350 ;351#pragma omp task mergeable detach(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp5-error {{'detach' and 'mergeable' clause are mutually exclusive and may not appear on the same directive}} omp5-note {{'mergeable' clause is specified here}}352#pragma omp task detach(-evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp5-error {{expected variable of the 'omp_event_handle_t' type}}353 ;354#pragma omp task detach(evt) shared(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}}355#pragma omp task detach(evt) firstprivate(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}}356 ;357 // expected-note@+2 {{in instantiation of function template specialization 'foo<int>' requested here}}358 // expected-note@+1 {{in instantiation of function template specialization 'foo<S>' requested here}}359 return foo<int>() + foo<S>();360}361 362