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