cxx-altivec.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify -std=c++11 %s
  2. // RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -faltivec -fsyntax-only -verify -std=c++11 %s
  3. // RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -faltivec -fsyntax-only -verify -std=c++11 %s
  4. __vector char vv_c;
  5. __vector signed char vv_sc;
  6. __vector unsigned char vv_uc;
  7. __vector short vv_s;
  8. __vector signed short vv_ss;
  9. __vector unsigned short vv_us;
  10. __vector short int vv_si;
  11. __vector signed short int vv_ssi;
  12. __vector unsigned short int vv_usi;
  13. __vector int vv_i;
  14. __vector signed int vv_sint;
  15. __vector unsigned int vv_ui;
  16. __vector float vv_f;
  17. __vector bool char vv_bc;
  18. __vector bool short vv_bs;
  19. __vector bool int vv_bi;
  20. __vector __bool char vv___bc;
  21. __vector __bool short vv___bs;
  22. __vector __bool int vv___bi;
  23. __vector __pixel vv_p;
  24. __vector pixel vv__p;
  25. __vector int vf__r();
  26. void vf__a(__vector int a);
  27. void vf__a2(int b, __vector int a);
  28. vector char v_c;
  29. vector signed char v_sc;
  30. vector unsigned char v_uc;
  31. vector short v_s;
  32. vector signed short v_ss;
  33. vector unsigned short v_us;
  34. vector short int v_si;
  35. vector signed short int v_ssi;
  36. vector unsigned short int v_usi;
  37. vector int v_i;
  38. vector signed int v_sint;
  39. vector unsigned int v_ui;
  40. vector float v_f;
  41. vector bool char v_bc;
  42. vector bool short v_bs;
  43. vector bool int v_bi;
  44. vector __bool char v___bc;
  45. vector __bool short v___bs;
  46. vector __bool int v___bi;
  47. vector __pixel v_p;
  48. vector pixel v__p;
  49. vector int f__r();
  50. void f_a(vector int a);
  51. void f_a2(int b, vector int a);
  52. vector int v = (vector int)(-1);
  53. // These should have warnings.
  54. __vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  55. __vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  56. __vector unsigned long vv_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  57. __vector long int vv_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  58. __vector signed long int vv_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  59. __vector unsigned long int vv_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  60. vector long v_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  61. vector signed long v_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  62. vector unsigned long v_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  63. vector long int v_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  64. vector signed long int v_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  65. vector unsigned long int v_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
  66. __vector long double vv_ld; // expected-error {{cannot use 'long double' with '__vector'}}
  67. vector long double v_ld; // expected-error {{cannot use 'long double' with '__vector'}}
  68. // These should have errors.
  69. __vector double vv_d1; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
  70. vector double v_d2; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
  71. __vector bool long long v_bll1; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}}
  72. __vector __bool long long v_bll2; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}}
  73. vector bool long long v_bll3; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}}
  74. vector __bool long long v_bll4; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}}
  75. __vector long double vv_ld3; // expected-error {{cannot use 'long double' with '__vector'}}
  76. vector long double v_ld4; // expected-error {{cannot use 'long double' with '__vector'}}
  77. vector bool v_b; // expected-error {{C++ requires a type specifier for all declarations}}
  78. vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}}
  79. vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}}
  80. vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
  81. vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
  82. vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
  83. vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}}
  84. vector __bool float v___bf; // expected-error {{cannot use 'float' with '__vector bool'}}
  85. vector __bool double v___bd; // expected-error {{cannot use 'double' with '__vector bool'}}
  86. vector __bool pixel v___bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
  87. vector __bool signed char v___bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
  88. vector __bool unsigned int v___bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
  89. vector __bool long v___bl; // expected-error {{cannot use 'long' with '__vector bool'}}
  90. // vector long is deprecated, but vector long long is not.
  91. vector long long v_ll;
  92. vector signed long long v_sll;
  93. vector unsigned long long v_ull;
  94. void f() {
  95. __vector unsigned int v = {0,0,0,0};
  96. __vector int v__cast = (__vector int)v;
  97. __vector int v_cast = (vector int)v;
  98. __vector char vb_cast = (vector char)v;
  99. // Check some casting between gcc and altivec vectors.
  100. #define gccvector __attribute__((vector_size(16)))
  101. gccvector unsigned int gccv = {0,0,0,0};
  102. gccvector unsigned int gccv1 = gccv;
  103. gccvector int gccv2 = (gccvector int)gccv;
  104. gccvector unsigned int gccv3 = v;
  105. __vector unsigned int av = gccv;
  106. __vector int avi = (__vector int)gccv;
  107. gccvector unsigned int gv = v;
  108. gccvector int gvi = (gccvector int)v;
  109. __attribute__((vector_size(8))) unsigned int gv8;
  110. gv8 = gccv; // expected-error {{assigning to '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values) from incompatible type '__attribute__((__vector_size__(4 * sizeof(unsigned int)))) unsigned int' (vector of 4 'unsigned int' values)}}
  111. av = gv8; // expected-error {{assigning to '__vector unsigned int' (vector of 4 'unsigned int' values) from incompatible type '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values)}}
  112. v = gccv;
  113. __vector unsigned int tv = gccv;
  114. gccv = v;
  115. gccvector unsigned int tgv = v;
  116. }
  117. // Now for the C++ version:
  118. class vc__v {
  119. __vector int v;
  120. __vector int f__r();
  121. void f__a(__vector int a);
  122. void f__a2(int b, __vector int a);
  123. };
  124. class c_v {
  125. vector int v;
  126. vector int f__r();
  127. void f__a(vector int a);
  128. void f__a2(int b, vector int a);
  129. };
  130. // bug 6895 - Vectorl literal casting confusion.
  131. vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
  132. vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
  133. vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
  134. vector int v4 = (vector int)(1, 2, 3, 4);
  135. vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
  136. vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));
  137. // bug 7553 - Problem with '==' and vectors
  138. void func() {
  139. bool res_b;
  140. res_b = (vv_sc == vv_sc);
  141. res_b = (vv_uc != vv_uc);
  142. res_b = (vv_s > vv_s);
  143. res_b = (vv_us >= vv_us);
  144. res_b = (vv_i < vv_i);
  145. res_b = (vv_ui <= vv_ui);
  146. res_b = (vv_f <= vv_f);
  147. }
  148. // vecreturn attribute test
  149. struct Vector
  150. {
  151. __vector float xyzw;
  152. } __attribute__((vecreturn));
  153. Vector Add(Vector lhs, Vector rhs)
  154. {
  155. Vector result;
  156. result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
  157. return result; // This will (eventually) be returned in a register
  158. }
  159. // vecreturn attribute test - should error because of virtual function.
  160. class VectorClassNonPod
  161. {
  162. __vector float xyzw;
  163. public:
  164. VectorClassNonPod() {}
  165. virtual ~VectorClassNonPod() {}
  166. } __attribute__((vecreturn)); // expected-error {{the vecreturn attribute can only be used on a POD (plain old data) class or structure (i.e. no virtual functions)}}
  167. // vecreturn attribute test - should error because of virtual function.
  168. class VectorClassMultipleMembers
  169. {
  170. public:
  171. __vector float xyzw;
  172. __vector float abcd;
  173. } __attribute__((vecreturn)); // expected-error {{the vecreturn attribute can only be used on a class or structure with one member, which must be a vector}}
  174. template<typename... Args> void PR16874() {
  175. (void) (Args::foo()...); // expected-error {{expression contains unexpanded parameter pack 'Args'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
  176. }