Skip to content

Commit 043b608

Browse files
committed
[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
1 parent 187f627 commit 043b608

File tree

5 files changed

+37
-35
lines changed

5 files changed

+37
-35
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10789,13 +10789,13 @@ def err_matrix_separate_incomplete_index: Error<
1078910789
"matrix row and column subscripts cannot be separated by any expression">;
1079010790
def err_matrix_subscript_comma: Error<
1079110791
"comma expressions are not allowed as indices in matrix subscript expressions">;
10792-
def err_builtin_matrix_arg: Error<"first argument must be a matrix">;
10792+
def err_builtin_matrix_arg: Error<"1st argument must be a matrix">;
1079310793
def err_builtin_matrix_scalar_unsigned_arg: Error<
1079410794
"%0 argument must be a constant unsigned integer expression">;
1079510795
def err_builtin_matrix_pointer_arg: Error<
10796-
"%0 argument must be a pointer to a valid matrix element type">;
10796+
"%ordinal0 argument must be a pointer to a valid matrix element type">;
1079710797
def err_builtin_matrix_pointer_arg_mismatch: Error<
10798-
"the pointee of the second argument must match the element type of the first argument (%0 != %1)">;
10798+
"the pointee of the 2nd argument must match the element type of the 1st argument (%0 != %1)">;
1079910799
def err_builtin_matrix_store_to_const: Error<
1080010800
"cannot store matrix to read-only pointer">;
1080110801
def err_builtin_matrix_stride_too_small: Error<

clang/lib/Sema/SemaChecking.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15295,7 +15295,8 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall,
1529515295
if (checkArgCount(*this, TheCall, 4))
1529615296
return ExprError();
1529715297

15298-
Expr *PtrExpr = TheCall->getArg(0);
15298+
unsigned PtrArgIdx = 0;
15299+
Expr *PtrExpr = TheCall->getArg(PtrArgIdx);
1529915300
Expr *RowsExpr = TheCall->getArg(1);
1530015301
Expr *ColumnsExpr = TheCall->getArg(2);
1530115302
Expr *StrideExpr = TheCall->getArg(3);
@@ -15319,14 +15320,14 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall,
1531915320
QualType ElementTy;
1532015321
if (!PtrTy) {
1532115322
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_pointer_arg)
15322-
<< "first";
15323+
<< PtrArgIdx + 1;
1532315324
ArgError = true;
1532415325
} else {
1532515326
ElementTy = PtrTy->getPointeeType().getUnqualifiedType();
1532615327

1532715328
if (!ConstantMatrixType::isValidElementType(ElementTy)) {
1532815329
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_pointer_arg)
15329-
<< "first";
15330+
<< PtrArgIdx + 1;
1533015331
ArgError = true;
1533115332
}
1533215333
}
@@ -15402,8 +15403,9 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall,
1540215403
if (checkArgCount(*this, TheCall, 3))
1540315404
return ExprError();
1540415405

15406+
unsigned PtrArgIdx = 1;
1540515407
Expr *MatrixExpr = TheCall->getArg(0);
15406-
Expr *PtrExpr = TheCall->getArg(1);
15408+
Expr *PtrExpr = TheCall->getArg(PtrArgIdx);
1540715409
Expr *StrideExpr = TheCall->getArg(2);
1540815410

