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