1 // RUN: %clang_cc1 -verify=expected,lt50,lt51 -fopenmp -fopenmp-version=45 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized 2 // RUN: %clang_cc1 -verify=expected,ge50,lt51 -fopenmp -fopenmp-version=50 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized 3 // RUN: %clang_cc1 -verify=expected,ge50,ge51 -fopenmp -fopenmp-version=51 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized 4 5 // RUN: %clang_cc1 -verify=expected,lt50,lt51 -fopenmp-simd -fopenmp-version=45 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized 6 // RUN: %clang_cc1 -verify=expected,ge50,lt51 -fopenmp-simd -fopenmp-version=50 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized 7 // RUN: %clang_cc1 -verify=expected,ge50,ge51 -fopenmp-simd -fopenmp-version=51 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized 8 9 // RUN: %clang_cc1 -verify=expected,ge50,ge51,cxx2b -fopenmp -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++2b %s -Wuninitialized 10 11 void xxx(int argc) { 12 int x; // expected-note {{initialize the variable 'x' to silence this warning}} 13 #pragma omp target update to(x) 14 argc = x; // expected-warning {{variable 'x' is uninitialized when used here}} 15 } 16 17 void foo() { 18 } 19 20 bool foobool(int argc) { 21 return argc; 22 } 23 24 struct S1; // Aexpected-note {{declared here}} 25 26 template <class T, class S> // Aexpected-note {{declared here}} 27 int tmain(T argc, S **argv) { 28 int n; 29 return 0; 30 } 31 32 struct S { 33 int i; 34 }; 35 36 int main(int argc, char **argv) { 37 int m; 38 #pragma omp target update // expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 39 #pragma omp target update to(m) { // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}} 40 #pragma omp target update to(m) ( // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}} 41 #pragma omp target update to(m) [ // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}} 42 #pragma omp target update to(m) ] // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}} 43 #pragma omp target update to(m) ) // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}} 44 45 #pragma omp declare mapper(id: S s) map(s.i) 46 S s; 47 48 // Check parsing with no modifiers. 49 // lt51-error@+2 {{expected expression}} 50 // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 51 #pragma omp target update to(: s) 52 // expected-error@+2 {{expected expression}} 53 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 54 #pragma omp target update to(:) 55 // expected-error@+2 2 {{expected expression}} 56 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 57 #pragma omp target update to(,:) 58 59 // Check parsing with one modifier. 60 // expected-error@+2 {{use of undeclared identifier 'foobar'}} 61 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 62 #pragma omp target update to(foobar: s) 63 // expected-error@+3 {{expected ',' or ')' in 'to' clause}} 64 // expected-error@+2 {{expected ')'}} 65 // expected-note@+1 {{to match this '('}} 66 #pragma omp target update to(m: s) 67 #pragma omp target update to(mapper(id): s) 68 // lt51-error@+2 {{use of undeclared identifier 'present'}} 69 // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 70 #pragma omp target update to(present: s) 71 // ge51-warning@+4 {{missing ':' after motion modifier - ignoring}} 72 // lt51-warning@+3 {{missing ':' after ) - ignoring}} 73 // expected-error@+2 {{expected expression}} 74 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 75 #pragma omp target update to(mapper(id) s) 76 // ge51-warning@+4 {{missing ':' after motion modifier - ignoring}} 77 // ge51-error@+3 {{expected expression}} 78 // lt51-error@+2 {{use of undeclared identifier 'present'}} 79 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 80 #pragma omp target update to(present s) 81 // ge51-warning@+4 {{missing ':' after motion modifier - ignoring}} 82 // lt51-warning@+3 {{missing ':' after ) - ignoring}} 83 // expected-error@+2 {{expected expression}} 84 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 85 #pragma omp target update to(mapper(id)) 86 // ge51-warning@+4 {{missing ':' after motion modifier - ignoring}} 87 // ge51-error@+3 {{expected expression}} 88 // lt51-error@+2 {{use of undeclared identifier 'present'}} 89 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 90 #pragma omp target update to(present) 91 // expected-error@+2 {{expected expression}} 92 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 93 #pragma omp target update to(mapper(id):) 94 // ge51-error@+3 {{expected expression}} 95 // lt51-error@+2 {{use of undeclared identifier 'present'}} 96 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 97 #pragma omp target update to(present:) 98 99 // Check parsing with two modifiers. 100 // lt51-warning@+1 {{missing ':' after ) - ignoring}} 101 #pragma omp target update to(mapper(id), present: s) 102 // lt51-error@+3 {{use of undeclared identifier 'present'}} 103 // lt51-error@+2 {{use of undeclared identifier 'id'}} 104 // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 105 #pragma omp target update to(present, mapper(id): s) 106 // lt51-warning@+1 {{missing ':' after ) - ignoring}} 107 #pragma omp target update to(mapper(id) present: s) 108 // lt51-error@+2 {{use of undeclared identifier 'present'}} 109 // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 110 #pragma omp target update to(present mapper(id): s) 111 112 // Check parsing with unnecessary commas. 113 // lt51-warning@+1 {{missing ':' after ) - ignoring}} 114 #pragma omp target update to(mapper(id),: s) 115 // lt51-error@+3 {{use of undeclared identifier 'present'}} 116 // lt51-error@+2 {{expected expression}} 117 // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 118 #pragma omp target update to(present , : s) 119 // ge51-warning@+2 {{missing ':' after motion modifier - ignoring}} 120 // lt51-warning@+1 {{missing ':' after ) - ignoring}} 121 #pragma omp target update to(mapper(id),,: s) 122 // ge51-warning@+5 {{missing ':' after motion modifier - ignoring}} 123 // lt51-error@+4 {{use of undeclared identifier 'present'}} 124 // lt51-error@+3 {{expected expression}} 125 // lt51-error@+2 {{expected expression}} 126 // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 127 #pragma omp target update to(present,,: s) 128 // lt51-warning@+1 {{missing ':' after ) - ignoring}} 129 #pragma omp target update to(mapper(id), present,: s) 130 // lt51-error@+4 {{use of undeclared identifier 'present'}} 131 // lt51-error@+3 {{use of undeclared identifier 'id'}} 132 // lt51-error@+2 {{expected expression}} 133 // lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 134 #pragma omp target update to(present, mapper(id),: s) 135 136 #pragma omp target update from(m) allocate(m) // expected-error {{unexpected OpenMP clause 'allocate' in directive '#pragma omp target update'}} 137 { 138 foo(); 139 } 140 141 double marr[10][5][10]; 142 #pragma omp target update to(marr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 143 {} 144 #pragma omp target update from(marr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 145 146 #pragma omp target update to(marr[0:][1:2:2][1:2]) // ge50-error {{array section does not specify length for outermost dimension}} lt50-error {{expected ']'}} lt50-note {{to match this '['}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 147 {} 148 #pragma omp target update from(marr[0:][1:2:2][1:2]) // ge50-error {{array section does not specify length for outermost dimension}} lt50-error {{expected ']'}} lt50-note {{to match this '['}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 149 150 int arr[4][3][2][1]; 151 #pragma omp target update to(arr[0:2][2:4][:2][1]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 152 {} 153 #pragma omp target update from(arr[0:2][2:4][:2][1]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 154 155 double ***dptr; 156 #pragma omp target update to(dptr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} ge50-error 2 {{section length is unspecified and cannot be inferred because subscripted value is an array of unknown bound}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 157 {} 158 #pragma omp target update from(dptr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} ge50-error 2 {{section length is unspecified and cannot be inferred because subscripted value is an array of unknown bound}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 159 160 int iarr[5][5]; 161 // ge50-error@+4 {{section stride is evaluated to a non-positive value -1}} 162 // lt50-error@+3 {{expected ']'}} 163 // lt50-note@+2 {{to match this '['}} 164 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 165 #pragma omp target update to(iarr[0:][1:2:-1]) 166 {} 167 // ge50-error@+4 {{section stride is evaluated to a non-positive value -1}} 168 // lt50-error@+3 {{expected ']'}} 169 // lt50-note@+2 {{to match this '['}} 170 // expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 171 #pragma omp target update from(iarr[0:][1:2:-1]) 172 {} 173 // lt50-error@+5 {{expected expression}} 174 // ge50-error@+4 {{array section does not specify length for outermost dimension}} 175 // lt50-error@+3 {{expected ']'}} 176 // lt50-note@+2 {{to match this '['}} 177 // lt50-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 178 #pragma omp target update to(iarr[0: :2][1:2]) 179 {} 180 // lt50-error@+5 {{expected expression}} 181 // ge50-error@+4 {{array section does not specify length for outermost dimension}} 182 // lt50-error@+3 {{expected ']'}} 183 // lt50-note@+2 {{to match this '['}} 184 // lt50-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 185 #pragma omp target update from(iarr[0: :2][1:2]) 186 {} 187 188 return tmain(argc, argv); 189 } 190 191 template<typename _Tp, int _Nm> struct array { 192 _Tp & operator[](int __n) noexcept; 193 }; 194 195 #pragma omp declare target 196 extern array<double, 4> arr; 197 #pragma omp end declare target 198 199 void copy_host_to_device() 200 { 201 #pragma omp target update from(arr) // expected-no-error 202 arr[0] = 0; 203 } 204 205 struct FOO; // expected-note {{forward declaration of 'FOO'}} 206 extern FOO a; 207 template <typename T, int I> 208 struct bar { 209 void func() { 210 #pragma omp target map(to: a) // expected-error {{incomplete type 'FOO' where a complete type is required}} 211 foo(); 212 } 213 }; 214 215 #if defined(__cplusplus) && __cplusplus >= 202101L 216 217 namespace cxx2b { 218 219 struct S { 220 int operator[](auto...); 221 }; 222 223 void f() { 224 225 int test[10]; 226 227 #pragma omp target update to(test[1]) 228 229 #pragma omp target update to(test[1, 2]) // cxx2b-error {{type 'int[10]' does not provide a subscript operator}} \ 230 // cxx2b-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 231 232 #pragma omp target update to(test [1:1:1]) 233 234 #pragma omp target update to(test [1, 2:1:1]) // cxx2b-error {{expected ']'}} // expected-note {{'['}} \ 235 // cxx2b-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 236 237 #pragma omp target update to(test [1, 2:]) // cxx2b-error {{expected ']'}} // expected-note {{'['}} \ 238 // cxx2b-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 239 240 #pragma omp target update to(test[1, 2 ::]) // cxx2b-error {{expected ']'}} // expected-note {{'['}} \ 241 // cxx2b-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 242 243 #pragma omp target update to(test[]) // cxx2b-error {{type 'int[10]' does not provide a subscript operator}} \ 244 // cxx2b-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} 245 S s; 246 (void)s[0]; 247 (void)s[]; 248 (void)s[1, 2]; 249 } 250 251 } 252 253 #endif 254