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