// RUN: %clang_cc1 %s -fenable-matrix -pedantic -std=c++11 -verify -triple=x86_64-apple-darwin9 template struct MyMatrix { using matrix_t = EltTy __attribute__((matrix_type(Rows, Columns))); matrix_t value; }; template typename MyMatrix::matrix_t transpose(MyMatrix &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::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::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::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 Mat1; MyMatrix Mat2; Mat1.value = *((decltype(Mat1)::matrix_t *)Ptr1); Mat1.value = transpose(Mat1); // expected-note@-1 {{in instantiation of function template specialization 'transpose' requested here}} Mat1.value = transpose(Mat2); // expected-note@-1 {{in instantiation of function template specialization 'transpose' requested here}} MyMatrix Mat3; Mat3.value = transpose(Mat2); // expected-note@-1 {{in instantiation of function template specialization 'transpose' requested here}} } template typename MyMatrix::matrix_t column_major_load(MyMatrix &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::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::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 Mat1; Mat1.value = column_major_load(Mat1, Ptr1); // expected-note@-1 {{in instantiation of function template specialization 'column_major_load' requested here}} column_major_load(Mat1, Ptr1); // expected-note@-1 {{in instantiation of function template specialization 'column_major_load' requested here}} MyMatrix Mat2; Mat1.value = column_major_load(Mat2, Ptr2); // expected-note@-1 {{in instantiation of function template specialization 'column_major_load' 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 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 void column_major_store(MyMatrix &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 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 &M1, unsigned *Ptr1, MyMatrix &M2, float *Ptr2) { column_major_store(M1, Ptr2, 10); // expected-note@-1 {{in instantiation of function template specialization 'column_major_store' requested here}} column_major_store(M2, Ptr2); // expected-note@-1 {{in instantiation of function template specialization 'column_major_store &, float *, 1U>' requested here}} } template void column_major_store(MyMatrix &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 Mat1; column_major_store(Mat1, Ptr1); // expected-note@-1 {{in instantiation of function template specialization 'column_major_store'}} column_major_store(Mat1, Ptr2); // expected-note@-1 {{in instantiation of function template specialization 'column_major_store'}} MyMatrix Mat2; column_major_store(Mat2, Ptr1); // expected-note@-1 {{in instantiation of function template specialization 'column_major_store'}} } void test_column_major_store_constexpr(unsigned *Ptr, MyMatrix &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 &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}} }