master_taskloop_firstprivate_messages.cpp 13 KB

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