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