1a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar// RUN: %clang_cc1 -verify -fopenmp %s
2a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
3a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarvoid foo() {
4a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar}
5a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
6a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarbool foobool(int argc) {
7a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  return argc;
8a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar}
9a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
10a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarstruct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
11a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarextern S1 a;
12a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarclass S2 {
13a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  mutable int a;
14a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
15a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarpublic:
16a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S2() : a(0) {}
17a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S2(const S2 &s2) : a(s2.a) {}
18a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  static float S2s;
19a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  static const float S2sc;
20a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar};
21a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarconst float S2::S2sc = 0;
22a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarconst S2 b;
23a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarconst S2 ba[5];
24a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarclass S3 {
25a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  int a;
26a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S3 &operator=(const S3 &s3);
27a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
28a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarpublic:
29a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S3() : a(0) {} // expected-note {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
30a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S3(S3 &s3) : a(s3.a) {} // expected-note {{candidate constructor not viable: 1st argument ('const S3') would lose const qualifier}}
31a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar};
32a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarconst S3 c;
33a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarconst S3 ca[5];
34a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarextern const int f;
35a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarclass S4 {
36a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  int a;
37a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S4();
38a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S4(const S4 &s4);
39a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarpublic:
40a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S4(int v):a(v) { }
41a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar};
42a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarclass S5 {
43a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  int a;
44a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S5():a(0) {}
45a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S5(const S5 &s5):a(s5.a) { }
46a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarpublic:
47a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S5(int v):a(v) { }
48a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar};
49a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarclass S6 {
50a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  int a;
51a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarpublic:
52a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S6() : a(0) { }
53a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar};
54a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
55a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga NainarS3 h;
56a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar#pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}}
57a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
58a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarint main(int argc, char **argv) {
59a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  const int d = 5;
60a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  const int da[5] = { 0 };
61a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S4 e(4);
62a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S5 g(5);
63a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  S6 p;
64a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  int i;
65a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  int &j = i;
66a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate // expected-error {{expected '(' after 'firstprivate'}}
67a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
68a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
69a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
70a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate () // expected-error {{expected expression}}
71a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
72a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
73a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
74a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
75a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
76a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
77a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
78a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
79a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
80a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
81a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
82a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
83a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
84a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
85a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
86a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate (argc)
87a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
88a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
89a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
90a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate (S1) // expected-error {{'S1' does not refer to a value}}
91a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
92a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
93a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
94a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate (a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
95a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
96a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
97a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
98a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate (argv[1]) // expected-error {{expected variable name}}
99a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
100a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
101a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
102a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate(ba)
103a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
104a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
105a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
106a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate(ca) // expected-error {{no matching constructor for initialization of 'S3'}}
107a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
108a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
109a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
110a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate(da)
111a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
112a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
113a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
114a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate(S2::S2s)
115a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
116a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
117a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
118a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate(S2::S2sc)
119a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
120a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
121a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
122a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
123a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
124a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
125a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
126a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute private(i), firstprivate(i) // expected-error {{private variable cannot be firstprivate}} expected-note{{defined as private}}
127a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
128a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
129a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams shared(i)
130a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate(i)
131a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (j = 0; j < argc; ++j) foo();
132a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
133a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams shared(i)
134a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate(i) // expected-note {{defined as firstprivate}}
135a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo(); // expected-error {{loop iteration variable in the associated loop of 'omp distribute' directive may not be firstprivate, predetermined as private}}
136a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
137a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams private(argc) // expected-note {{defined as private}}
138a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate(argc) // expected-error {{private variable in '#pragma omp teams' cannot be firstprivate in '#pragma omp distribute'}}
139a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
140a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
141a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams reduction(+:argc) // expected-note {{defined as reduction}}
142a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate(argc) // expected-error {{reduction variable in '#pragma omp teams' cannot be firstprivate in '#pragma omp distribute'}}
143a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
144a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
145a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
146a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute firstprivate(j)
147a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
148a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
149a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
150a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp distribute lastprivate(argc), firstprivate(argc) // expected-error {{lastprivate variable cannot be firstprivate in '#pragma omp distribute'}} expected-note{{defined as lastprivate}}
151a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
152a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp target
153a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  #pragma omp teams
154a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar#pragma omp distribute firstprivate(argc), lastprivate(argc)  // expected-error {{lastprivate variable cannot be firstprivate in '#pragma omp distribute'}} expected-note{{defined as firstprivate}}
155a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  for (i = 0; i < argc; ++i) foo();
156a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  return 0;
157a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar}
158