1 // RUN: %clang_cc1 -verify -fopenmp %s 2 3 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} 4 extern S1 a; 5 class S2 { 6 mutable int a; 7 8 public: 9 S2() : a(0) {} 10 }; 11 const S2 b; 12 const S2 ba[5]; 13 class S3 { 14 int a; 15 16 public: 17 S3() : a(0) {} 18 }; 19 const S3 ca[5]; 20 class S4 { 21 int a; 22 S4(); // expected-note {{implicitly declared private here}} 23 24 public: 25 S4(int v) : a(v) { 26 #pragma omp target private(a) private(this->a) 27 for (int k = 0; k < v; ++k) 28 ++this->a; 29 } 30 }; 31 class S5 { 32 int a; 33 S5() : a(0) {} // expected-note {{implicitly declared private here}} 34 35 public: 36 S5(int v) : a(v) {} 37 S5 &operator=(S5 &s) { 38 #pragma omp target private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}} 39 for (int k = 0; k < s.a; ++k) 40 ++s.a; 41 return *this; 42 } 43 }; 44 45 template <typename T> 46 class S6 { 47 public: 48 T a; 49 50 S6() : a(0) {} 51 S6(T v) : a(v) { 52 #pragma omp target private(a) private(this->a) 53 for (int k = 0; k < v; ++k) 54 ++this->a; 55 } 56 S6 &operator=(S6 &s) { 57 #pragma omp target private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}} 58 for (int k = 0; k < s.a; ++k) 59 ++s.a; 60 return *this; 61 } 62 }; 63 64 template <typename T> 65 class S7 : public T { 66 T a; 67 S7() : a(0) {} 68 69 public: 70 S7(T v) : a(v) { 71 #pragma omp target private(a) private(this->a) private(T::a) 72 for (int k = 0; k < a.a; ++k) 73 ++this->a.a; 74 } 75 S7 &operator=(S7 &s) { 76 #pragma omp target private(a) private(this->a) private(s.a) private(s.T::a) // expected-error 2 {{expected variable name or data member of current class}} 77 for (int k = 0; k < s.a.a; ++k) 78 ++s.a.a; 79 return *this; 80 } 81 }; 82 83 S3 h; 84 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} 85 86 template <class I, class C> 87 int foomain(I argc, C **argv) { 88 I e(4); 89 I g(5); 90 int i; 91 int &j = i; 92 #pragma omp target private // expected-error {{expected '(' after 'private'}} 93 {} 94 #pragma omp target private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 95 {} 96 #pragma omp target private() // expected-error {{expected expression}} 97 {} 98 #pragma omp target private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 99 {} 100 #pragma omp target private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 101 {} 102 #pragma omp target private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 103 {} 104 #pragma omp target private(argc) 105 {} 106 #pragma omp target private(S1) // expected-error {{'S1' does not refer to a value}} 107 {} 108 #pragma omp target private(a, b) // expected-error {{private variable with incomplete type 'S1'}} 109 {} 110 #pragma omp target private(argv[1]) // expected-error {{expected variable name}} 111 {} 112 #pragma omp target private(e, g) 113 {} 114 #pragma omp target private(h) // expected-error {{threadprivate or thread local variable cannot be private}} 115 {} 116 #pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}} 117 #pragma omp parallel 118 { 119 int v = 0; 120 int i; 121 } 122 #pragma omp parallel shared(i) 123 #pragma omp parallel private(i) 124 #pragma omp target private(j) 125 {} 126 #pragma omp target private(i) 127 {} 128 return 0; 129 } 130 131 void bar(S4 a[2]) { 132 #pragma omp parallel 133 #pragma omp target private(a) 134 {} 135 } 136 137 namespace A { 138 double x; 139 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} 140 } 141 namespace B { 142 using A::x; 143 } 144 145 int main(int argc, char **argv) { 146 S4 e(4); 147 S5 g(5); 148 S6<float> s6(0.0) , s6_0(1.0); 149 S7<S6<float> > s7(0.0) , s7_0(1.0); 150 int i; 151 int &j = i; 152 #pragma omp target private // expected-error {{expected '(' after 'private'}} 153 {} 154 #pragma omp target private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 155 {} 156 #pragma omp target private() // expected-error {{expected expression}} 157 {} 158 #pragma omp target private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 159 {} 160 #pragma omp target private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 161 {} 162 #pragma omp target private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 163 {} 164 #pragma omp target private(argc) 165 {} 166 #pragma omp target private(S1) // expected-error {{'S1' does not refer to a value}} 167 {} 168 #pragma omp target private(a, b) // expected-error {{private variable with incomplete type 'S1'}} 169 {} 170 #pragma omp target private(argv[1]) // expected-error {{expected variable name}} 171 {} 172 #pragma omp target private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} 173 {} 174 #pragma omp target private(h) // expected-error {{threadprivate or thread local variable cannot be private}} 175 {} 176 #pragma omp target private(B::x) // expected-error {{threadprivate or thread local variable cannot be private}} 177 {} 178 #pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}} 179 #pragma omp parallel 180 { 181 int i; 182 } 183 #pragma omp parallel shared(i) 184 #pragma omp parallel private(i) 185 #pragma omp target private(j) 186 {} 187 #pragma omp target private(i) 188 {} 189 static int si; 190 #pragma omp target private(si) // OK 191 {} 192 #pragma omp target map(i) private(i) // expected-error {{private variable cannot be in a map clause in '#pragma omp target' directive}} 193 {} 194 s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}} 195 s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float> >::operator=' requested here}} 196 return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}} 197 } 198 199