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