master_taskloop_simd_linear_messages.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 xxx(int argc) {
  13. int i, lin, step; // expected-note {{initialize the variable 'lin' to silence this warning}} expected-note {{initialize the variable 'step' to silence this warning}}
  14. #pragma omp master taskloop simd linear(i, lin : step) // expected-warning {{variable 'lin' is uninitialized when used here}} expected-warning {{variable 'step' is uninitialized when used here}}
  15. for (i = 0; i < 10; ++i)
  16. ;
  17. }
  18. namespace X {
  19. int x;
  20. };
  21. struct B {
  22. static int ib; // expected-note {{'B::ib' declared here}}
  23. static int bfoo() { return 8; }
  24. };
  25. int bfoo() { return 4; }
  26. int z;
  27. const int C1 = 1;
  28. const int C2 = 2;
  29. void test_linear_colons()
  30. {
  31. int B = 0;
  32. #pragma omp master taskloop simd linear(B:bfoo())
  33. for (int i = 0; i < 10; ++i) ;
  34. // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'}}
  35. #pragma omp master taskloop simd linear(B::ib:B:bfoo())
  36. for (int i = 0; i < 10; ++i) ;
  37. // expected-error@+1 {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
  38. #pragma omp master taskloop simd linear(B:ib)
  39. for (int i = 0; i < 10; ++i) ;
  40. // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'?}}
  41. #pragma omp master taskloop simd linear(z:B:ib)
  42. for (int i = 0; i < 10; ++i) ;
  43. #pragma omp master taskloop simd linear(B:B::bfoo())
  44. for (int i = 0; i < 10; ++i) ;
  45. #pragma omp master taskloop simd linear(X::x : ::z)
  46. for (int i = 0; i < 10; ++i) ;
  47. #pragma omp master taskloop simd linear(B,::z, X::x)
  48. for (int i = 0; i < 10; ++i) ;
  49. #pragma omp master taskloop simd linear(::z)
  50. for (int i = 0; i < 10; ++i) ;
  51. // expected-error@+1 {{expected variable name}}
  52. #pragma omp master taskloop simd linear(B::bfoo())
  53. for (int i = 0; i < 10; ++i) ;
  54. #pragma omp master taskloop simd linear(B::ib,B:C1+C2)
  55. for (int i = 0; i < 10; ++i) ;
  56. }
  57. template<int L, class T, class N> T test_template(T* arr, N num) {
  58. N i;
  59. T sum = (T)0;
  60. T ind2 = - num * L; // expected-note {{'ind2' defined here}}
  61. // expected-error@+1 {{argument of a linear clause should be of integral or pointer type}}
  62. #pragma omp master taskloop simd linear(ind2:L)
  63. for (i = 0; i < num; ++i) {
  64. T cur = arr[(int)ind2];
  65. ind2 += L;
  66. sum += cur;
  67. }
  68. return T();
  69. }
  70. template<int LEN> int test_warn() {
  71. int ind2 = 0;
  72. // expected-warning@+1 {{zero linear step (ind2 should probably be const)}}
  73. #pragma omp master taskloop simd linear(ind2:LEN)
  74. for (int i = 0; i < 100; i++) {
  75. ind2 += LEN;
  76. }
  77. return ind2;
  78. }
  79. struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
  80. extern S1 a;
  81. class S2 {
  82. mutable int a;
  83. public:
  84. S2():a(0) { }
  85. };
  86. const S2 b; // expected-note 2 {{'b' defined here}}
  87. const S2 ba[5];
  88. class S3 {
  89. int a;
  90. public:
  91. S3():a(0) { }
  92. };
  93. const S3 ca[5];
  94. class S4 {
  95. int a;
  96. S4();
  97. public:
  98. S4(int v):a(v) { }
  99. };
  100. class S5 {
  101. int a;
  102. S5():a(0) {}
  103. public:
  104. S5(int v):a(v) { }
  105. };
  106. S3 h;
  107. #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
  108. template<class I, class C> int foomain(I argc, C **argv) {
  109. I e(4);
  110. I g(5);
  111. int i, z;
  112. int &j = i;
  113. #pragma omp master taskloop simd linear // expected-error {{expected '(' after 'linear'}}
  114. for (int k = 0; k < argc; ++k) ++k;
  115. #pragma omp master taskloop simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
  116. for (int k = 0; k < argc; ++k) ++k;
  117. #pragma omp master taskloop simd linear (val // expected-error {{use of undeclared identifier 'val'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
  118. for (int k = 0; k < argc; ++k) ++k;
  119. #pragma omp master taskloop simd linear (uval( // expected-error {{expected expression}} expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
  120. for (int k = 0; k < argc; ++k) ++k;
  121. #pragma omp master taskloop simd linear (ref() // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
  122. for (int k = 0; k < argc; ++k) ++k;
  123. #pragma omp master taskloop simd linear (foo() // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
  124. for (int k = 0; k < argc; ++k) ++k;
  125. #pragma omp master taskloop simd linear () // expected-error {{expected expression}}
  126. for (int k = 0; k < argc; ++k) ++k;
  127. #pragma omp master taskloop simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
  128. for (int k = 0; k < argc; ++k) ++k;
  129. #pragma omp master taskloop simd linear (val argc // expected-error {{use of undeclared identifier 'val'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
  130. for (int k = 0; k < argc; ++k) ++k;
  131. #pragma omp master taskloop simd linear (val(argc, // expected-error {{expected expression}} expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
  132. for (int k = 0; k < argc; ++k) ++k;
  133. #pragma omp master taskloop simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
  134. for (int k = 0; k < argc; ++k) ++k;
  135. #pragma omp master taskloop simd linear (argc : 5) 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 '('}}
  136. for (int k = 0; k < argc; ++k) ++k;
  137. #pragma omp master taskloop simd linear (S1) // expected-error {{'S1' does not refer to a value}}
  138. for (int k = 0; k < argc; ++k) ++k;
  139. // expected-error@+2 {{linear variable with incomplete type 'S1'}}
  140. // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
  141. #pragma omp master taskloop simd linear (val(a, b):B::ib)
  142. for (int k = 0; k < argc; ++k) ++k;
  143. #pragma omp master taskloop simd linear (argv[1]) // expected-error {{expected variable name}}
  144. for (int k = 0; k < argc; ++k) ++k;
  145. #pragma omp master taskloop simd linear(ref(e, g)) // expected-error 2 {{variable of non-reference type 'int' can be used only with 'val' modifier, but used with 'ref'}}
  146. for (int k = 0; k < argc; ++k) ++k;
  147. #pragma omp master taskloop simd linear(h, z) // expected-error {{threadprivate or thread local variable cannot be linear}}
  148. for (int k = 0; k < argc; ++k) ++k;
  149. #pragma omp master taskloop simd linear(uval(i)) // expected-error {{variable of non-reference type 'int' can be used only with 'val' modifier, but used with 'uval'}}
  150. for (int k = 0; k < argc; ++k) ++k;
  151. #pragma omp parallel
  152. {
  153. int v = 0;
  154. int i;
  155. #pragma omp master taskloop simd allocate(omp_thread_mem_alloc: v) linear(v:i) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'master taskloop simd' directive}}
  156. for (int k = 0; k < argc; ++k) { i = k; v += i; }
  157. }
  158. #pragma omp master taskloop simd linear(ref(j))
  159. for (int k = 0; k < argc; ++k) ++k;
  160. #pragma omp master taskloop simd linear(uval(j))
  161. for (int k = 0; k < argc; ++k) ++k;
  162. int v = 0;
  163. #pragma omp master taskloop simd linear(v:j)
  164. for (int k = 0; k < argc; ++k) { ++k; v += j; }
  165. #pragma omp master taskloop simd linear(i)
  166. for (int k = 0; k < argc; ++k) ++k;
  167. return 0;
  168. }
  169. namespace A {
  170. double x;
  171. #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
  172. }
  173. namespace C {
  174. using A::x;
  175. }
  176. void linear_modifiers(int argc) {
  177. int &f = argc;
  178. #pragma omp master taskloop simd linear(f)
  179. for (int k = 0; k < argc; ++k) ++k;
  180. #pragma omp master taskloop simd linear(val(f))
  181. for (int k = 0; k < argc; ++k) ++k;
  182. #pragma omp master taskloop simd linear(uval(f))
  183. for (int k = 0; k < argc; ++k) ++k;
  184. #pragma omp master taskloop simd linear(ref(f))
  185. for (int k = 0; k < argc; ++k) ++k;
  186. #pragma omp master taskloop simd linear(foo(f)) // expected-error {{expected one of 'ref', val' or 'uval' modifiers}}
  187. for (int k = 0; k < argc; ++k) ++k;
  188. }
  189. int f;
  190. int main(int argc, char **argv) {
  191. double darr[100];
  192. // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
  193. test_template<-4>(darr, 4);
  194. // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
  195. test_warn<0>();
  196. S4 e(4); // expected-note {{'e' defined here}}
  197. S5 g(5); // expected-note {{'g' defined here}}
  198. int i, z;
  199. int &j = i;
  200. #pragma omp master taskloop simd linear(f) linear(f) // expected-error {{linear variable cannot be linear}} expected-note {{defined as linear}}
  201. for (int k = 0; k < argc; ++k) ++k;
  202. #pragma omp master taskloop simd linear // expected-error {{expected '(' after 'linear'}}
  203. for (int k = 0; k < argc; ++k) ++k;
  204. #pragma omp master taskloop simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
  205. for (int k = 0; k < argc; ++k) ++k;
  206. #pragma omp master taskloop simd linear () // expected-error {{expected expression}}
  207. for (int k = 0; k < argc; ++k) ++k;
  208. #pragma omp master taskloop simd linear (val // expected-error {{use of undeclared identifier 'val'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
  209. for (int k = 0; k < argc; ++k) ++k;
  210. #pragma omp master taskloop simd linear (ref()) // expected-error {{expected expression}}
  211. for (int k = 0; k < argc; ++k) ++k;
  212. #pragma omp master taskloop simd linear (foo()) // expected-error {{expected expression}}
  213. for (int k = 0; k < argc; ++k) ++k;
  214. #pragma omp master taskloop simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
  215. for (int k = 0; k < argc; ++k) ++k;
  216. #pragma omp master taskloop simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
  217. for (int k = 0; k < argc; ++k) ++k;
  218. #pragma omp master taskloop simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
  219. for (int k = 0; k < argc; ++k) ++k;
  220. #pragma omp master taskloop simd linear (argc, z)
  221. for (int k = 0; k < argc; ++k) ++k;
  222. #pragma omp master taskloop simd linear (S1) // expected-error {{'S1' does not refer to a value}}
  223. for (int k = 0; k < argc; ++k) ++k;
  224. // expected-error@+2 {{linear variable with incomplete type 'S1'}}
  225. // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
  226. #pragma omp master taskloop simd linear(a, b)
  227. for (int k = 0; k < argc; ++k) ++k;
  228. #pragma omp master taskloop simd linear (argv[1]) // expected-error {{expected variable name}}
  229. for (int k = 0; k < argc; ++k) ++k;
  230. // expected-error@+2 {{argument of a linear clause should be of integral or pointer type, not 'S4'}}
  231. // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
  232. #pragma omp master taskloop simd linear(val(e, g))
  233. for (int k = 0; k < argc; ++k) ++k;
  234. #pragma omp master taskloop simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
  235. for (int k = 0; k < argc; ++k) ++k;
  236. #pragma omp parallel
  237. {
  238. int i;
  239. #pragma omp master taskloop simd linear(val(i))
  240. for (int k = 0; k < argc; ++k) ++k;
  241. #pragma omp master taskloop simd linear(uval(i) : 4) // expected-error {{variable of non-reference type 'int' can be used only with 'val' modifier, but used with 'uval'}}
  242. for (int k = 0; k < argc; ++k) { ++k; i += 4; }
  243. }
  244. #pragma omp master taskloop simd linear(ref(j))
  245. for (int k = 0; k < argc; ++k) ++k;
  246. #pragma omp master taskloop simd linear(i)
  247. for (int k = 0; k < argc; ++k) ++k;
  248. foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
  249. return 0;
  250. }