1 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -verify -fopenmp \ 2 // RUN: -fopenmp-version=51 -Wuninitialized %s 3 4 void foo() 5 { 6 int i,j,k; 7 int z; 8 9 // expected-error@+2 {{statement after '#pragma omp teams loop' must be a for loop}} 10 #pragma omp teams loop bind(thread) 11 i = 0; 12 13 // OpenMP 5.1 [2.22 Nesting of regions] 14 // 15 // A barrier region may not be closely nested inside a worksharing, loop, 16 // task, taskloop, critical, ordered, atomic, or masked region. 17 18 // expected-error@+3 {{region cannot be closely nested inside 'teams loop' region}} 19 #pragma omp teams loop bind(thread) 20 for (i=0; i<1000; ++i) { 21 #pragma omp barrier 22 } 23 24 // A masked region may not be closely nested inside a worksharing, loop, 25 // atomic, task, or taskloop region. 26 27 // expected-error@+3 {{region cannot be closely nested inside 'teams loop' region}} 28 #pragma omp teams loop bind(thread) 29 for (i=0; i<1000; ++i) { 30 #pragma omp masked filter(2) 31 { } 32 } 33 34 // An ordered region that corresponds to an ordered construct without any 35 // clause or with the threads or depend clause may not be closely nested 36 // inside a critical, ordered, loop, atomic, task, or taskloop region. 37 38 // expected-error@+3 {{region cannot be closely nested inside 'teams loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} 39 #pragma omp teams loop bind(thread) 40 for (i=0; i<1000; ++i) { 41 #pragma omp ordered 42 { } 43 } 44 45 // expected-error@+3 {{region cannot be closely nested inside 'teams loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} 46 #pragma omp teams loop bind(thread) 47 for (i=0; i<1000; ++i) { 48 #pragma omp ordered threads 49 { } 50 } 51 52 // expected-error@+3 {{region cannot be closely nested inside 'teams loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} 53 #pragma omp teams loop bind(thread) 54 for (i=0; i<1000; ++i) { 55 #pragma omp ordered depend(source) 56 } 57 58 // bind clause 59 60 // expected-error@+1 {{directive '#pragma omp teams loop' cannot contain more than one 'bind' clause}} 61 #pragma omp teams loop bind(thread) bind(thread) 62 for (i=0; i<1000; ++i) { 63 } 64 65 // expected-error@+2 {{expected 'teams', 'parallel' or 'thread' in OpenMP clause 'bind'}} 66 #pragma omp target 67 #pragma omp teams loop bind(other) 68 for (i=0; i<1000; ++i) { 69 } 70 71 // collapse clause 72 73 // expected-error@+4 {{expected 2 for loops after '#pragma omp teams loop', but found only 1}} 74 // expected-note@+1 {{as specified in 'collapse' clause}} 75 #pragma omp teams loop collapse(2) bind(thread) 76 for (i=0; i<1000; ++i) 77 z = i+11; 78 79 // expected-error@+1 {{directive '#pragma omp teams loop' cannot contain more than one 'collapse' clause}} 80 #pragma omp teams loop collapse(2) collapse(2) bind(thread) 81 for (i=0; i<1000; ++i) 82 for (j=0; j<1000; ++j) 83 z = i+j+11; 84 85 // order clause 86 87 // expected-error@+1 {{expected 'concurrent' in OpenMP clause 'order'}} 88 #pragma omp teams loop order(foo) bind(thread) 89 for (i=0; i<1000; ++i) 90 z = i+11; 91 92 // private clause 93 94 // expected-error@+1 {{use of undeclared identifier 'undef_var'}} 95 #pragma omp teams loop private(undef_var) bind(thread) 96 for (i=0; i<1000; ++i) 97 z = i+11; 98 99 // lastprivate 100 101 // A list item may not appear in a lastprivate clause unless it is the loop 102 // iteration variable of a loop that is associated with the construct. 103 104 // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp teams loop' directives}} 105 #pragma omp teams loop lastprivate(z) bind(thread) 106 for (i=0; i<1000; ++i) { 107 z = i+11; 108 } 109 110 // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp teams loop' directives}} 111 #pragma omp teams loop lastprivate(k) collapse(2) bind(thread) 112 for (i=0; i<1000; ++i) 113 for (j=0; j<1000; ++j) 114 for (k=0; k<1000; ++k) 115 z = i+j+k+11; 116 117 // reduction 118 119 // expected-error@+1 {{use of undeclared identifier 'undef_var'}} 120 #pragma omp teams loop reduction(+:undef_var) bind(thread) 121 for (i=0; i<1000; ++i) 122 z = i+11; 123 } 124 125 template <typename T, int C> 126 void templ_test(T t) { 127 T i,z; 128 129 // expected-error@+4 {{expected 2 for loops after '#pragma omp teams loop', but found only 1}} 130 // expected-note@+1 {{as specified in 'collapse' clause}} 131 #pragma omp teams loop collapse(C) bind(thread) 132 for (i=0; i<1000; ++i) 133 z = i+11; 134 135 // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp teams loop' directives}} 136 #pragma omp teams loop lastprivate(z) bind(thread) 137 for (i=0; i<1000; ++i) { 138 z = i+11; 139 } 140 } 141 142 void bar() 143 { 144 templ_test<int, 2>(16); // expected-note {{in instantiation of function template specialization 'templ_test<int, 2>' requested here}} 145 } 146