Skip to content

Commit

Permalink
[Matrix] Replace some err kinds with err_builtin_invalid_arg_type. (NFC)
Browse files Browse the repository at this point in the history
Replace some custom matrix diagnostic kinds with the more generic
err_builtin_invalid_arg_type introduced in D111985.

Reviewed By: aaron.ballman, erichkeane

Differential Revision: https://reviews.llvm.org/D112532
  • Loading branch information
fhahn committed Oct 26, 2021
1 parent a9a0ea9 commit d7fbad0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
7 changes: 3 additions & 4 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11304,7 +11304,9 @@ def err_builtin_launder_invalid_arg : Error<
"'__builtin_launder' is not allowed">;

def err_builtin_invalid_arg_type: Error <
"%ordinal0 argument must be a %1 (was %2)">;
"%ordinal0 argument must be a "
"%select{vector, integer or floating point type|matrix|"
"pointer to a valid matrix element type}1 (was %2)">;

def err_builtin_matrix_disabled: Error<
"matrix types extension is disabled. Pass -fenable-matrix to enable it">;
Expand All @@ -11318,11 +11320,8 @@ 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<"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<
"%ordinal0 argument must be a pointer to a valid matrix element type">;
def err_builtin_matrix_pointer_arg_mismatch: Error<
"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<
Expand Down
21 changes: 12 additions & 9 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16530,7 +16530,7 @@ static bool checkMathBuiltinElementType(Sema &S, SourceLocation Loc,
QualType Ty) {
if (!Ty->getAs<VectorType>() && !ConstantMatrixType::isValidElementType(Ty)) {
S.Diag(Loc, diag::err_builtin_invalid_arg_type)
<< 1 << "vector, integer or floating point type" << Ty;
<< 1 << /* vector, integer or float ty*/ 0 << Ty;
return true;
}
return false;
Expand Down Expand Up @@ -16578,7 +16578,8 @@ ExprResult Sema::SemaBuiltinMatrixTranspose(CallExpr *TheCall,

auto *MType = Matrix->getType()->getAs<ConstantMatrixType>();
if (!MType) {
Diag(Matrix->getBeginLoc(), diag::err_builtin_matrix_arg);
Diag(Matrix->getBeginLoc(), diag::err_builtin_invalid_arg_type)
<< 1 << /* matrix ty*/ 1 << Matrix->getType();
return ExprError();
}

Expand Down Expand Up @@ -16649,15 +16650,16 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall,
auto *PtrTy = PtrExpr->getType()->getAs<PointerType>();
QualType ElementTy;
if (!PtrTy) {
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_pointer_arg)
<< PtrArgIdx + 1;
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
<< PtrArgIdx + 1 << /*pointer to element ty*/ 2 << PtrExpr->getType();
ArgError = true;
} else {
ElementTy = PtrTy->getPointeeType().getUnqualifiedType();

if (!ConstantMatrixType::isValidElementType(ElementTy)) {
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_pointer_arg)
<< PtrArgIdx + 1;
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
<< PtrArgIdx + 1 << /* pointer to element ty*/ 2
<< PtrExpr->getType();
ArgError = true;
}
}
Expand Down Expand Up @@ -16756,7 +16758,8 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall,

auto *MatrixTy = MatrixExpr->getType()->getAs<ConstantMatrixType>();
if (!MatrixTy) {
Diag(MatrixExpr->getBeginLoc(), diag::err_builtin_matrix_arg) << 0;
Diag(MatrixExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
<< 1 << /*matrix ty */ 1 << MatrixExpr->getType();
ArgError = true;
}

Expand All @@ -16775,8 +16778,8 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall,
// Check pointer argument.
auto *PtrTy = PtrExpr->getType()->getAs<PointerType>();
if (!PtrTy) {
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_pointer_arg)
<< PtrArgIdx + 1;
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
<< PtrArgIdx + 1 << /*pointer to element ty*/ 2 << PtrExpr->getType();
ArgError = true;
} else {
QualType ElementTy = PtrTy->getPointeeType();
Expand Down

0 comments on commit d7fbad0

Please sign in to comment.