[Matrix] Use 1st/2nd instead of first/second in matrix diags.

This was suggested in D72782 and brings the diagnostics more in line
with how argument references are handled elsewhere.

Reviewers: rjmccall, jfb, Bigcheese

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D82473
This commit is contained in:
Florian Hahn 2020-06-25 11:48:07 +01:00
parent 187f627a50
commit 043b608399
5 changed files with 37 additions and 35 deletions

View File

@ -10789,13 +10789,13 @@ def err_matrix_separate_incomplete_index: Error<
"matrix row and column subscripts cannot be separated by any expression">;
def err_matrix_subscript_comma: Error<
"comma expressions are not allowed as indices in matrix subscript expressions">;
def err_builtin_matrix_arg: Error<"first argument must be a matrix">;
def err_builtin_matrix_arg: Error<"1st argument must be a matrix">;
def err_builtin_matrix_scalar_unsigned_arg: Error<
"%0 argument must be a constant unsigned integer expression">;
def err_builtin_matrix_pointer_arg: Error<
"%0 argument must be a pointer to a valid matrix element type">;
"%ordinal0 argument must be a pointer to a valid matrix element type">;
def err_builtin_matrix_pointer_arg_mismatch: Error<
"the pointee of the second argument must match the element type of the first argument (%0 != %1)">;
"the pointee of the 2nd argument must match the element type of the 1st argument (%0 != %1)">;
def err_builtin_matrix_store_to_const: Error<
"cannot store matrix to read-only pointer">;
def err_builtin_matrix_stride_too_small: Error<

View File

