master_taskloop_lastprivate_messages.cpp 11 KB

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