Alexey Bataev | db39021 | 2015-05-20 04:24:19 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify %s |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2 | |
| 3 | static int sii; |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 4 | #pragma omp threadprivate(sii) |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 5 | static int globalii; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6 | |
| 7 | int test_iteration_spaces() { |
| 8 | const int N = 100; |
| 9 | float a[N], b[N], c[N]; |
| 10 | int ii, jj, kk; |
| 11 | float fii; |
| 12 | double dii; |
| 13 | #pragma omp simd |
| 14 | for (int i = 0; i < 10; i+=1) { |
| 15 | c[i] = a[i] + b[i]; |
| 16 | } |
| 17 | #pragma omp simd |
| 18 | for (char i = 0; i < 10; i++) { |
| 19 | c[i] = a[i] + b[i]; |
| 20 | } |
| 21 | #pragma omp simd |
| 22 | for (char i = 0; i < 10; i+='\1') { |
| 23 | c[i] = a[i] + b[i]; |
| 24 | } |
| 25 | #pragma omp simd |
| 26 | for (long long i = 0; i < 10; i++) { |
| 27 | c[i] = a[i] + b[i]; |
| 28 | } |
| 29 | // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}} |
| 30 | #pragma omp simd |
| 31 | for (long long i = 0; i < 10; i+=1.5) { |
| 32 | c[i] = a[i] + b[i]; |
| 33 | } |
| 34 | #pragma omp simd |
| 35 | for (long long i = 0; i < 'z'; i+=1u) { |
| 36 | c[i] = a[i] + b[i]; |
| 37 | } |
| 38 | // expected-error@+2 {{variable must be of integer or random access iterator type}} |
| 39 | #pragma omp simd |
| 40 | for (float fi = 0; fi < 10.0; fi++) { |
| 41 | c[(int)fi] = a[(int)fi] + b[(int)fi]; |
| 42 | } |
| 43 | // expected-error@+2 {{variable must be of integer or random access iterator type}} |
| 44 | #pragma omp simd |
| 45 | for (double fi = 0; fi < 10.0; fi++) { |
| 46 | c[(int)fi] = a[(int)fi] + b[(int)fi]; |
| 47 | } |
| 48 | // expected-error@+2 {{variable must be of integer or random access iterator type}} |
| 49 | #pragma omp simd |
| 50 | for (int &ref = ii; ref < 10; ref++) { |
| 51 | } |
| 52 | // expected-error@+2 {{initialization clause of OpenMP for loop must be of the form 'var = init' or 'T var = init'}} |
| 53 | #pragma omp simd |
| 54 | for (int i; i < 10; i++) |
| 55 | c[i] = a[i]; |
| 56 | |
| 57 | // expected-error@+2 {{initialization clause of OpenMP for loop must be of the form 'var = init' or 'T var = init'}} |
| 58 | #pragma omp simd |
| 59 | for (int i = 0, j = 0; i < 10; ++i) |
| 60 | c[i] = a[i]; |
| 61 | |
| 62 | // expected-error@+2 {{initialization clause of OpenMP for loop must be of the form 'var = init' or 'T var = init'}} |
| 63 | #pragma omp simd |
| 64 | for (;ii < 10; ++ii) |
| 65 | c[ii] = a[ii]; |
| 66 | |
| 67 | // expected-warning@+3 {{expression result unused}} |
| 68 | // expected-error@+2 {{initialization clause of OpenMP for loop must be of the form 'var = init' or 'T var = init'}} |
| 69 | #pragma omp simd |
| 70 | for (ii + 1;ii < 10; ++ii) |
| 71 | c[ii] = a[ii]; |
| 72 | |
| 73 | // expected-error@+2 {{initialization clause of OpenMP for loop must be of the form 'var = init' or 'T var = init'}} |
| 74 | #pragma omp simd |
| 75 | for (c[ii] = 0;ii < 10; ++ii) |
| 76 | c[ii] = a[ii]; |
| 77 | |
| 78 | // Ok to skip parenthesises. |
| 79 | #pragma omp simd |
| 80 | for (((ii)) = 0;ii < 10; ++ii) |
| 81 | c[ii] = a[ii]; |
| 82 | |
| 83 | // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} |
| 84 | #pragma omp simd |
| 85 | for (int i = 0; i; i++) |
| 86 | c[i] = a[i]; |
| 87 | |
| 88 | // expected-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} |
| 89 | // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}} |
| 90 | #pragma omp simd |
| 91 | for (int i = 0; jj < kk; ii++) |
| 92 | c[i] = a[i]; |
| 93 | |
| 94 | // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} |
| 95 | #pragma omp simd |
| 96 | for (int i = 0; !!i; i++) |
| 97 | c[i] = a[i]; |
| 98 | |
| 99 | // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} |
| 100 | #pragma omp simd |
| 101 | for (int i = 0; i != 1; i++) |
| 102 | c[i] = a[i]; |
| 103 | |
| 104 | // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} |
| 105 | #pragma omp simd |
| 106 | for (int i = 0; ; i++) |
| 107 | c[i] = a[i]; |
| 108 | |
| 109 | // Ok. |
| 110 | #pragma omp simd |
| 111 | for (int i = 11; i > 10; i--) |
| 112 | c[i] = a[i]; |
| 113 | |
| 114 | // Ok. |
| 115 | #pragma omp simd |
| 116 | for (int i = 0; i < 10; ++i) |
| 117 | c[i] = a[i]; |
| 118 | |
| 119 | // Ok. |
| 120 | #pragma omp simd |
| 121 | for (ii = 0; ii < 10; ++ii) |
| 122 | c[ii] = a[ii]; |
| 123 | |
| 124 | // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} |
| 125 | #pragma omp simd |
| 126 | for (ii = 0; ii < 10; ++jj) |
| 127 | c[ii] = a[jj]; |
| 128 | |
| 129 | // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} |
| 130 | #pragma omp simd |
| 131 | for (ii = 0; ii < 10; ++ ++ ii) |
| 132 | c[ii] = a[ii]; |
| 133 | |
| 134 | // Ok but undefined behavior (in general, cannot check that incr |
| 135 | // is really loop-invariant). |
| 136 | #pragma omp simd |
| 137 | for (ii = 0; ii < 10; ii = ii + ii) |
| 138 | c[ii] = a[ii]; |
| 139 | |
| 140 | // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}} |
| 141 | #pragma omp simd |
| 142 | for (ii = 0; ii < 10; ii = ii + 1.0f) |
| 143 | c[ii] = a[ii]; |
| 144 | |
| 145 | // Ok - step was converted to integer type. |
| 146 | #pragma omp simd |
| 147 | for (ii = 0; ii < 10; ii = ii + (int)1.1f) |
| 148 | c[ii] = a[ii]; |
| 149 | |
| 150 | // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} |
| 151 | #pragma omp simd |
| 152 | for (ii = 0; ii < 10; jj = ii + 2) |
| 153 | c[ii] = a[ii]; |
| 154 | |
| 155 | // expected-warning@+3 {{relational comparison result unused}} |
| 156 | // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} |
| 157 | #pragma omp simd |
| 158 | for (ii = 0; ii < 10; jj > kk + 2) |
| 159 | c[ii] = a[ii]; |
| 160 | |
| 161 | // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} |
| 162 | #pragma omp simd |
| 163 | for (ii = 0; ii < 10;) |
| 164 | c[ii] = a[ii]; |
| 165 | |
| 166 | // expected-warning@+3 {{expression result unused}} |
| 167 | // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} |
| 168 | #pragma omp simd |
| 169 | for (ii = 0; ii < 10; !ii) |
| 170 | c[ii] = a[ii]; |
| 171 | |
| 172 | // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} |
| 173 | #pragma omp simd |
| 174 | for (ii = 0; ii < 10; ii ? ++ii : ++jj) |
| 175 | c[ii] = a[ii]; |
| 176 | |
| 177 | // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} |
| 178 | #pragma omp simd |
| 179 | for (ii = 0; ii < 10; ii = ii < 10) |
| 180 | c[ii] = a[ii]; |
| 181 | |
| 182 | // expected-note@+3 {{loop step is expected to be positive due to this condition}} |
| 183 | // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} |
| 184 | #pragma omp simd |
| 185 | for (ii = 0; ii < 10; ii = ii + 0) |
| 186 | c[ii] = a[ii]; |
| 187 | |
| 188 | // expected-note@+3 {{loop step is expected to be positive due to this condition}} |
| 189 | // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} |
| 190 | #pragma omp simd |
| 191 | for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45)) |
| 192 | c[ii] = a[ii]; |
| 193 | |
| 194 | // expected-note@+3 {{loop step is expected to be positive due to this condition}} |
| 195 | // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} |
| 196 | #pragma omp simd |
| 197 | for (ii = 0; (ii) < 10; ii-=25) |
| 198 | c[ii] = a[ii]; |
| 199 | |
| 200 | // expected-note@+3 {{loop step is expected to be positive due to this condition}} |
| 201 | // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} |
| 202 | #pragma omp simd |
| 203 | for (ii = 0; (ii < 10); ii-=0) |
| 204 | c[ii] = a[ii]; |
| 205 | |
| 206 | // expected-note@+3 {{loop step is expected to be negative due to this condition}} |
| 207 | // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}} |
| 208 | #pragma omp simd |
| 209 | for (ii = 0; ii > 10; (ii+=0)) |
| 210 | c[ii] = a[ii]; |
| 211 | |
| 212 | // expected-note@+3 {{loop step is expected to be positive due to this condition}} |
| 213 | // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} |
| 214 | #pragma omp simd |
| 215 | for (ii = 0; ii < 10; (ii) = (1-1)+(ii)) |
| 216 | c[ii] = a[ii]; |
| 217 | |
| 218 | // expected-note@+3 {{loop step is expected to be negative due to this condition}} |
| 219 | // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}} |
| 220 | #pragma omp simd |
| 221 | for ((ii = 0); ii > 10; (ii-=0)) |
| 222 | c[ii] = a[ii]; |
| 223 | |
| 224 | // expected-note@+3 {{loop step is expected to be positive due to this condition}} |
| 225 | // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} |
| 226 | #pragma omp simd |
| 227 | for (ii = 0; (ii < 10); (ii-=0)) |
| 228 | c[ii] = a[ii]; |
| 229 | |
| 230 | // expected-note@+2 {{defined as private}} |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 231 | // expected-error@+2 {{loop iteration variable in the associated loop of 'omp simd' directive may not be private, predetermined as linear}} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 232 | #pragma omp simd private(ii) |
| 233 | for (ii = 0; ii < 10; ii++) |
| 234 | c[ii] = a[ii]; |
| 235 | |
| 236 | // expected-error@+3 {{unexpected OpenMP clause 'shared' in directive '#pragma omp simd'}} |
| 237 | // expected-note@+2 {{defined as shared}} |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 238 | // expected-error@+2 {{loop iteration variable in the associated loop of 'omp simd' directive may not be shared, predetermined as linear}} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 239 | #pragma omp simd shared(ii) |
| 240 | for (ii = 0; ii < 10; ii++) |
| 241 | c[ii] = a[ii]; |
| 242 | |
| 243 | #pragma omp simd linear(ii) |
| 244 | for (ii = 0; ii < 10; ii++) |
| 245 | c[ii] = a[ii]; |
| 246 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 247 | #pragma omp simd lastprivate(ii) linear(jj) collapse(2) // expected-note {{defined as linear}} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 248 | for (ii = 0; ii < 10; ii++) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 249 | for (jj = 0; jj < 10; jj++) // expected-error {{loop iteration variable in the associated loop of 'omp simd' directive may not be linear, predetermined as lastprivate}} |
| 250 | c[ii] = a[jj]; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 251 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 252 | |
| 253 | #pragma omp parallel |
| 254 | { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 255 | #pragma omp simd |
| 256 | for (sii = 0; sii < 10; sii+=1) |
| 257 | c[sii] = a[sii]; |
| 258 | } |
| 259 | |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 260 | #pragma omp parallel |
| 261 | { |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 262 | #pragma omp simd |
| 263 | for (globalii = 0; globalii < 10; globalii+=1) |
| 264 | c[globalii] = a[globalii]; |
| 265 | } |
| 266 | |
| 267 | #pragma omp parallel |
| 268 | { |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 269 | #pragma omp simd collapse(2) |
| 270 | for (ii = 0; ii < 10; ii += 1) |
| 271 | for (globalii = 0; globalii < 10; globalii += 1) |
| 272 | c[globalii] += a[globalii] + ii; |
| 273 | } |
| 274 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 275 | // expected-error@+2 {{statement after '#pragma omp simd' must be a for loop}} |
| 276 | #pragma omp simd |
| 277 | for (auto &item : a) { |
| 278 | item = item + 1; |
| 279 | } |
| 280 | |
| 281 | // expected-note@+3 {{loop step is expected to be positive due to this condition}} |
| 282 | // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}} |
| 283 | #pragma omp simd |
| 284 | for (unsigned i = 9; i < 10; i--) { |
| 285 | c[i] = a[i] + b[i]; |
| 286 | } |
| 287 | |
| 288 | int (*lb)[4] = nullptr; |
| 289 | #pragma omp simd |
| 290 | for (int (*p)[4] = lb; p < lb + 8; ++p) { |
| 291 | } |
| 292 | |
| 293 | // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
| 294 | #pragma omp simd |
| 295 | for (int a{0}; a<10; ++a) { |
| 296 | } |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | // Iterators allowed in openmp for-loops. |
| 302 | namespace std { |
| 303 | struct random_access_iterator_tag { }; |
| 304 | template <class Iter> struct iterator_traits { |
| 305 | typedef typename Iter::difference_type difference_type; |
| 306 | typedef typename Iter::iterator_category iterator_category; |
| 307 | }; |
| 308 | template <class Iter> |
| 309 | typename iterator_traits<Iter>::difference_type |
| 310 | distance(Iter first, Iter last) { return first - last; } |
| 311 | } |
| 312 | class Iter0 { |
| 313 | public: |
| 314 | Iter0() { } |
| 315 | Iter0(const Iter0 &) { } |
| 316 | Iter0 operator ++() { return *this; } |
| 317 | Iter0 operator --() { return *this; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 318 | Iter0 operator + (int delta) { return *this; } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 319 | bool operator <(Iter0 a) { return true; } |
| 320 | }; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 321 | // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 322 | int operator -(Iter0 a, Iter0 b) { return 0; } |
| 323 | class Iter1 { |
| 324 | public: |
| 325 | Iter1(float f=0.0f, double d=0.0) { } |
| 326 | Iter1(const Iter1 &) { } |
| 327 | Iter1 operator ++() { return *this; } |
| 328 | Iter1 operator --() { return *this; } |
| 329 | bool operator <(Iter1 a) { return true; } |
| 330 | bool operator >=(Iter1 a) { return false; } |
| 331 | }; |
| 332 | class GoodIter { |
| 333 | public: |
| 334 | GoodIter() { } |
| 335 | GoodIter(const GoodIter &) { } |
| 336 | GoodIter(int fst, int snd) { } |
| 337 | GoodIter &operator =(const GoodIter &that) { return *this; } |
| 338 | GoodIter &operator =(const Iter0 &that) { return *this; } |
| 339 | GoodIter &operator +=(int x) { return *this; } |
| 340 | explicit GoodIter(void *) { } |
| 341 | GoodIter operator ++() { return *this; } |
| 342 | GoodIter operator --() { return *this; } |
| 343 | bool operator !() { return true; } |
| 344 | bool operator <(GoodIter a) { return true; } |
| 345 | bool operator <=(GoodIter a) { return true; } |
| 346 | bool operator >=(GoodIter a) { return false; } |
| 347 | typedef int difference_type; |
| 348 | typedef std::random_access_iterator_tag iterator_category; |
| 349 | }; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 350 | // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 351 | int operator -(GoodIter a, GoodIter b) { return 0; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 352 | // expected-note@+1 2 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 353 | GoodIter operator -(GoodIter a) { return a; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 354 | // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 355 | GoodIter operator -(GoodIter a, int v) { return GoodIter(); } |
| 356 | GoodIter operator +(GoodIter a, int v) { return GoodIter(); } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 357 | // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 358 | GoodIter operator -(int v, GoodIter a) { return GoodIter(); } |
| 359 | GoodIter operator +(int v, GoodIter a) { return GoodIter(); } |
| 360 | |
| 361 | int test_with_random_access_iterator() { |
| 362 | GoodIter begin, end; |
| 363 | Iter0 begin0, end0; |
| 364 | #pragma omp simd |
| 365 | for (GoodIter I = begin; I < end; ++I) |
| 366 | ++I; |
| 367 | // expected-error@+2 {{variable must be of integer or random access iterator type}} |
| 368 | #pragma omp simd |
| 369 | for (GoodIter &I = begin; I < end; ++I) |
| 370 | ++I; |
| 371 | #pragma omp simd |
| 372 | for (GoodIter I = begin; I >= end; --I) |
| 373 | ++I; |
| 374 | // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
| 375 | #pragma omp simd |
| 376 | for (GoodIter I(begin); I < end; ++I) |
| 377 | ++I; |
| 378 | // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
| 379 | #pragma omp simd |
| 380 | for (GoodIter I(nullptr); I < end; ++I) |
| 381 | ++I; |
| 382 | // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
| 383 | #pragma omp simd |
| 384 | for (GoodIter I(0); I < end; ++I) |
| 385 | ++I; |
| 386 | // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
| 387 | #pragma omp simd |
| 388 | for (GoodIter I(1,2); I < end; ++I) |
| 389 | ++I; |
| 390 | #pragma omp simd |
| 391 | for (begin = GoodIter(0); begin < end; ++begin) |
| 392 | ++begin; |
| 393 | #pragma omp simd |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 394 | for (begin = GoodIter(1,2); begin < end; ++begin) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 395 | ++begin; |
| 396 | // expected-error@+2 {{initialization clause of OpenMP for loop must be of the form 'var = init' or 'T var = init'}} |
| 397 | #pragma omp simd |
| 398 | for (++begin; begin < end; ++begin) |
| 399 | ++begin; |
| 400 | #pragma omp simd |
| 401 | for (begin = end; begin < end; ++begin) |
| 402 | ++begin; |
| 403 | // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} |
| 404 | #pragma omp simd |
| 405 | for (GoodIter I = begin; I - I; ++I) |
| 406 | ++I; |
| 407 | // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} |
| 408 | #pragma omp simd |
| 409 | for (GoodIter I = begin; begin < end; ++I) |
| 410 | ++I; |
| 411 | // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} |
| 412 | #pragma omp simd |
| 413 | for (GoodIter I = begin; !I; ++I) |
| 414 | ++I; |
| 415 | // expected-note@+3 {{loop step is expected to be negative due to this condition}} |
| 416 | // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} |
| 417 | #pragma omp simd |
| 418 | for (GoodIter I = begin; I >= end; I = I + 1) |
| 419 | ++I; |
| 420 | #pragma omp simd |
| 421 | for (GoodIter I = begin; I >= end; I = I - 1) |
| 422 | ++I; |
| 423 | // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}} |
| 424 | #pragma omp simd |
| 425 | for (GoodIter I = begin; I >= end; I = -I) |
| 426 | ++I; |
| 427 | // expected-note@+3 {{loop step is expected to be negative due to this condition}} |
| 428 | // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} |
| 429 | #pragma omp simd |
| 430 | for (GoodIter I = begin; I >= end; I = 2 + I) |
| 431 | ++I; |
| 432 | // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}} |
| 433 | #pragma omp simd |
| 434 | for (GoodIter I = begin; I >= end; I = 2 - I) |
| 435 | ++I; |
| 436 | #pragma omp simd |
| 437 | for (Iter0 I = begin0; I < end0; ++I) |
| 438 | ++I; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 439 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 440 | // Initializer is constructor without params. |
| 441 | // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
| 442 | #pragma omp simd |
| 443 | for (Iter0 I; I < end0; ++I) |
| 444 | ++I; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 445 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 446 | Iter1 begin1, end1; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 447 | // expected-error@+3 {{invalid operands to binary expression ('Iter1' and 'Iter1')}} |
| 448 | // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 449 | #pragma omp simd |
| 450 | for (Iter1 I = begin1; I < end1; ++I) |
| 451 | ++I; |
| 452 | // expected-note@+3 {{loop step is expected to be negative due to this condition}} |
| 453 | // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} |
| 454 | #pragma omp simd |
| 455 | for (Iter1 I = begin1; I >= end1; ++I) |
| 456 | ++I; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 457 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 458 | // Initializer is constructor with all default params. |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame^] | 459 | // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'float')}} |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 460 | // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 461 | // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
| 462 | #pragma omp simd |
| 463 | for (Iter1 I; I < end1; ++I) { |
| 464 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 465 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | template <typename IT, int ST> class TC { |
| 470 | public: |
| 471 | int dotest_lt(IT begin, IT end) { |
| 472 | // expected-note@+3 {{loop step is expected to be positive due to this condition}} |
| 473 | // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}} |
| 474 | #pragma omp simd |
| 475 | for (IT I = begin; I < end; I = I + ST) { |
| 476 | ++I; |
| 477 | } |
| 478 | // expected-note@+3 {{loop step is expected to be positive due to this condition}} |
| 479 | // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}} |
| 480 | #pragma omp simd |
| 481 | for (IT I = begin; I <= end; I += ST) { |
| 482 | ++I; |
| 483 | } |
| 484 | #pragma omp simd |
| 485 | for (IT I = begin; I < end; ++I) { |
| 486 | ++I; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | static IT step() { |
| 491 | return IT(ST); |
| 492 | } |
| 493 | }; |
| 494 | template <typename IT, int ST=0> int dotest_gt(IT begin, IT end) { |
| 495 | // expected-note@+3 2 {{loop step is expected to be negative due to this condition}} |
| 496 | // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} |
| 497 | #pragma omp simd |
| 498 | for (IT I = begin; I >= end; I = I + ST) { |
| 499 | ++I; |
| 500 | } |
| 501 | // expected-note@+3 2 {{loop step is expected to be negative due to this condition}} |
| 502 | // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} |
| 503 | #pragma omp simd |
| 504 | for (IT I = begin; I >= end; I += ST) { |
| 505 | ++I; |
| 506 | } |
| 507 | |
| 508 | // expected-note@+3 {{loop step is expected to be negative due to this condition}} |
| 509 | // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} |
| 510 | #pragma omp simd |
| 511 | for (IT I = begin; I >= end; ++I) { |
| 512 | ++I; |
| 513 | } |
| 514 | |
| 515 | #pragma omp simd |
| 516 | for (IT I = begin; I < end; I+=TC<int,ST>::step()) { |
| 517 | ++I; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | void test_with_template() { |
| 522 | GoodIter begin, end; |
| 523 | TC<GoodIter, 100> t1; |
| 524 | TC<GoodIter, -100> t2; |
| 525 | t1.dotest_lt(begin, end); |
| 526 | t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}} |
| 527 | dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}} |
| 528 | dotest_gt<unsigned, -10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, -10>' requested here}} |
| 529 | } |
| 530 | |
| 531 | void test_loop_break() { |
| 532 | const int N = 100; |
| 533 | float a[N], b[N], c[N]; |
| 534 | #pragma omp simd |
| 535 | for (int i = 0; i < 10; i++) { |
| 536 | c[i] = a[i] + b[i]; |
| 537 | for (int j = 0; j < 10; ++j) { |
| 538 | if (a[i] > b[j]) |
| 539 | break; // OK in nested loop |
| 540 | } |
| 541 | switch(i) { |
| 542 | case 1: |
| 543 | b[i]++; |
| 544 | break; |
| 545 | default: |
| 546 | break; |
| 547 | } |
| 548 | if (c[i] > 10) |
| 549 | break; // expected-error {{'break' statement cannot be used in OpenMP for loop}} |
| 550 | |
| 551 | if (c[i] > 11) |
| 552 | break; // expected-error {{'break' statement cannot be used in OpenMP for loop}} |
| 553 | } |
| 554 | |
| 555 | #pragma omp simd |
| 556 | for (int i = 0; i < 10; i++) { |
| 557 | for (int j = 0; j < 10; j++) { |
| 558 | c[i] = a[i] + b[i]; |
| 559 | if (c[i] > 10) { |
| 560 | if (c[i] < 20) { |
| 561 | break; // OK |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | void test_loop_eh() { |
| 569 | const int N = 100; |
| 570 | float a[N], b[N], c[N]; |
| 571 | #pragma omp simd |
| 572 | for (int i = 0; i < 10; i++) { |
| 573 | c[i] = a[i] + b[i]; |
| 574 | try { // expected-error {{'try' statement cannot be used in OpenMP simd region}} |
| 575 | for (int j = 0; j < 10; ++j) { |
| 576 | if (a[i] > b[j]) |
| 577 | throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}} |
| 578 | } |
| 579 | throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}} |
| 580 | } |
| 581 | catch (float f) { |
| 582 | if (f > 0.1) |
| 583 | throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}} |
| 584 | return; // expected-error {{cannot return from OpenMP region}} |
| 585 | } |
| 586 | switch(i) { |
| 587 | case 1: |
| 588 | b[i]++; |
| 589 | break; |
| 590 | default: |
| 591 | break; |
| 592 | } |
| 593 | for (int j = 0; j < 10; j++) { |
| 594 | if (c[i] > 10) |
| 595 | throw c[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}} |
| 596 | } |
| 597 | } |
| 598 | if (c[9] > 10) |
| 599 | throw c[9]; // OK |
| 600 | |
| 601 | #pragma omp simd |
| 602 | for (int i = 0; i < 10; ++i) { |
| 603 | struct S { |
| 604 | void g() { throw 0; } |
| 605 | }; |
| 606 | } |
| 607 | } |
| 608 | |