Skip to content

Commit e27f326

Browse files
committed
[clang] Unify and refactor error formatting
1 parent be94ac2 commit e27f326

23 files changed

+274
-265
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12416,17 +12416,13 @@ def err_builtin_is_within_lifetime_invalid_arg : Error<
1241612416
"%select{non-|function }0pointer argument to '__builtin_is_within_lifetime' "
1241712417
"is not allowed">;
1241812418

12419-
def err_builtin_invalid_arg_type: Error <
12420-
"%ordinal0 argument must be "
12421-
"%select{a vector, integer or floating point type|a matrix|"
12422-
"a pointer to a valid matrix element type|"
12423-
"a signed integer or floating point type|a vector type|"
12424-
"a floating point type|"
12425-
"a vector of integers|"
12426-
"an unsigned integer|"
12427-
"an 'int'|"
12428-
"a vector of floating points|"
12429-
"an integer or vector of integers}1 (was %2)">;
12419+
def err_builtin_invalid_arg_type: Error<
12420+
"%ordinal0 argument must be a"
12421+
"%select{| scalar| vector| vector,| vector of| scalar or vector of}1"
12422+
"%select{| integer| signed integer| unsigned integer| 'int'|"
12423+
" matrix| pointer to a valid matrix element}2"
12424+
"%plural{0:|:%plural{0:|: or}2}3"
12425+
"%select{| floating-point}3 %plural{[0,3]:type|:types}1 (was %4)">;
1243012426

1243112427
def err_builtin_matrix_disabled: Error<
1243212428
"matrix types extension is disabled. Pass -fenable-matrix to enable it">;

