1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized 2 3 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized 4 5 typedef void **omp_allocator_handle_t; 6 extern const omp_allocator_handle_t omp_default_mem_alloc; 7 extern const omp_allocator_handle_t omp_large_cap_mem_alloc; 8 extern const omp_allocator_handle_t omp_const_mem_alloc; 9 extern const omp_allocator_handle_t omp_high_bw_mem_alloc; 10 extern const omp_allocator_handle_t omp_low_lat_mem_alloc; 11 extern const omp_allocator_handle_t omp_cgroup_mem_alloc; 12 extern const omp_allocator_handle_t omp_pteam_mem_alloc; 13 extern const omp_allocator_handle_t omp_thread_mem_alloc; 14 15 void foo() { 16 } 17 18 bool foobool(int argc) { 19 return argc; 20 } 21 22 void xxx(int argc) { 23 int fp; // expected-note {{initialize the variable 'fp' to silence this warning}} 24 #pragma omp target parallel for firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}} 25 for (int i = 0; i < 10; ++i) 26 ; 27 } 28 29 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} 30 extern S1 a; 31 class S2 { 32 mutable int a; 33 34 public: 35 S2() : a(0) {} 36 S2(const S2 &s2) : a(s2.a) {} 37 static float S2s; 38 static const float S2sc; 39 }; 40 const float S2::S2sc = 0; 41 const S2 b; 42 const S2 ba[5]; 43 class S3 { 44 int a; 45 S3 &operator=(const S3 &s3); 46 47 public: 48 S3() : a(0) {} 49 S3(const S3 &s3) : a(s3.a) {} 50 }; 51 const S3 c; 52 const S3 ca[5]; 53 extern const int f; 54 class S4 { 55 int a; 56 S4(); 57 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}} 58 59 public: 60 S4(int v) : a(v) {} 61 }; 62 class S5 { 63 int a; 64 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}} 65 66 public: 67 S5() : a(0) {} 68 S5(int v) : a(v) {} 69 }; 70 class S6 { 71 int a; 72 S6() : a(0) {} 73 74 public: 75 S6(const S6 &s6) : a(s6.a) {} 76 S6(int v) : a(v) {} 77 }; 78 79 S3 h; 80 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} 81 82 template <class I, class C> 83 int foomain(int argc, char **argv) { 84 I e(4); 85 C g(5); 86 int i, z; 87 int &j = i; 88 #pragma omp target parallel for firstprivate // expected-error {{expected '(' after 'firstprivate'}} 89 for (int k = 0; k < argc; ++k) 90 ++k; 91 #pragma omp target parallel for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 92 for (int k = 0; k < argc; ++k) 93 ++k; 94 #pragma omp target parallel for firstprivate() // expected-error {{expected expression}} 95 for (int k = 0; k < argc; ++k) 96 ++k; 97 #pragma omp target parallel for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 98 for (int k = 0; k < argc; ++k) 99 ++k; 100 #pragma omp target parallel for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 101 for (int k = 0; k < argc; ++k) 102 ++k; 103 #pragma omp target parallel for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 104 for (int k = 0; k < argc; ++k) 105 ++k; 106 #pragma omp target parallel for 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 '('}} 107 for (int k = 0; k < argc; ++k) 108 ++k; 109 #pragma omp target parallel for firstprivate(S1) // expected-error {{'S1' does not refer to a value}} 110 for (int k = 0; k < argc; ++k) 111 ++k; 112 #pragma omp target parallel for firstprivate(z, a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} 113 for (int k = 0; k < argc; ++k) 114 ++k; 115 #pragma omp target parallel for firstprivate(argv[1]) // expected-error {{expected variable name}} 116 for (int k = 0; k < argc; ++k) 117 ++k; 118 #pragma omp target parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} 119 for (int k = 0; k < argc; ++k) 120 ++k; 121 #pragma omp target parallel for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} 122 for (int k = 0; k < argc; ++k) 123 ++k; 124 #pragma omp parallel 125 { 126 int v = 0; 127 int i; 128 #pragma omp target parallel for firstprivate(i) 129 for (int k = 0; k < argc; ++k) { 130 i = k; 131 v += i; 132 } 133 } 134 #pragma omp parallel shared(i) 135 #pragma omp parallel private(i) 136 #pragma omp target parallel for firstprivate(j) 137 for (int k = 0; k < argc; ++k) 138 ++k; 139 #pragma omp target parallel for firstprivate(i) 140 for (int k = 0; k < argc; ++k) 141 ++k; 142 #pragma omp target parallel for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} 143 for (i = 0; i < argc; ++i) 144 foo(); 145 #pragma omp parallel private(i) 146 #pragma omp target parallel for firstprivate(i) // expected-note 2 {{defined as firstprivate}} 147 for (i = 0; i < argc; ++i) // expected-error 2 {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}} 148 foo(); 149 #pragma omp parallel reduction(+ : i) 150 #pragma omp target parallel for firstprivate(i) // expected-note 2 {{defined as firstprivate}} 151 for (i = 0; i < argc; ++i) // expected-error 2 {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}} 152 foo(); 153 return 0; 154 } 155 156 namespace A { 157 double x; 158 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} 159 } 160 namespace B { 161 using A::x; 162 } 163 164 int main(int argc, char **argv) { 165 const int d = 5; 166 const int da[5] = {0}; 167 S4 e(4); 168 S5 g(5); 169 S3 m; 170 S6 n(2); 171 int i, z; 172 int &j = i; 173 #pragma omp target parallel for firstprivate // expected-error {{expected '(' after 'firstprivate'}} 174 for (i = 0; i < argc; ++i) 175 foo(); 176 #pragma omp target parallel for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 177 for (i = 0; i < argc; ++i) 178 foo(); 179 #pragma omp target parallel for firstprivate() // expected-error {{expected expression}} 180 for (i = 0; i < argc; ++i) 181 foo(); 182 #pragma omp target parallel for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 183 for (i = 0; i < argc; ++i) 184 foo(); 185 #pragma omp target parallel for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 186 for (i = 0; i < argc; ++i) 187 foo(); 188 #pragma omp target parallel for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 189 for (i = 0; i < argc; ++i) 190 foo(); 191 #pragma omp target parallel for allocate(omp_thread_mem_alloc: argc) firstprivate(argc) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'target parallel for' directive}} 192 for (i = 0; i < argc; ++i) 193 foo(); 194 #pragma omp target parallel for firstprivate(S1) // expected-error {{'S1' does not refer to a value}} 195 for (i = 0; i < argc; ++i) 196 foo(); 197 #pragma omp target parallel for firstprivate(z, a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} 198 for (i = 0; i < argc; ++i) 199 foo(); 200 #pragma omp target parallel for firstprivate(argv[1]) // expected-error {{expected variable name}} 201 for (i = 0; i < argc; ++i) 202 foo(); 203 #pragma omp target parallel for firstprivate(2 * 2) // expected-error {{expected variable name}} 204 for (i = 0; i < argc; ++i) 205 foo(); 206 #pragma omp target parallel for firstprivate(ba) // OK 207 for (i = 0; i < argc; ++i) 208 foo(); 209 #pragma omp target parallel for firstprivate(ca) // OK 210 for (i = 0; i < argc; ++i) 211 foo(); 212 #pragma omp target parallel for firstprivate(da) // OK 213 for (i = 0; i < argc; ++i) 214 foo(); 215 int xa; 216 #pragma omp target parallel for firstprivate(xa) // OK 217 for (i = 0; i < argc; ++i) 218 foo(); 219 #pragma omp target parallel for firstprivate(S2::S2s) // OK 220 for (i = 0; i < argc; ++i) 221 foo(); 222 #pragma omp target parallel for firstprivate(S2::S2sc) // OK 223 for (i = 0; i < argc; ++i) 224 foo(); 225 #pragma omp target parallel for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp target parallel for'}} 226 for (i = 0; i < argc; ++i) 227 foo(); 228 #pragma omp target parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} 229 for (i = 0; i < argc; ++i) 230 foo(); 231 #pragma omp target parallel for firstprivate(m) // OK 232 for (i = 0; i < argc; ++i) 233 foo(); 234 #pragma omp target parallel for firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}} 235 for (i = 0; i < argc; ++i) 236 foo(); 237 #pragma omp target parallel for private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}} 238 for (i = 0; i < argc; ++i) 239 foo(); 240 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}} 241 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}} 242 foo(); 243 #pragma omp parallel shared(xa) 244 #pragma omp target parallel for firstprivate(xa) // OK: may be firstprivate 245 for (i = 0; i < argc; ++i) 246 foo(); 247 #pragma omp target parallel for firstprivate(j) 248 for (i = 0; i < argc; ++i) 249 foo(); 250 #pragma omp target parallel for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} 251 for (i = 0; i < argc; ++i) 252 foo(); 253 #pragma omp target parallel for lastprivate(n) firstprivate(n) // OK 254 for (i = 0; i < argc; ++i) 255 foo(); 256 #pragma omp parallel 257 { 258 int v = 0; 259 int i; 260 #pragma omp target parallel for firstprivate(i) 261 for (int k = 0; k < argc; ++k) { 262 i = k; 263 v += i; 264 } 265 } 266 #pragma omp parallel private(i) 267 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}} 268 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}} 269 foo(); 270 #pragma omp parallel reduction(+ : i) 271 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}} 272 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}} 273 foo(); 274 static int si; 275 #pragma omp target parallel for firstprivate(si) // OK 276 for (i = 0; i < argc; ++i) 277 si = i + 1; 278 279 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}} 280 } 281