Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 2 | template<typename T, unsigned Length> |
| 3 | struct make1 { |
| 4 | typedef T __attribute__((ext_vector_type(Length))) type; |
| 5 | }; |
| 6 | |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 7 | void test_make1() { |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 8 | make1<int, 5>::type x; |
| 9 | x.x = 4; |
| 10 | } |
| 11 | |
| 12 | template<typename T, unsigned Length> |
| 13 | struct make2 { |
| 14 | typedef T __attribute__((ext_vector_type(Length))) type; // expected-error{{zero vector size}} |
| 15 | }; |
| 16 | |
| 17 | int test_make2() { |
| 18 | make2<int, 0> x; // expected-note{{in instantiation of}} |
| 19 | } |
| 20 | |
| 21 | template<typename T, unsigned Length> |
| 22 | struct make3 { |
Douglas Gregor | 27cac99 | 2010-06-30 17:30:41 +0000 | [diff] [blame] | 23 | typedef T __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector element type 's'}} |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | struct s {}; |
| 27 | |
| 28 | int test_make3() { |
| 29 | make3<s, 3>x; // expected-note{{in instantiation of}} |
| 30 | } |
| 31 | |
| 32 | template<typename T, T Length> |
| 33 | struct make4 { |
| 34 | typedef T __attribute__((ext_vector_type(Length))) type; |
| 35 | }; |
| 36 | |
| 37 | int test_make4() { |
| 38 | make4<int, 4>::type x; |
| 39 | x.w = 7; |
| 40 | } |
| 41 | |
| 42 | typedef int* int_ptr; |
| 43 | template<unsigned Length> |
| 44 | struct make5 { |
Douglas Gregor | 27cac99 | 2010-06-30 17:30:41 +0000 | [diff] [blame] | 45 | typedef int_ptr __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector element type}} |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 48 | template<int Length> |
| 49 | struct make6 { |
| 50 | typedef int __attribute__((ext_vector_type(Length))) type; |
| 51 | }; |
| 52 | |
| 53 | int test_make6() { |
| 54 | make6<4>::type x; |
| 55 | x.w = 7; |
| 56 | |
| 57 | make6<2>::type y; |
| 58 | y.x = -1; |
| 59 | y.w = -1; // expected-error{{vector component access exceeds type}} |
| 60 | } |
Douglas Gregor | 4ac0140 | 2011-06-15 16:02:29 +0000 | [diff] [blame] | 61 | |
| 62 | namespace Deduction { |
| 63 | template<typename T> struct X0; |
| 64 | |
| 65 | template<typename T, unsigned N> |
| 66 | struct X0<T __attribute__((ext_vector_type(N)))> { |
| 67 | static const unsigned value = 0; |
| 68 | }; |
| 69 | |
| 70 | template<typename T> |
| 71 | struct X0<T __attribute__((ext_vector_type(4)))> { |
| 72 | static const unsigned value = 1; |
| 73 | }; |
| 74 | |
| 75 | template<unsigned N> |
| 76 | struct X0<float __attribute__((ext_vector_type(N)))> { |
| 77 | static const unsigned value = 2; |
| 78 | }; |
| 79 | |
| 80 | template<> |
| 81 | struct X0<float __attribute__((ext_vector_type(4)))> { |
| 82 | static const unsigned value = 3; |
| 83 | }; |
| 84 | |
| 85 | typedef int __attribute__((ext_vector_type(2))) int2; |
| 86 | typedef int __attribute__((ext_vector_type(4))) int4; |
| 87 | typedef float __attribute__((ext_vector_type(2))) float2; |
| 88 | typedef float __attribute__((ext_vector_type(4))) float4; |
| 89 | |
| 90 | int array0[X0<int2>::value == 0? 1 : -1]; |
| 91 | int array1[X0<int4>::value == 1? 1 : -1]; |
| 92 | int array2[X0<float2>::value == 2? 1 : -1]; |
| 93 | int array3[X0<float4>::value == 3? 1 : -1]; |
| 94 | } |