@ -15295,7 +15295,8 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall,
if (checkArgCount(*this, TheCall, 4))
return ExprError();
Expr *PtrExpr = TheCall->getArg(0);
unsigned PtrArgIdx = 0;
Expr *PtrExpr = TheCall->getArg(PtrArgIdx);
Expr *RowsExpr = TheCall->getArg(1);
Expr *ColumnsExpr = TheCall->getArg(2);
Expr *StrideExpr = TheCall->getArg(3);
@ -15319,14 +15320,14 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall,
QualType ElementTy;
if (!PtrTy) {
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_pointer_arg)
<< "first";
<< PtrArgIdx + 1;
ArgError = true;
} else {
ElementTy = PtrTy->getPointeeType().getUnqualifiedType();
if (!ConstantMatrixType::isValidElementType(ElementTy)) {
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_pointer_arg)
<< "first";
<< PtrArgIdx + 1;
ArgError = true;
}
}
@ -15402,8 +15403,9 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall,
if (checkArgCount(*this, TheCall, 3))
return ExprError();
unsigned PtrArgIdx = 1;
Expr *MatrixExpr = TheCall->getArg(0);
Expr *PtrExpr = TheCall->getArg(1);
Expr *PtrExpr = TheCall->getArg(PtrArgIdx);
Expr *StrideExpr = TheCall->getArg(2);
bool ArgError = false;
@ -15442,7 +15444,7 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall,
auto *PtrTy = PtrExpr->getType()->getAs<PointerType>();
if (!PtrTy) {
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_pointer_arg)
<< "second";
<< PtrArgIdx + 1;
ArgError = true;
} else {
QualType ElementTy = PtrTy->getPointeeType();

View File

@ -11,11 +11,11 @@ void transpose(sx5x10_t a, ix3x2_t b, dx3x3 c, int *d, int e) {
b = __builtin_matrix_transpose(b);
// expected-error@-1 {{assigning to 'ix3x2_t' (aka 'int __attribute__((matrix_type(3, 2)))') from incompatible type 'int __attribute__((matrix_type(2, 3)))'}}
__builtin_matrix_transpose(d);
// expected-error@-1 {{first argument must be a matrix}}
// expected-error@-1 {{1st argument must be a matrix}}
__builtin_matrix_transpose(e);
// expected-error@-1 {{first argument must be a matrix}}
// expected-error@-1 {{1st argument must be a matrix}}
__builtin_matrix_transpose("test");
// expected-error@-1 {{first argument must be a matrix}}
// expected-error@-1 {{1st argument must be a matrix}}
ix3x3 m = __builtin_matrix_transpose(c);
// expected-error@-1 {{initializing 'ix3x3' (aka 'unsigned int __attribute__((matrix_type(3, 3)))') with an expression of incompatible type 'double __attribute__((matrix_type(3, 3)))'}}
@ -43,10 +43,10 @@ void column_major_load(float *p1, int *p2, _Bool *p3, struct Foo *p4) {
// expected-error@-1 {{stride must be greater or equal to the number of rows}}
sx5x10_t a8 = __builtin_matrix_column_major_load(p3, 5, 10, 6);
// expected-error@-1 {{first argument must be a pointer to a valid matrix element type}}
// expected-error@-1 {{1st argument must be a pointer to a valid matrix element type}}
sx5x10_t a9 = __builtin_matrix_column_major_load(p4, 5, 10, 6);
// expected-error@-1 {{first argument must be a pointer to a valid matrix element type}}
// expected-error@-1 {{1st argument must be a pointer to a valid matrix element type}}
sx5x10_t a10 = __builtin_matrix_column_major_load(p1, 1ull << 21, 10, 6);
// expected-error@-1 {{row dimension is outside the allowed range [1, 1048575}}
@ -54,13 +54,13 @@ void column_major_load(float *p1, int *p2, _Bool *p3, struct Foo *p4) {
// expected-error@-1 {{column dimension is outside the allowed range [1, 1048575}}
sx5x10_t a12 = __builtin_matrix_column_major_load(
10, // expected-error {{first argument must be a pointer to a valid matrix element type}}
10, // expected-error {{1st argument must be a pointer to a valid matrix element type}}
1ull << 21, // expected-error {{row dimension is outside the allowed range [1, 1048575]}}
1ull << 21, // expected-error {{column dimension is outside the allowed range [1, 1048575]}}
""); // expected-warning {{incompatible pointer to integer conversion casting 'char [1]' to type 'unsigned long'}}
sx5x10_t a13 = __builtin_matrix_column_major_load(
10, // expected-error {{first argument must be a pointer to a valid matrix element type}}
10, // expected-error {{1st argument must be a pointer to a valid matrix element type}}
*p4, // expected-error {{casting 'struct Foo' to incompatible type 'unsigned long'}}
"", // expected-error {{column argument must be a constant unsigned integer expression}}
// expected-warning@-1 {{incompatible pointer to integer conversion casting 'char [1]' to type 'unsigned long'}}
@ -73,18 +73,18 @@ void column_major_store(sx5x10_t *m1, ix3x2_t *m2, float *p1, int *p2, struct Fo
__builtin_matrix_column_major_store(*m1, p1, 0);
// expected-error@-1 {{stride must be greater or equal to the number of rows}}
__builtin_matrix_column_major_store(*m1, p2, 10);
// expected-error@-1 {{the pointee of the second argument must match the element type of the first argument ('int' != 'float')}}
// expected-error@-1 {{the pointee of the 2nd argument must match the element type of the 1st argument ('int' != 'float')}}
__builtin_matrix_column_major_store(p1, p2, 10);
// expected-error@-1 {{first argument must be a matrix}}
// expected-error@-1 {{1st argument must be a matrix}}
__builtin_matrix_column_major_store(
"", // expected-error {{first argument must be a matrix}}
10, // expected-error {{second argument must be a pointer to a valid matrix element type}}
"", // expected-error {{1st argument must be a matrix}}
10, // expected-error {{2nd argument must be a pointer to a valid matrix element type}}
*p3); // expected-error {{casting 'struct Foo' to incompatible type 'unsigned long'}}
__builtin_matrix_column_major_store(
*m1,
10, // expected-error {{second argument must be a pointer to a valid matrix element type}}
10, // expected-error {{2nd argument must be a pointer to a valid matrix element type}}
10);
*m1 = __builtin_matrix_column_major_store(*m1, p1, 10);

View File

@ -15,9 +15,9 @@ typename MyMatrix<EltTy1, R1, C1>::matrix_t transpose(MyMatrix<EltTy0, R0, C0> &
// 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 {{first argument must be a matrix}}
// expected-error@-2 {{first argument must be a matrix}}
// expected-error@-3 {{first argument must be a matrix}}
// 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)))'}}
@ -99,13 +99,13 @@ void call_column_major_load_temp(unsigned *Ptr, unsigned 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 {{first argument must be a pointer to a valid matrix element type}}
// 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 second argument must match the element type of the first argument ('float' != 'unsigned int')}}
// 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>
@ -126,14 +126,14 @@ 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 second argument must match the element type of the first argument ('float' != 'unsigned int')}}
// expected-error@-3 {{the pointee of the second argument must match the element type of the first argument ('unsigned int' != 'float')}}
// 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 second argument must match the element type of the first argument ('char' != 'unsigned int')}}
// expected-error@-2 {{the pointee of the second argument must match the element type of the first argument ('char' != 'unsigned int')}}
// expected-error@-3 {{he pointee of the second argument must match the element type of the first argument ('char' != 'float')}}
// 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) {
@ -152,9 +152,9 @@ void test_column_major_store_constexpr(unsigned *Ptr, MyMatrix<unsigned, 3, 3> &
__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 {{first argument must be a matrix}}
// expected-error@-1 {{1st argument must be a matrix}}
__builtin_matrix_column_major_store(M.value, constexpr1(), 1);
// expected-error@-1 {{second argument must be a pointer to a valid matrix element type}}
// 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}}
}
@ -162,5 +162,5 @@ void test_column_major_store_wrapper(unsigned *Ptr, MyMatrix<unsigned, 3, 3> &M,
__builtin_matrix_column_major_store(M.value, Ptr, W);
__builtin_matrix_column_major_store(W, Ptr, W);
// expected-error@-1 {{first argument must be a matrix}}
// expected-error@-1 {{1st argument must be a matrix}}
}

View File

@ -22,10 +22,10 @@ double test_dimension_mismatch(double3x3 m, MatrixValue *mv) {
double test_store(MatrixValue *mv, float *Ptr) {
__builtin_matrix_column_major_store(mv.value, Ptr, 1);
// expected-error@-1 {{the pointee of the second argument must match the element type of the first argument ('float' != 'double')}}
// expected-error@-1 {{the pointee of the 2nd argument must match the element type of the 1st argument ('float' != 'double')}}
// expected-error@-2 {{stride must be greater or equal to the number of rows}}
__builtin_matrix_column_major_store(mv.value, mv.value, mv.value);
// expected-error@-1 {{second argument must be a pointer to a valid matrix element type}}
// expected-error@-1 {{2nd argument must be a pointer to a valid matrix element type}}
// expected-error@-2 {{casting 'double4x4' (aka 'double __attribute__((matrix_type(4, 4)))') to incompatible type 'unsigned long}}
}