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 S2(const S2 &s2) : a(s2.a) {} 21 static float S2s; 22 static const float S2sc; 23 }; 24 const float S2::S2sc = 0; 25 const S2 b; 26 const S2 ba[5]; 27 class S3 { 28 int a; 29 S3 &operator=(const S3 &s3); 30 31 public: 32 S3() : a(0) {} 33 S3(const S3 &s3) : a(s3.a) {} 34 }; 35 const S3 c; 36 const S3 ca[5]; 37 extern const int f; 38 class S4 { 39 int a; 40 S4(); 41 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}} 42 43 public: 44 S4(int v) : a(v) {} 45 }; 46 class S5 { 47 int a; 48 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}} 49 50 public: 51 S5() : a(0) {} 52 S5(int v) : a(v) {} 53 }; 54 class S6 { 55 int a; 56 S6() : a(0) {} 57 58 public: 59 S6(const S6 &s6) : a(s6.a) {} 60 S6(int v) : a(v) {} 61 }; 62 63 S3 h; 64 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} 65 66 template <class I, class C> 67 int foomain(int argc, char **argv) { 68 I e(4); 69 C g(5); 70 int i, z; 71 int &j = i; 72 #pragma omp parallel 73 #pragma omp single firstprivate // expected-error {{expected '(' after 'firstprivate'}} 74 foo(); 75 #pragma omp parallel 76 #pragma omp single firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 77 foo(); 78 #pragma omp parallel 79 #pragma omp single firstprivate() // expected-error {{expected expression}} 80 foo(); 81 #pragma omp parallel 82 #pragma omp single firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 83 foo(); 84 #pragma omp parallel 85 #pragma omp single firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 86 foo(); 87 #pragma omp parallel 88 #pragma omp single firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 89 foo(); 90 #pragma omp parallel 91 #pragma omp single firstprivate(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 '('}} 92 foo(); 93 #pragma omp parallel 94 #pragma omp single firstprivate(S1) // expected-error {{'S1' does not refer to a value}} 95 foo(); 96 #pragma omp parallel 97 #pragma omp single firstprivate(z, a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} 98 foo(); 99 #pragma omp parallel 100 #pragma omp single firstprivate(argv[1]) // expected-error {{expected variable name}} 101 foo(); 102 #pragma omp parallel 103 #pragma omp single firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} 104 foo(); 105 #pragma omp parallel 106 #pragma omp single firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} 107 foo(); 108 #pragma omp parallel 109 #pragma omp single linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp single'}} 110 foo(); 111 #pragma omp parallel 112 { 113 int v = 0; 114 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp single' directive into a parallel or another task region?}} 115 #pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}} 116 foo(); 117 v += i; 118 } 119 #pragma omp parallel shared(i) 120 #pragma omp parallel private(i) 121 #pragma omp single firstprivate(j) 122 foo(); 123 #pragma omp parallel 124 #pragma omp single firstprivate(i) 125 foo(); 126 #pragma omp parallel 127 #pragma omp single firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} 128 foo(); 129 #pragma omp parallel private(i) // expected-note {{defined as private}} 130 #pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}} 131 foo(); 132 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}} 133 #pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}} 134 foo(); 135 return 0; 136 } 137 138 namespace A { 139 double x; 140 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} 141 } 142 namespace B { 143 using A::x; 144 } 145 146 int main(int argc, char **argv) { 147 const int d = 5; 148 const int da[5] = {0}; 149 S4 e(4); 150 S5 g(5); 151 S3 m; 152 S6 n(2); 153 int i, z; 154 int &j = i; 155 #pragma omp parallel 156 #pragma omp single firstprivate // expected-error {{expected '(' after 'firstprivate'}} 157 foo(); 158 #pragma omp parallel 159 #pragma omp single firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 160 foo(); 161 #pragma omp parallel 162 #pragma omp single firstprivate() // expected-error {{expected expression}} 163 foo(); 164 #pragma omp parallel 165 #pragma omp single firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 166 foo(); 167 #pragma omp parallel 168 #pragma omp single firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 169 foo(); 170 #pragma omp parallel 171 #pragma omp single firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 172 foo(); 173 #pragma omp parallel 174 #pragma omp single firstprivate(argc, z) 175 foo(); 176 #pragma omp parallel 177 #pragma omp single firstprivate(S1) // expected-error {{'S1' does not refer to a value}} 178 foo(); 179 #pragma omp parallel 180 #pragma omp single firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} 181 foo(); 182 #pragma omp parallel 183 #pragma omp single firstprivate(argv[1]) // expected-error {{expected variable name}} 184 foo(); 185 #pragma omp parallel 186 #pragma omp single firstprivate(2 * 2) // expected-error {{expected variable name}} 187 foo(); 188 #pragma omp parallel 189 #pragma omp single firstprivate(ba) // OK 190 foo(); 191 #pragma omp parallel 192 #pragma omp single firstprivate(ca) // OK 193 foo(); 194 #pragma omp parallel 195 #pragma omp single firstprivate(da) // OK 196 foo(); 197 int xa; 198 #pragma omp parallel 199 #pragma omp single firstprivate(xa) // OK 200 foo(); 201 #pragma omp parallel 202 #pragma omp single firstprivate(S2::S2s) // OK 203 foo(); 204 #pragma omp parallel 205 #pragma omp single firstprivate(S2::S2sc) // OK 206 foo(); 207 #pragma omp parallel 208 #pragma omp single safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp single'}} 209 foo(); 210 #pragma omp parallel 211 #pragma omp single firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} 212 foo(); 213 #pragma omp parallel 214 #pragma omp single firstprivate(m) // OK 215 foo(); 216 #pragma omp parallel 217 #pragma omp single firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}} 218 foo(); 219 #pragma omp parallel 220 #pragma omp single private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}} 221 foo(); 222 #pragma omp parallel shared(xa) 223 #pragma omp single firstprivate(xa) // OK: may be firstprivate 224 foo(); 225 #pragma omp parallel 226 #pragma omp single firstprivate(j) 227 foo(); 228 #pragma omp parallel 229 #pragma omp single firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} 230 foo(); 231 #pragma omp parallel 232 #pragma omp single firstprivate(n) // OK 233 foo(); 234 #pragma omp parallel 235 { 236 int v = 0; 237 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp single' directive into a parallel or another task region?}} 238 #pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}} 239 foo(); 240 v += i; 241 } 242 #pragma omp parallel private(i) // expected-note {{defined as private}} 243 #pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}} 244 foo(); 245 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}} 246 #pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}} 247 foo(); 248 static int t; 249 #pragma omp single firstprivate(t) // OK 250 foo(); 251 252 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}} 253 } 254