1 // RUN: %clang_cc1 -verify -fopenmp -o - %s -Wno-openmp-target 2 // RUN: %clang_cc1 -verify -fopenmp -std=c++98 -o - %s -Wno-openmp-target 3 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -o - %s -Wno-openmp-target 4 5 // RUN: %clang_cc1 -verify -fopenmp-simd -o - %s -Wno-openmp-target 6 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++98 -o - %s -Wno-openmp-target 7 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 -o - %s -Wno-openmp-target 8 9 extern int omp_default_mem_alloc; 10 void foo() { 11 } 12 13 bool foobool(int argc) { 14 return argc; 15 } 16 17 void foobar(int &ref) { 18 #pragma omp target 19 #pragma omp teams reduction(+:ref) 20 foo(); 21 } 22 23 struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}} 24 extern S1 a; 25 class S2 { 26 mutable int a; 27 S2 &operator+(const S2 &arg) { return (*this); } // expected-note 3 {{implicitly declared private here}} 28 29 public: 30 S2() : a(0) {} 31 S2(S2 &s2) : a(s2.a) {} 32 static float S2s; // expected-note 2 {{static data member is predetermined as shared}} 33 static const float S2sc; // expected-note 2 {{'S2sc' declared here}} 34 }; 35 const float S2::S2sc = 0; 36 S2 b; // expected-note 3 {{'b' defined here}} 37 const S2 ba[5]; // expected-note 2 {{'ba' defined here}} 38 class S3 { 39 int a; 40 41 public: 42 int b; 43 S3() : a(0) {} 44 S3(const S3 &s3) : a(s3.a) {} 45 S3 operator+(const S3 &arg1) { return arg1; } 46 }; 47 int operator+(const S3 &arg1, const S3 &arg2) { return 5; } 48 S3 c; // expected-note 3 {{'c' defined here}} 49 const S3 ca[5]; // expected-note 2 {{'ca' defined here}} 50 extern const int f; // expected-note 4 {{'f' declared here}} 51 class S4 { 52 int a; 53 S4(); // expected-note {{implicitly declared private here}} 54 S4(const S4 &s4); 55 S4 &operator+(const S4 &arg) { return (*this); } 56 57 public: 58 S4(int v) : a(v) {} 59 }; 60 S4 &operator&=(S4 &arg1, S4 &arg2) { return arg1; } 61 class S5 { 62 int a; 63 S5() : a(0) {} // expected-note {{implicitly declared private here}} 64 S5(const S5 &s5) : a(s5.a) {} 65 S5 &operator+(const S5 &arg); 66 67 public: 68 S5(int v) : a(v) {} 69 }; 70 class S6 { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const S6' for 1st argument}} 71 #if __cplusplus >= 201103L // C++11 or later 72 // expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}} 73 #endif 74 int a; 75 76 public: 77 S6() : a(6) {} 78 operator int() { return 6; } 79 } o; 80 81 S3 h, k; 82 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} 83 84 template <class T> // expected-note {{declared here}} 85 T tmain(T argc) { 86 const T d = T(); // expected-note 4 {{'d' defined here}} 87 const T da[5] = {T()}; // expected-note 2 {{'da' defined here}} 88 T qa[5] = {T()}; 89 T i; 90 T &j = i; // expected-note 4 {{'j' defined here}} 91 S3 &p = k; // expected-note 2 {{'p' defined here}} 92 const T &r = da[(int)i]; // expected-note 2 {{'r' defined here}} 93 T &q = qa[(int)i]; // expected-note 2 {{'q' defined here}} 94 T fl; 95 #pragma omp target 96 #pragma omp teams reduction // expected-error {{expected '(' after 'reduction'}} 97 foo(); 98 #pragma omp target 99 #pragma omp teams reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}} 100 foo(); 101 #pragma omp target 102 #pragma omp teams reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}} 103 foo(); 104 #pragma omp target 105 #pragma omp teams reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 106 foo(); 107 #pragma omp target 108 #pragma omp teams reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} 109 foo(); 110 #pragma omp target 111 #pragma omp teams reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} 112 foo(); 113 #pragma omp target 114 #pragma omp teams reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} 115 foo(); 116 #pragma omp target 117 #pragma omp teams reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}} 118 foo(); 119 #pragma omp target 120 #pragma omp teams reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}} 121 foo(); 122 #pragma omp target 123 #pragma omp teams reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name, array element or array section}} 124 foo(); 125 #pragma omp target 126 #pragma omp teams reduction(foo : argc) //expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'float'}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'int'}} 127 foo(); 128 #pragma omp target 129 #pragma omp teams reduction(&& : argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}} 130 foo(); 131 #pragma omp target 132 #pragma omp teams reduction(^ : T) // expected-error {{'T' does not refer to a value}} 133 foo(); 134 #pragma omp target 135 #pragma omp teams reduction(+ : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 3 {{const-qualified variable cannot be reduction}} expected-error 2 {{'operator+' is a private member of 'S2'}} 136 foo(); 137 #pragma omp target 138 #pragma omp teams reduction(min : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 4 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 3 {{const-qualified variable cannot be reduction}} 139 foo(); 140 #pragma omp target 141 #pragma omp teams reduction(max : h.b) // expected-error {{expected variable name, array element or array section}} 142 foo(); 143 #pragma omp target 144 #pragma omp teams reduction(+ : ba) // expected-error {{const-qualified variable cannot be reduction}} 145 foo(); 146 #pragma omp target 147 #pragma omp teams reduction(* : ca) // expected-error {{const-qualified variable cannot be reduction}} 148 foo(); 149 #pragma omp target 150 #pragma omp teams reduction(- : da) // expected-error {{const-qualified variable cannot be reduction}} expected-error {{const-qualified variable cannot be reduction}} 151 foo(); 152 #pragma omp target 153 #pragma omp teams reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}} 154 foo(); 155 #pragma omp target 156 #pragma omp teams reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}} 157 foo(); 158 #pragma omp target 159 #pragma omp teams reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}} 160 foo(); 161 #pragma omp target 162 #pragma omp teams reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}} 163 foo(); 164 #pragma omp target 165 #pragma omp teams reduction(+ : o) // expected-error 2 {{no viable overloaded '='}} 166 foo(); 167 #pragma omp target 168 #pragma omp teams private(i), reduction(+ : j), reduction(+ : q) // expected-error 4 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} 169 foo(); 170 #pragma omp parallel private(k) 171 #pragma omp target 172 #pragma omp teams reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} 173 foo(); 174 #pragma omp target 175 #pragma omp teams reduction(+ : p), reduction(+ : p) // expected-error 2 {{variable can appear only once in OpenMP 'reduction' clause}} expected-note 2 {{previously referenced here}} 176 foo(); 177 #pragma omp target 178 #pragma omp teams reduction(+ : r) // expected-error 2 {{const-qualified variable cannot be reduction}} 179 foo(); 180 #pragma omp parallel shared(i) 181 #pragma omp parallel reduction(min : i) 182 #pragma omp target 183 #pragma omp teams reduction(max : j) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} 184 foo(); 185 #pragma omp target 186 #pragma omp teams 187 #pragma omp parallel for private(fl) 188 for (int i = 0; i < 10; ++i) 189 {} 190 #pragma omp target 191 #pragma omp teams reduction(+ : fl) 192 foo(); 193 #pragma omp target 194 #pragma omp teams 195 #pragma omp parallel for reduction(- : fl) 196 for (int i = 0; i < 10; ++i) 197 {} 198 #pragma omp target 199 #pragma omp teams reduction(+ : fl) 200 foo(); 201 202 return T(); 203 } 204 205 namespace A { 206 double x; 207 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} 208 } 209 namespace B { 210 using A::x; 211 } 212 213 int main(int argc, char **argv) { 214 const int d = 5; // expected-note 2 {{'d' defined here}} 215 const int da[5] = {0}; // expected-note {{'da' defined here}} 216 int qa[5] = {0}; 217 S4 e(4); 218 S5 g(5); 219 int i; 220 int &j = i; // expected-note 2 {{'j' defined here}} 221 S3 &p = k; // expected-note 2 {{'p' defined here}} 222 const int &r = da[i]; // expected-note {{'r' defined here}} 223 int &q = qa[i]; // expected-note {{'q' defined here}} 224 float fl; 225 #pragma omp target 226 #pragma omp teams reduction // expected-error {{expected '(' after 'reduction'}} 227 foo(); 228 #pragma omp target 229 #pragma omp teams reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}} 230 foo(); 231 #pragma omp target 232 #pragma omp teams reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}} 233 foo(); 234 #pragma omp target 235 #pragma omp teams reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 236 foo(); 237 #pragma omp target 238 #pragma omp teams reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} 239 foo(); 240 #pragma omp target 241 #pragma omp teams reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} 242 foo(); 243 #pragma omp target 244 #pragma omp teams reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} 245 foo(); 246 #pragma omp target 247 #pragma omp teams reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}} 248 foo(); 249 #pragma omp target 250 #pragma omp teams reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 251 foo(); 252 #pragma omp target 253 #pragma omp teams reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name, array element or array section}} 254 foo(); 255 #pragma omp target 256 #pragma omp teams reduction(~ : argc) // expected-error {{expected unqualified-id}} 257 foo(); 258 #pragma omp target 259 #pragma omp teams reduction(&& : argc) 260 foo(); 261 #pragma omp target 262 #pragma omp teams reduction(^ : S1) // expected-error {{'S1' does not refer to a value}} 263 foo(); 264 #pragma omp target 265 #pragma omp teams reduction(+ : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{const-qualified variable cannot be reduction}} expected-error {{'operator+' is a private member of 'S2'}} 266 foo(); 267 #pragma omp target 268 #pragma omp teams reduction(min : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 2 {{const-qualified variable cannot be reduction}} 269 foo(); 270 #pragma omp target 271 #pragma omp teams reduction(max : h.b) // expected-error {{expected variable name, array element or array section}} 272 foo(); 273 #pragma omp target 274 #pragma omp teams reduction(+ : ba) // expected-error {{const-qualified variable cannot be reduction}} 275 foo(); 276 #pragma omp target 277 #pragma omp teams reduction(* : ca) // expected-error {{const-qualified variable cannot be reduction}} 278 foo(); 279 #pragma omp target 280 #pragma omp teams reduction(- : da) // expected-error {{const-qualified variable cannot be reduction}} 281 foo(); 282 #pragma omp target 283 #pragma omp teams reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}} 284 foo(); 285 #pragma omp target 286 #pragma omp teams reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}} 287 foo(); 288 #pragma omp target 289 #pragma omp teams reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}} 290 foo(); 291 #pragma omp target 292 #pragma omp teams reduction(& : e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{invalid operands to binary expression ('S4' and 'S4')}} expected-error {{calling a private constructor of class 'S5'}} expected-error {{invalid operands to binary expression ('S5' and 'S5')}} 293 foo(); 294 #pragma omp target 295 #pragma omp teams reduction(+ : h, k, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be reduction}} 296 foo(); 297 #pragma omp target 298 #pragma omp teams reduction(+ : o) // expected-error {{no viable overloaded '='}} 299 foo(); 300 #pragma omp target 301 #pragma omp teams private(i), reduction(+ : j), reduction(+ : q) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} 302 foo(); 303 #pragma omp parallel private(k) 304 #pragma omp target 305 #pragma omp teams reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} 306 foo(); 307 #pragma omp target 308 #pragma omp teams reduction(+ : p), reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'reduction' clause}} expected-note {{previously referenced here}} 309 foo(); 310 #pragma omp target 311 #pragma omp teams reduction(+ : r) // expected-error {{const-qualified variable cannot be reduction}} 312 foo(); 313 #pragma omp parallel shared(i) 314 #pragma omp parallel reduction(min : i) 315 #pragma omp target 316 #pragma omp teams reduction(max : j) // expected-error {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} 317 foo(); 318 #pragma omp target 319 #pragma omp teams 320 #pragma omp parallel for private(fl) 321 for (int i = 0; i < 10; ++i) 322 {} 323 #pragma omp target 324 #pragma omp teams reduction(+ : fl) 325 foo(); 326 #pragma omp target 327 #pragma omp teams 328 #pragma omp parallel for reduction(- : fl) 329 for (int i = 0; i < 10; ++i) 330 {} 331 #pragma omp target 332 #pragma omp teams reduction(+ : fl) 333 foo(); 334 static int m; 335 #pragma omp target 336 #pragma omp teams reduction(+ : m) // OK 337 foo(); 338 339 return tmain(argc) + tmain(fl); // expected-note {{in instantiation of function template specialization 'tmain<int>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<float>' requested here}} 340 } 341