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