1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
// RUN: %clang_cc1 %s -fenable-matrix -pedantic -std=c++11 -verify -triple=x86_64-apple-darwin9
template <typename EltTy, unsigned Rows, unsigned Columns>
struct MyMatrix {
using matrix_t = EltTy __attribute__((matrix_type(Rows, Columns)));
matrix_t value;
};
template <typename EltTy0, unsigned R0, unsigned C0, typename EltTy1, unsigned R1, unsigned C1>
typename MyMatrix<EltTy1, R1, C1>::matrix_t transpose(MyMatrix<EltTy0, R0, C0> &A) {
char *v1 = __builtin_matrix_transpose(A.value);
// expected-error@-1 {{cannot initialize a variable of type 'char *' with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 2)))'}}
// expected-error@-2 {{cannot initialize a variable of type 'char *' with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 3)))'}}
// expected-error@-3 {{cannot initialize a variable of type 'char *' with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 3)))'}}
__builtin_matrix_transpose(A);
// expected-error@-1 {{1st argument must be a matrix}}
// expected-error@-2 {{1st argument must be a matrix}}
// expected-error@-3 {{1st argument must be a matrix}}
return __builtin_matrix_transpose(A.value);
// expected-error@-1 {{cannot initialize return object of type 'typename MyMatrix<unsigned int, 2U, 3U>::matrix_t' (aka 'unsigned int __attribute__((matrix_type(2, 3)))') with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 2)))'}}
// expected-error@-2 {{cannot initialize return object of type 'typename MyMatrix<unsigned int, 2U, 3U>::matrix_t' (aka 'unsigned int __attribute__((matrix_type(2, 3)))') with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 3)))'}}
// expected-error@-3 {{cannot initialize return object of type 'typename MyMatrix<float, 3U, 3U>::matrix_t' (aka 'float __attribute__((matrix_type(3, 3)))') with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 3)))'}}
}
void test_transpose_template(unsigned *Ptr1, float *Ptr2) {
MyMatrix<unsigned, 2, 3> Mat1;
MyMatrix<unsigned, 3, 3> Mat2;
Mat1.value = *((decltype(Mat1)::matrix_t *)Ptr1);
Mat1.value = transpose<unsigned, 2, 3, unsigned, 2, 3>(Mat1);
// expected-note@-1 {{in instantiation of function template specialization 'transpose<unsigned int, 2U, 3U, unsigned int, 2U, 3U>' requested here}}
Mat1.value = transpose<unsigned, 3, 3, unsigned, 2, 3>(Mat2);
// expected-note@-1 {{in instantiation of function template specialization 'transpose<unsigned int, 3U, 3U, unsigned int, 2U, 3U>' requested here}}
MyMatrix<float, 3, 3> Mat3;
Mat3.value = transpose<unsigned, 3, 3, float, 3, 3>(Mat2);
// expected-note@-1 {{in instantiation of function template specialization 'transpose<unsigned int, 3U, 3U, float, 3U, 3U>' requested here}}
}
template <typename EltTy0, unsigned R0, unsigned C0, typename EltTy1, unsigned R1, unsigned C1>
typename MyMatrix<EltTy1, R1, C1>::matrix_t column_major_load(MyMatrix<EltTy0, R0, C0> &A, EltTy0 *Ptr) {
char *v1 = __builtin_matrix_column_major_load(Ptr, 9, 4, 10);
// expected-error@-1 {{cannot initialize a variable of type 'char *' with an rvalue of type 'unsigned int __attribute__((matrix_type(9, 4)))'}}
// expected-error@-2 {{cannot initialize a variable of type 'char *' with an rvalue of type 'unsigned int __attribute__((matrix_type(9, 4)))'}}
// expected-error@-3 {{cannot initialize a variable of type 'char *' with an rvalue of type 'float __attribute__((matrix_type(9, 4)))'}}
return __builtin_matrix_column_major_load(Ptr, R0, C0, R0);
// expected-error@-1 {{cannot initialize return object of type 'typename MyMatrix<unsigned int, 5U, 5U>::matrix_t' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') with an rvalue of type 'unsigned int __attribute__((matrix_type(2, 3)))'}}
// expected-error@-2 {{cannot initialize return object of type 'typename MyMatrix<unsigned int, 2U, 3U>::matrix_t' (aka 'unsigned int __attribute__((matrix_type(2, 3)))') with an rvalue of type 'float __attribute__((matrix_type(2, 3)))'}}
}
void test_column_major_loads_template(unsigned *Ptr1, float *Ptr2) {
MyMatrix<unsigned, 2, 3> Mat1;
Mat1.value = column_major_load<unsigned, 2, 3, unsigned, 2, 3>(Mat1, Ptr1);
// expected-note@-1 {{in instantiation of function template specialization 'column_major_load<unsigned int, 2U, 3U, unsigned int, 2U, 3U>' requested here}}
column_major_load<unsigned, 2, 3, unsigned, 5, 5>(Mat1, Ptr1);
// expected-note@-1 {{in instantiation of function template specialization 'column_major_load<unsigned int, 2U, 3U, unsigned int, 5U, 5U>' requested here}}
MyMatrix<float, 2, 3> Mat2;
Mat1.value = column_major_load<float, 2, 3, unsigned, 2, 3>(Mat2, Ptr2);
// expected-note@-1 {{in instantiation of function template specialization 'column_major_load<float, 2U, 3U, unsigned int, 2U, 3U>' requested here}}
}
constexpr int constexpr1() { return 1; }
constexpr int constexpr_neg1() { return -1; }
void test_column_major_load_constexpr(unsigned *Ptr) {
(void)__builtin_matrix_column_major_load(Ptr, 2, 2, constexpr1());
// expected-error@-1 {{stride must be greater or equal to the number of rows}}
(void)__builtin_matrix_column_major_load(Ptr, constexpr_neg1(), 2, 4);
// expected-error@-1 {{row dimension is outside the allowed range [1, 1048575]}}
(void)__builtin_matrix_column_major_load(Ptr, 2, constexpr_neg1(), 4);
// expected-error@-1 {{column dimension is outside the allowed range [1, 1048575]}}
}
struct IntWrapper {
operator int() {
return 1;
}
};
void test_column_major_load_wrapper(unsigned *Ptr, IntWrapper &W) {
(void)__builtin_matrix_column_major_load(Ptr, W, 2, 2);
// expected-error@-1 {{row argument must be a constant unsigned integer expression}}
(void)__builtin_matrix_column_major_load(Ptr, 2, W, 2);
// expected-error@-1 {{column argument must be a constant unsigned integer expression}}
}
template <typename T, unsigned R, unsigned C, unsigned S>
void test_column_major_load_temp(T Ptr) {
(void)__builtin_matrix_column_major_load(Ptr, R, C, S);
}
void call_column_major_load_temp(unsigned *Ptr, unsigned X) {
(void)__builtin_matrix_column_major_load(Ptr, X, X, X);
// expected-error@-1 {{row argument must be a constant unsigned integer expression}}
// expected-error@-2 {{column argument must be a constant unsigned integer expression}}
(void)__builtin_matrix_column_major_load(X, 2, 2, 2);
// expected-error@-1 {{1st argument must be a pointer to a valid matrix element type}}
}
template <typename EltTy0, unsigned R0, unsigned C0, typename PtrTy>
void column_major_store(MyMatrix<EltTy0, R0, C0> &A, PtrTy Ptr, unsigned Stride) {
__builtin_matrix_column_major_store(A.value, Ptr, Stride);
// expected-error@-1 {{the pointee of the 2nd argument must match the element type of the 1st argument ('float' != 'unsigned int')}}
}
template <typename MTy, typename PtrTy, unsigned Stride>
void column_major_store(MTy &A, PtrTy Ptr) {
__builtin_matrix_column_major_store(A.value, Ptr, Stride);
// expected-error@-1 {{stride must be greater or equal to the number of rows}}
}
void test_column_major_stores_template(MyMatrix<unsigned, 2, 3> &M1, unsigned *Ptr1, MyMatrix<float, 3, 4> &M2, float *Ptr2) {
column_major_store(M1, Ptr2, 10);
// expected-note@-1 {{in instantiation of function template specialization 'column_major_store<unsigned int, 2U, 3U, float *>' requested here}}
column_major_store<decltype(M2), float *, 1>(M2, Ptr2);
// expected-note@-1 {{in instantiation of function template specialization 'column_major_store<MyMatrix<float, 3, 4> &, float *, 1U>' requested here}}
}
template <typename EltTy0, unsigned R0, unsigned C0, typename EltTy1>
void column_major_store(MyMatrix<EltTy0, R0, C0> &A, EltTy1 *Ptr) {
__builtin_matrix_column_major_store(A.value, Ptr, 1);
// expected-error@-1 3 {{stride must be greater or equal to the number of rows}}
// expected-error@-2 {{the pointee of the 2nd argument must match the element type of the 1st argument ('float' != 'unsigned int')}}
// expected-error@-3 {{the pointee of the 2nd argument must match the element type of the 1st argument ('unsigned int' != 'float')}}
char *s;
return __builtin_matrix_column_major_store(A.value, s, 20);
// expected-error@-1 {{the pointee of the 2nd argument must match the element type of the 1st argument ('char' != 'unsigned int')}}
// expected-error@-2 {{the pointee of the 2nd argument must match the element type of the 1st argument ('char' != 'unsigned int')}}
// expected-error@-3 {{he pointee of the 2nd argument must match the element type of the 1st argument ('char' != 'float')}}
}
void test_column_major_store_template(unsigned *Ptr1, float *Ptr2) {
MyMatrix<unsigned, 2, 3> Mat1;
column_major_store<unsigned, 2, 3, unsigned>(Mat1, Ptr1);
// expected-note@-1 {{in instantiation of function template specialization 'column_major_store<unsigned int, 2U, 3U, unsigned int>'}}
column_major_store<unsigned, 2, 3, float>(Mat1, Ptr2);
// expected-note@-1 {{in instantiation of function template specialization 'column_major_store<unsigned int, 2U, 3U, float>'}}
MyMatrix<float, 2, 3> Mat2;
column_major_store<float, 2, 3, unsigned>(Mat2, Ptr1);
// expected-note@-1 {{in instantiation of function template specialization 'column_major_store<float, 2U, 3U, unsigned int>'}}
}
void test_column_major_store_constexpr(unsigned *Ptr, MyMatrix<unsigned, 3, 3> &M) {
__builtin_matrix_column_major_store(M.value, Ptr, constexpr1());
// expected-error@-1 {{stride must be greater or equal to the number of rows}}
__builtin_matrix_column_major_store(constexpr1(), Ptr, 1);
// expected-error@-1 {{1st argument must be a matrix}}
__builtin_matrix_column_major_store(M.value, constexpr1(), 1);
// expected-error@-1 {{2nd argument must be a pointer to a valid matrix element type}}
// expected-error@-2 {{stride must be greater or equal to the number of rows}}
}
void test_column_major_store_wrapper(unsigned *Ptr, MyMatrix<unsigned, 3, 3> &M, IntWrapper &W) {
__builtin_matrix_column_major_store(M.value, Ptr, W);
__builtin_matrix_column_major_store(W, Ptr, W);
// expected-error@-1 {{1st argument must be a matrix}}
}
|