clang/lib/Sema/SemaChecking.cpp

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,25 +1983,29 @@ checkMathBuiltinElementType(Sema &S, SourceLocation Loc, QualType ArgTy,
19831983
if (!ArgTy->getAs<VectorType>() &&
19841984
!ConstantMatrixType::isValidElementType(ArgTy)) {
19851985
return S.Diag(Loc, diag::err_builtin_invalid_arg_type)
1986-
<< ArgOrdinal << /* vector, integer or float ty*/ 0 << ArgTy;
1986+
<< ArgOrdinal << /* vector, */ 3 << /* integer */ 1 << /* fp */ 1
1987+
<< ArgTy;
19871988
}
19881989
break;
19891990
case Sema::EltwiseBuiltinArgTyRestriction::FloatTy:
19901991
if (!EltTy->isRealFloatingType()) {
19911992
return S.Diag(Loc, diag::err_builtin_invalid_arg_type)
1992-
<< ArgOrdinal << /* vector or float ty*/ 5 << ArgTy;
1993+
<< ArgOrdinal << /* scalar or vector */ 5 << /* no int */ 0
1994+
<< /* floating-point */ 1 << ArgTy;
19931995
}
19941996
break;
19951997
case Sema::EltwiseBuiltinArgTyRestriction::IntegerTy:
19961998
if (!EltTy->isIntegerType()) {
19971999
return S.Diag(Loc, diag::err_builtin_invalid_arg_type)
1998-
<< ArgOrdinal << /* vector or int ty*/ 10 << ArgTy;
2000+
<< ArgOrdinal << /* scalar or vector */ 5 << /* integer */ 1
2001+
<< /* no fp */ 0 << ArgTy;
19992002
}
20002003
break;
20012004
case Sema::EltwiseBuiltinArgTyRestriction::SignedIntOrFloatTy:
20022005
if (EltTy->isUnsignedIntegerType()) {
20032006
return S.Diag(Loc, diag::err_builtin_invalid_arg_type)
2004-
<< 1 << /* signed integer or float ty*/ 3 << ArgTy;
2007+
<< 1 << /* scalar or vector */ 5 << /* signed int */ 2
2008+
<< /* or fp */ 1 << ArgTy;
20052009
}
20062010
break;
20072011
}
@@ -2071,7 +2075,8 @@ static bool BuiltinPopcountg(Sema &S, CallExpr *TheCall) {
20712075

20722076
if (!ArgTy->isUnsignedIntegerType()) {
20732077
S.Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2074-
<< 1 << /*unsigned integer ty*/ 7 << ArgTy;
2078+
<< 1 << /* scalar */ 1 << /* unsigned integer ty */ 3 << /* no fp */ 0
2079+
<< ArgTy;
20752080
return true;
20762081
}
20772082
return false;
@@ -2095,7 +2100,8 @@ static bool BuiltinCountZeroBitsGeneric(Sema &S, CallExpr *TheCall) {
20952100

20962101
if (!Arg0Ty->isUnsignedIntegerType()) {
20972102
S.Diag(Arg0->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2098-
<< 1 << /*unsigned integer ty*/ 7 << Arg0Ty;
2103+
<< 1 << /* scalar */ 1 << /* unsigned integer ty */ 3 << /* no fp */ 0
2104+
<< Arg0Ty;
20992105
return true;
21002106
}
21012107

@@ -2111,7 +2117,7 @@ static bool BuiltinCountZeroBitsGeneric(Sema &S, CallExpr *TheCall) {
21112117

21122118
if (!Arg1Ty->isSpecificBuiltinType(BuiltinType::Int)) {
21132119
S.Diag(Arg1->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2114-
<< 2 << /*'int' ty*/ 8 << Arg1Ty;
2120+
<< 2 << /* scalar */ 1 << /* 'int' ty */ 4 << /* no fp */ 0 << Arg1Ty;
21152121
return true;
21162122
}
21172123
}
@@ -2826,7 +2832,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
28262832

28272833
if (ElTy.isNull()) {
28282834
Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2829-
<< 1 << /* vector ty*/ 4 << Arg->getType();
2835+
<< 1 << /* vector ty */ 2 << /* no int */ 0 << /* no fp */ 0
2836+
<< Arg->getType();
28302837
return ExprError();
28312838
}
28322839

@@ -2849,7 +2856,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
28492856

28502857
if (ElTy.isNull() || !ElTy->isFloatingType()) {
28512858
Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2852-
<< 1 << /* vector of floating points */ 9 << Arg->getType();
2859+
<< 1 << /* vector of */ 4 << /* no int */ 0 << /* fp */ 1
2860+
<< Arg->getType();
28532861
return ExprError();
28542862
}
28552863

@@ -2878,7 +2886,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
28782886

28792887
if (ElTy.isNull() || !ElTy->isIntegerType()) {
28802888
Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2881-
<< 1 << /* vector of integers */ 6 << Arg->getType();
2889+
<< 1 << /* vector of */ 4 << /* int */ 1 << /* no fp */ 0
2890+
<< Arg->getType();
28822891
return ExprError();
28832892
}
28842893

@@ -14789,8 +14798,9 @@ bool Sema::BuiltinNonDeterministicValue(CallExpr *TheCall) {
1478914798
QualType TyArg = Arg.get()->getType();
1479014799

1479114800
if (!TyArg->isBuiltinType() && !TyArg->isVectorType())
14792-
return Diag(TheCall->getArg(0)->getBeginLoc(), diag::err_builtin_invalid_arg_type)
14793-
<< 1 << /*vector, integer or floating point ty*/ 0 << TyArg;
14801+
return Diag(TheCall->getArg(0)->getBeginLoc(),
14802+
diag::err_builtin_invalid_arg_type)
14803+
<< 1 << /* vector, */ 3 << /* integer */ 1 << /* fp */ 1 << TyArg;
1479414804

1479514805
TheCall->setType(TyArg);
1479614806
return false;
@@ -14809,7 +14819,7 @@ ExprResult Sema::BuiltinMatrixTranspose(CallExpr *TheCall,
1480914819
auto *MType = Matrix->getType()->getAs<ConstantMatrixType>();
1481014820
if (!MType) {
1481114821
Diag(Matrix->getBeginLoc(), diag::err_builtin_invalid_arg_type)
14812-
<< 1 << /* matrix ty*/ 1 << Matrix->getType();
14822+
<< 1 << 0 << /* matrix ty */ 5 << /* no fp */ 0 << Matrix->getType();
1481314823
return ExprError();
1481414824
}
1481514825

@@ -14881,15 +14891,16 @@ ExprResult Sema::BuiltinMatrixColumnMajorLoad(CallExpr *TheCall,
1488114891
QualType ElementTy;
1488214892
if (!PtrTy) {
1488314893
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
14884-
<< PtrArgIdx + 1 << /*pointer to element ty*/ 2 << PtrExpr->getType();
14894+
<< PtrArgIdx + 1 << 0 << /* pointer to element ty */ 6 << /* no fp */ 0
14895+
<< PtrExpr->getType();
1488514896
ArgError = true;
1488614897
} else {
1488714898
ElementTy = PtrTy->getPointeeType().getUnqualifiedType();
1488814899

1488914900
if (!ConstantMatrixType::isValidElementType(ElementTy)) {
1489014901
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
14891-
<< PtrArgIdx + 1 << /* pointer to element ty*/ 2
14892-
<< PtrExpr->getType();
14902+
<< PtrArgIdx + 1 << 0 << /* pointer to element ty */ 6
14903+
<< /* no fp */ 0 << PtrExpr->getType();
1489314904
ArgError = true;
1489414905
}
1489514906
}
@@ -14989,7 +15000,7 @@ ExprResult Sema::BuiltinMatrixColumnMajorStore(CallExpr *TheCall,
1498915000
auto *MatrixTy = MatrixExpr->getType()->getAs<ConstantMatrixType>();
1499015001
if (!MatrixTy) {
1499115002
Diag(MatrixExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
14992-
<< 1 << /*matrix ty */ 1 << MatrixExpr->getType();
15003+
<< 1 << 0 << /* matrix ty */ 5 << 0 << MatrixExpr->getType();
1499315004
ArgError = true;
1499415005
}
1499515006

@@ -15009,7 +15020,8 @@ ExprResult Sema::BuiltinMatrixColumnMajorStore(CallExpr *TheCall,
1500915020
auto *PtrTy = PtrExpr->getType()->getAs<PointerType>();
1501015021
if (!PtrTy) {
1501115022
Diag(PtrExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
15012-
<< PtrArgIdx + 1 << /*pointer to element ty*/ 2 << PtrExpr->getType();
15023+
<< PtrArgIdx + 1 << 0 << /* pointer to element ty */ 6 << 0
15024+
<< PtrExpr->getType();
1501315025
ArgError = true;
1501415026
} else {
1501515027
QualType ElementTy = PtrTy->getPointeeType();

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2338,7 +2338,8 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
23382338

23392339
if (!EltTy->isIntegerType()) {
23402340
Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2341-
<< 1 << /* integer ty */ 6 << ArgTy;
2341+
<< 1 << /* scalar or vector of */ 5 << /* integer ty */ 1
2342+
<< /* no fp */ 0 << ArgTy;
23422343
return true;
23432344
}
23442345

clang/test/Sema/aarch64-sve-vector-exp-ops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
svfloat32_t test_exp_vv_i8mf8(svfloat32_t v) {
88

99
return __builtin_elementwise_exp(v);
10-
// expected-error@-1 {{1st argument must be a floating point type}}
10+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
1111
}
1212

1313
svfloat32_t test_exp2_vv_i8mf8(svfloat32_t v) {
1414

1515
return __builtin_elementwise_exp2(v);
16-
// expected-error@-1 {{1st argument must be a floating point type}}
16+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
1717
}

clang/test/Sema/aarch64-sve-vector-log-ops.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
svfloat32_t test_log_vv_i8mf8(svfloat32_t v) {
88

99
return __builtin_elementwise_log(v);
10-
// expected-error@-1 {{1st argument must be a floating point type}}
10+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
1111
}
1212

1313
svfloat32_t test_log10_vv_i8mf8(svfloat32_t v) {
1414

1515
return __builtin_elementwise_log10(v);
16-
// expected-error@-1 {{1st argument must be a floating point type}}
16+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
1717
}
1818

1919
svfloat32_t test_log2_vv_i8mf8(svfloat32_t v) {
2020

2121
return __builtin_elementwise_log2(v);
22-
// expected-error@-1 {{1st argument must be a floating point type}}
22+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
2323
}

clang/test/Sema/aarch64-sve-vector-pow-ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
svfloat32_t test_pow_vv_i8mf8(svfloat32_t v) {
88

99
return __builtin_elementwise_pow(v, v);
10-
// expected-error@-1 {{1st argument must be a floating point type}}
10+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
1111
}

clang/test/Sema/aarch64-sve-vector-trig-ops.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,59 @@
77
svfloat32_t test_asin_vv_i8mf8(svfloat32_t v) {
88

99
return __builtin_elementwise_asin(v);
10-
// expected-error@-1 {{1st argument must be a floating point type}}
10+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
1111
}
1212

1313
svfloat32_t test_acos_vv_i8mf8(svfloat32_t v) {
1414

1515
return __builtin_elementwise_acos(v);
16-
// expected-error@-1 {{1st argument must be a floating point type}}
16+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
1717
}
1818

1919
svfloat32_t test_atan_vv_i8mf8(svfloat32_t v) {
2020

2121
return __builtin_elementwise_atan(v);
22-
// expected-error@-1 {{1st argument must be a floating point type}}
22+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
2323
}
2424

2525
svfloat32_t test_atan2_vv_i8mf8(svfloat32_t v) {
2626

2727
return __builtin_elementwise_atan2(v, v);
28-
// expected-error@-1 {{1st argument must be a floating point type}}
28+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
2929
}
3030

3131
svfloat32_t test_sin_vv_i8mf8(svfloat32_t v) {
3232

3333
return __builtin_elementwise_sin(v);
34-
// expected-error@-1 {{1st argument must be a floating point type}}
34+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
3535
}
3636

3737
svfloat32_t test_cos_vv_i8mf8(svfloat32_t v) {
3838

3939
return __builtin_elementwise_cos(v);
40-
// expected-error@-1 {{1st argument must be a floating point type}}
40+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
4141
}
4242

4343
svfloat32_t test_tan_vv_i8mf8(svfloat32_t v) {
4444

4545
return __builtin_elementwise_tan(v);
46-
// expected-error@-1 {{1st argument must be a floating point type}}
46+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
4747
}
4848

4949
svfloat32_t test_sinh_vv_i8mf8(svfloat32_t v) {
5050

5151
return __builtin_elementwise_sinh(v);
52-
// expected-error@-1 {{1st argument must be a floating point type}}
52+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
5353
}
5454

5555
svfloat32_t test_cosh_vv_i8mf8(svfloat32_t v) {
5656

5757
return __builtin_elementwise_cosh(v);
58-
// expected-error@-1 {{1st argument must be a floating point type}}
58+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
5959
}
6060

6161
svfloat32_t test_tanh_vv_i8mf8(svfloat32_t v) {
6262

6363
return __builtin_elementwise_tanh(v);
64-
// expected-error@-1 {{1st argument must be a floating point type}}
64+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types}}
6565
}

0 commit comments

Comments
 (0)