1540915411
bool ArgError = false;
@@ -15442,7 +15444,7 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall,
1544215444
auto *PtrTy = PtrExpr->getType()->getAs<PointerType>();
1544315445
if (!PtrTy) {
1544415446
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_pointer_arg)
15445-
<< "second";
15447+
<< PtrArgIdx + 1;
1544615448
ArgError = true;
1544715449
} else {
1544815450
QualType ElementTy = PtrTy->getPointeeType();

clang/test/Sema/matrix-type-builtins.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ void transpose(sx5x10_t a, ix3x2_t b, dx3x3 c, int *d, int e) {
1111
b = __builtin_matrix_transpose(b);
1212
// expected-error@-1 {{assigning to 'ix3x2_t' (aka 'int __attribute__((matrix_type(3, 2)))') from incompatible type 'int __attribute__((matrix_type(2, 3)))'}}
1313
__builtin_matrix_transpose(d);
14-
// expected-error@-1 {{first argument must be a matrix}}
14+
// expected-error@-1 {{1st argument must be a matrix}}
1515
__builtin_matrix_transpose(e);
16-
// expected-error@-1 {{first argument must be a matrix}}
16+
// expected-error@-1 {{1st argument must be a matrix}}
1717
__builtin_matrix_transpose("test");
18-
// expected-error@-1 {{first argument must be a matrix}}
18+
// expected-error@-1 {{1st argument must be a matrix}}
1919

2020
ix3x3 m = __builtin_matrix_transpose(c);
2121
// 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,24 +43,24 @@ void column_major_load(float *p1, int *p2, _Bool *p3, struct Foo *p4) {
4343
// expected-error@-1 {{stride must be greater or equal to the number of rows}}
4444

4545
sx5x10_t a8 = __builtin_matrix_column_major_load(p3, 5, 10, 6);
46-
// expected-error@-1 {{first argument must be a pointer to a valid matrix element type}}
46+
// expected-error@-1 {{1st argument must be a pointer to a valid matrix element type}}
4747

4848
sx5x10_t a9 = __builtin_matrix_column_major_load(p4, 5, 10, 6);
49-
// expected-error@-1 {{first argument must be a pointer to a valid matrix element type}}
49+
// expected-error@-1 {{1st argument must be a pointer to a valid matrix element type}}
5050

5151
sx5x10_t a10 = __builtin_matrix_column_major_load(p1, 1ull << 21, 10, 6);
5252
// expected-error@-1 {{row dimension is outside the allowed range [1, 1048575}}
5353
sx5x10_t a11 = __builtin_matrix_column_major_load(p1, 10, 1ull << 21, 10);
5454
// expected-error@-1 {{column dimension is outside the allowed range [1, 1048575}}
5555

5656
sx5x10_t a12 = __builtin_matrix_column_major_load(
57-
10, // expected-error {{first argument must be a pointer to a valid matrix element type}}
57+
10, // expected-error {{1st argument must be a pointer to a valid matrix element type}}
5858
1ull << 21, // expected-error {{row dimension is outside the allowed range [1, 1048575]}}
5959
1ull << 21, // expected-error {{column dimension is outside the allowed range [1, 1048575]}}
6060
""); // expected-warning {{incompatible pointer to integer conversion casting 'char [1]' to type 'unsigned long'}}
6161

6262
sx5x10_t a13 = __builtin_matrix_column_major_load(
63-
10, // expected-error {{first argument must be a pointer to a valid matrix element type}}
63+
10, // expected-error {{1st argument must be a pointer to a valid matrix element type}}
6464
*p4, // expected-error {{casting 'struct Foo' to incompatible type 'unsigned long'}}
6565
"", // expected-error {{column argument must be a constant unsigned integer expression}}
6666
// 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
7373
__builtin_matrix_column_major_store(*m1, p1, 0);
7474
// expected-error@-1 {{stride must be greater or equal to the number of rows}}
7575
__builtin_matrix_column_major_store(*m1, p2, 10);
76-
// expected-error@-1 {{the pointee of the second argument must match the element type of the first argument ('int' != 'float')}}
76+
// expected-error@-1 {{the pointee of the 2nd argument must match the element type of the 1st argument ('int' != 'float')}}
7777
__builtin_matrix_column_major_store(p1, p2, 10);
78-
// expected-error@-1 {{first argument must be a matrix}}
78+
// expected-error@-1 {{1st argument must be a matrix}}
7979

8080
__builtin_matrix_column_major_store(
81-
"", // expected-error {{first argument must be a matrix}}
82-
10, // expected-error {{second argument must be a pointer to a valid matrix element type}}
81+
"", // expected-error {{1st argument must be a matrix}}
82+
10, // expected-error {{2nd argument must be a pointer to a valid matrix element type}}
8383
*p3); // expected-error {{casting 'struct Foo' to incompatible type 'unsigned long'}}
8484

8585
__builtin_matrix_column_major_store(
8686
*m1,
87-
10, // expected-error {{second argument must be a pointer to a valid matrix element type}}
87+
10, // expected-error {{2nd argument must be a pointer to a valid matrix element type}}
8888
10);
8989

9090
*m1 = __builtin_matrix_column_major_store(*m1, p1, 10);

clang/test/SemaCXX/matrix-type-builtins.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ typename MyMatrix<EltTy1, R1, C1>::matrix_t transpose(MyMatrix<EltTy0, R0, C0> &
1515
// expected-error@-3 {{cannot initialize a variable of type 'char *' with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 3)))'}}
1616

1717
__builtin_matrix_transpose(A);
18-
// expected-error@-1 {{first argument must be a matrix}}
19-
// expected-error@-2 {{first argument must be a matrix}}
20-
// expected-error@-3 {{first argument must be a matrix}}
18+
// expected-error@-1 {{1st argument must be a matrix}}
19+
// expected-error@-2 {{1st argument must be a matrix}}
20+
// expected-error@-3 {{1st argument must be a matrix}}
2121

2222
return __builtin_matrix_transpose(A.value);
2323
// 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) {
9999
// expected-error@-1 {{row argument must be a constant unsigned integer expression}}
100100
// expected-error@-2 {{column argument must be a constant unsigned integer expression}}
101101
(void)__builtin_matrix_column_major_load(X, 2, 2, 2);
102-
// expected-error@-1 {{first argument must be a pointer to a valid matrix element type}}
102+
// expected-error@-1 {{1st argument must be a pointer to a valid matrix element type}}
103103
}
104104

105105
template <typename EltTy0, unsigned R0, unsigned C0, typename PtrTy>
106106
void column_major_store(MyMatrix<EltTy0, R0, C0> &A, PtrTy Ptr, unsigned Stride) {
107107
__builtin_matrix_column_major_store(A.value, Ptr, Stride);
108-
// expected-error@-1 {{the pointee of the second argument must match the element type of the first argument ('float' != 'unsigned int')}}
108+
// expected-error@-1 {{the pointee of the 2nd argument must match the element type of the 1st argument ('float' != 'unsigned int')}}
109109
}
110110

111111
template <typename MTy, typename PtrTy, unsigned Stride>
@@ -126,14 +126,14 @@ template <typename EltTy0, unsigned R0, unsigned C0, typename EltTy1>
126126
void column_major_store(MyMatrix<EltTy0, R0, C0> &A, EltTy1 *Ptr) {
127127
__builtin_matrix_column_major_store(A.value, Ptr, 1);
128128
// expected-error@-1 3 {{stride must be greater or equal to the number of rows}}
129-
// expected-error@-2 {{the pointee of the second argument must match the element type of the first argument ('float' != 'unsigned int')}}
130-
// expected-error@-3 {{the pointee of the second argument must match the element type of the first argument ('unsigned int' != 'float')}}
129+
// expected-error@-2 {{the pointee of the 2nd argument must match the element type of the 1st argument ('float' != 'unsigned int')}}
130+
// expected-error@-3 {{the pointee of the 2nd argument must match the element type of the 1st argument ('unsigned int' != 'float')}}
131131

132132
char *s;
133133
return __builtin_matrix_column_major_store(A.value, s, 20);
134-
// expected-error@-1 {{the pointee of the second argument must match the element type of the first argument ('char' != 'unsigned int')}}
135-
// expected-error@-2 {{the pointee of the second argument must match the element type of the first argument ('char' != 'unsigned int')}}
136-
// expected-error@-3 {{he pointee of the second argument must match the element type of the first argument ('char' != 'float')}}
134+
// expected-error@-1 {{the pointee of the 2nd argument must match the element type of the 1st argument ('char' != 'unsigned int')}}
135+
// expected-error@-2 {{the pointee of the 2nd argument must match the element type of the 1st argument ('char' != 'unsigned int')}}
136+
// expected-error@-3 {{he pointee of the 2nd argument must match the element type of the 1st argument ('char' != 'float')}}
137137
}
138138

139139
void test_column_major_store_template(unsigned *Ptr1, float *Ptr2) {
@@ -152,15 +152,15 @@ void test_column_major_store_constexpr(unsigned *Ptr, MyMatrix<unsigned, 3, 3> &
152152
__builtin_matrix_column_major_store(M.value, Ptr, constexpr1());
153153
// expected-error@-1 {{stride must be greater or equal to the number of rows}}
154154
__builtin_matrix_column_major_store(constexpr1(), Ptr, 1);
155-
// expected-error@-1 {{first argument must be a matrix}}
155+
// expected-error@-1 {{1st argument must be a matrix}}
156156
__builtin_matrix_column_major_store(M.value, constexpr1(), 1);
157-
// expected-error@-1 {{second argument must be a pointer to a valid matrix element type}}
157+
// expected-error@-1 {{2nd argument must be a pointer to a valid matrix element type}}
158158
// expected-error@-2 {{stride must be greater or equal to the number of rows}}
159159
}
160160

161161
void test_column_major_store_wrapper(unsigned *Ptr, MyMatrix<unsigned, 3, 3> &M, IntWrapper &W) {
162162
__builtin_matrix_column_major_store(M.value, Ptr, W);
163163

164164
__builtin_matrix_column_major_store(W, Ptr, W);
165-
// expected-error@-1 {{first argument must be a matrix}}
165+
// expected-error@-1 {{1st argument must be a matrix}}
166166
}

clang/test/SemaObjC/matrix-type-builtins.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ void test_element_type_mismatch(u4x4 m, MatrixValue *mv) {
2222

2323
double test_store(MatrixValue *mv, float *Ptr) {
2424
__builtin_matrix_column_major_store(mv.value, Ptr, 1);
25-
// expected-error@-1 {{the pointee of the second argument must match the element type of the first argument ('float' != 'double')}}
25+
// expected-error@-1 {{the pointee of the 2nd argument must match the element type of the 1st argument ('float' != 'double')}}
2626
// expected-error@-2 {{stride must be greater or equal to the number of rows}}
2727

2828
__builtin_matrix_column_major_store(mv.value, mv.value, mv.value);
29-
// expected-error@-1 {{second argument must be a pointer to a valid matrix element type}}
29+
// expected-error@-1 {{2nd argument must be a pointer to a valid matrix element type}}
3030
// expected-error@-2 {{casting 'double4x4' (aka 'double __attribute__((matrix_type(4, 4)))') to incompatible type 'unsigned long}}
3131
}

0 commit comments

Comments
 (0)