1// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s 2 3void foo() { 4} 5 6bool foobool(int argc) { 7 return argc; 8} 9 10struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} 11extern S1 a; 12class S2 { 13 mutable int a; 14 15public: 16 S2() : a(0) {} 17 S2(S2 &s2) : a(s2.a) {} 18 static float S2s; 19 static const float S2sc; 20}; 21const float S2::S2sc = 0; 22const S2 b; 23const S2 ba[5]; 24class S3 { 25 int a; 26 S3 &operator=(const S3 &s3); 27 28public: 29 S3() : a(0) {} 30 S3(S3 &s3) : a(s3.a) {} 31}; 32const S3 c; 33const S3 ca[5]; 34extern const int f; 35class S4 { // expected-note 2 {{'S4' declared here}} 36 int a; 37 S4(); 38 S4(const S4 &s4); 39 40public: 41 S4(int v) : a(v) {} 42}; 43class S5 { // expected-note 4 {{'S5' declared here}} 44 int a; 45 S5(const S5 &s5) : a(s5.a) {} 46 47public: 48 S5() : a(0) {} 49 S5(int v) : a(v) {} 50}; 51class S6 { 52 int a; 53 S6() : a(0) {} 54 55public: 56 S6(const S6 &s6) : a(s6.a) {} 57 S6(int v) : a(v) {} 58}; 59 60S3 h; 61#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} 62 63template <class I, class C> 64int foomain(int argc, char **argv) { 65 I e(4); // expected-note {{'e' defined here}} 66 C g(5); // expected-note 2 {{'g' defined here}} 67 int i; 68 int &j = i; // expected-note {{'j' defined here}} 69#pragma omp parallel 70#pragma omp for firstprivate // expected-error {{expected '(' after 'firstprivate'}} 71 for (int k = 0; k < argc; ++k) 72 ++k; 73#pragma omp parallel 74#pragma omp for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 75 for (int k = 0; k < argc; ++k) 76 ++k; 77#pragma omp parallel 78#pragma omp for firstprivate() // expected-error {{expected expression}} 79 for (int k = 0; k < argc; ++k) 80 ++k; 81#pragma omp parallel 82#pragma omp for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 83 for (int k = 0; k < argc; ++k) 84 ++k; 85#pragma omp parallel 86#pragma omp for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 87 for (int k = 0; k < argc; ++k) 88 ++k; 89#pragma omp parallel 90#pragma omp for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 91 for (int k = 0; k < argc; ++k) 92 ++k; 93#pragma omp parallel 94#pragma omp for firstprivate(argc) 95 for (int k = 0; k < argc; ++k) 96 ++k; 97#pragma omp parallel 98#pragma omp for firstprivate(S1) // expected-error {{'S1' does not refer to a value}} 99 for (int k = 0; k < argc; ++k) 100 ++k; 101#pragma omp parallel 102#pragma omp for firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} 103 for (int k = 0; k < argc; ++k) 104 ++k; 105#pragma omp parallel 106#pragma omp for firstprivate(argv[1]) // expected-error {{expected variable name}} 107 for (int k = 0; k < argc; ++k) 108 ++k; 109#pragma omp parallel 110#pragma omp for firstprivate(e, g) // expected-error 2 {{firstprivate variable must have an accessible, unambiguous copy constructor}} 111 for (int k = 0; k < argc; ++k) 112 ++k; 113#pragma omp parallel 114#pragma omp for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} 115 for (int k = 0; k < argc; ++k) 116 ++k; 117#pragma omp parallel 118#pragma omp for linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp for'}} 119 for (int k = 0; k < argc; ++k) 120 ++k; 121#pragma omp parallel 122 { 123 int v = 0; 124 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for' directive into a parallel or another task region?}} 125#pragma omp for firstprivate(i) // expected-error {{private variable cannot be firstprivate}} 126 for (int k = 0; k < argc; ++k) { 127 i = k; 128 v += i; 129 } 130 } 131#pragma omp parallel shared(i) 132#pragma omp parallel private(i) 133#pragma omp for firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}} 134 for (int k = 0; k < argc; ++k) 135 ++k; 136#pragma omp parallel 137#pragma omp for firstprivate(i) 138 for (int k = 0; k < argc; ++k) 139 ++k; 140#pragma omp parallel 141#pragma omp for lastprivate(g) firstprivate(g) // expected-error {{firstprivate variable must have an accessible, unambiguous copy constructor}} 142 for (i = 0; i < argc; ++i) 143 foo(); 144#pragma omp parallel private(i) // expected-note {{defined as private}} 145#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}} 146 for (i = 0; i < argc; ++i) 147 foo(); 148#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}} 149#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}} 150 for (i = 0; i < argc; ++i) 151 foo(); 152 return 0; 153} 154 155int main(int argc, char **argv) { 156 const int d = 5; 157 const int da[5] = {0}; 158 S4 e(4); // expected-note {{'e' defined here}} 159 S5 g(5); // expected-note 2 {{'g' defined here}} 160 S3 m; 161 S6 n(2); 162 int i; 163 int &j = i; // expected-note {{'j' defined here}} 164#pragma omp parallel 165#pragma omp for firstprivate // expected-error {{expected '(' after 'firstprivate'}} 166 for (i = 0; i < argc; ++i) 167 foo(); 168#pragma omp parallel 169#pragma omp for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 170 for (i = 0; i < argc; ++i) 171 foo(); 172#pragma omp parallel 173#pragma omp for firstprivate() // expected-error {{expected expression}} 174 for (i = 0; i < argc; ++i) 175 foo(); 176#pragma omp parallel 177#pragma omp for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 178 for (i = 0; i < argc; ++i) 179 foo(); 180#pragma omp parallel 181#pragma omp for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 182 for (i = 0; i < argc; ++i) 183 foo(); 184#pragma omp parallel 185#pragma omp for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 186 for (i = 0; i < argc; ++i) 187 foo(); 188#pragma omp parallel 189#pragma omp for firstprivate(argc) 190 for (i = 0; i < argc; ++i) 191 foo(); 192#pragma omp parallel 193#pragma omp for firstprivate(S1) // expected-error {{'S1' does not refer to a value}} 194 for (i = 0; i < argc; ++i) 195 foo(); 196#pragma omp parallel 197#pragma omp for firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} 198 for (i = 0; i < argc; ++i) 199 foo(); 200#pragma omp parallel 201#pragma omp for firstprivate(argv[1]) // expected-error {{expected variable name}} 202 for (i = 0; i < argc; ++i) 203 foo(); 204#pragma omp parallel 205#pragma omp for firstprivate(2 * 2) // expected-error {{expected variable name}} 206 for (i = 0; i < argc; ++i) 207 foo(); 208#pragma omp parallel 209#pragma omp for firstprivate(ba) // OK 210 for (i = 0; i < argc; ++i) 211 foo(); 212#pragma omp parallel 213#pragma omp for firstprivate(ca) // OK 214 for (i = 0; i < argc; ++i) 215 foo(); 216#pragma omp parallel 217#pragma omp for firstprivate(da) // OK 218 for (i = 0; i < argc; ++i) 219 foo(); 220 int xa; 221#pragma omp parallel 222#pragma omp for firstprivate(xa) // OK 223 for (i = 0; i < argc; ++i) 224 foo(); 225#pragma omp parallel 226#pragma omp for firstprivate(S2::S2s) // OK 227 for (i = 0; i < argc; ++i) 228 foo(); 229#pragma omp parallel 230#pragma omp for firstprivate(S2::S2sc) // OK 231 for (i = 0; i < argc; ++i) 232 foo(); 233#pragma omp parallel 234#pragma omp for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp for'}} 235 for (i = 0; i < argc; ++i) 236 foo(); 237#pragma omp parallel 238#pragma omp for firstprivate(e, g) // expected-error 2 {{firstprivate variable must have an accessible, unambiguous copy constructor}} 239 for (i = 0; i < argc; ++i) 240 foo(); 241#pragma omp parallel 242#pragma omp for firstprivate(m) // OK 243 for (i = 0; i < argc; ++i) 244 foo(); 245#pragma omp parallel 246#pragma omp for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} 247 for (i = 0; i < argc; ++i) 248 foo(); 249#pragma omp parallel 250#pragma omp for private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}} 251 for (i = 0; i < argc; ++i) 252 foo(); 253#pragma omp parallel 254#pragma omp for firstprivate(i) // expected-note {{defined as firstprivate}} 255 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp for' directive may not be firstprivate, predetermined as private}} 256 foo(); 257#pragma omp parallel shared(xa) 258#pragma omp for firstprivate(xa) // OK: may be firstprivate 259 for (i = 0; i < argc; ++i) 260 foo(); 261#pragma omp parallel 262#pragma omp for firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}} 263 for (i = 0; i < argc; ++i) 264 foo(); 265#pragma omp parallel 266#pragma omp for lastprivate(g) firstprivate(g) // expected-error {{firstprivate variable must have an accessible, unambiguous copy constructor}} 267 for (i = 0; i < argc; ++i) 268 foo(); 269#pragma omp parallel 270#pragma omp for lastprivate(n) firstprivate(n) // OK 271 for (i = 0; i < argc; ++i) 272 foo(); 273#pragma omp parallel 274 { 275 int v = 0; 276 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for' directive into a parallel or another task region?}} 277#pragma omp for firstprivate(i) // expected-error {{private variable cannot be firstprivate}} 278 for (int k = 0; k < argc; ++k) { 279 i = k; 280 v += i; 281 } 282 } 283#pragma omp parallel private(i) // expected-note {{defined as private}} 284#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}} 285 for (i = 0; i < argc; ++i) 286 foo(); 287#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}} 288#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}} 289 for (i = 0; i < argc; ++i) 290 foo(); 291 292 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}} 293} 294