Skip to content

Commit 69b8372

Browse files
authored
[clang][sema] consolidate diags for incompatible_vector_* (#83609)
removing the additions of `err_vec_builtin_non_vector_all` & `err_vec_builtin_incompatible_vector_all` caused by #83077. Instead adding a select option to `err_vec_builtin_non_vector` & `err_vec_builtin_incompatible_vector` to account for uses where there are more than two arguments.
1 parent 147f54e commit 69b8372

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10266,15 +10266,10 @@ def err_block_on_vm : Error<
1026610266
def err_sizeless_nonlocal : Error<
1026710267
"non-local variable with sizeless type %0">;
1026810268

10269-
def err_vec_builtin_non_vector_all : Error<
10270-
"all arguments to %0 must be vectors">;
10271-
def err_vec_builtin_incompatible_vector_all : Error<
10272-
"all arguments to %0 must have vectors of the same type">;
10273-
1027410269
def err_vec_builtin_non_vector : Error<
10275-
"first two arguments to %0 must be vectors">;
10270+
"%select{first two|all}1 arguments to %0 must be vectors">;
1027610271
def err_vec_builtin_incompatible_vector : Error<
10277-
"first two arguments to %0 must have the same type">;
10272+
"%select{first two|all}1 arguments to %0 must have the same type">;
1027810273
def err_vsx_builtin_nonconstant_argument : Error<
1027910274
"argument %0 to %1 must be a 2-bit unsigned literal (i.e. 0, 1, 2 or 3)">;
1028010275

clang/lib/Sema/SemaChecking.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5218,15 +5218,17 @@ bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) {
52185218
// Note: type promotion is intended to be handeled via the intrinsics
52195219
// and not the builtin itself.
52205220
S->Diag(TheCall->getBeginLoc(),
5221-
diag::err_vec_builtin_incompatible_vector_all)
5222-
<< TheCall->getDirectCallee()
5221+
diag::err_vec_builtin_incompatible_vector)
5222+
<< TheCall->getDirectCallee() << /*useAllTerminology*/ true
52235223
<< SourceRange(A.get()->getBeginLoc(), B.get()->getEndLoc());
52245224
retValue = true;
52255225
}
52265226
if (VecTyA->getNumElements() != VecTyB->getNumElements()) {
5227-
// if we get here a HLSLVectorTruncation is needed.
5228-
S->Diag(BuiltinLoc, diag::err_vec_builtin_incompatible_vector_all)
5229-
<< TheCall->getDirectCallee()
5227+
// You should only be hitting this case if you are calling the builtin
5228+
// directly. HLSL intrinsics should avoid this case via a
5229+
// HLSLVectorTruncation.
5230+
S->Diag(BuiltinLoc, diag::err_vec_builtin_incompatible_vector)
5231+
<< TheCall->getDirectCallee() << /*useAllTerminology*/ true
52305232
<< SourceRange(TheCall->getArg(0)->getBeginLoc(),
52315233
TheCall->getArg(1)->getEndLoc());
52325234
retValue = true;
@@ -5241,8 +5243,8 @@ bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) {
52415243

52425244
// Note: if we get here one of the args is a scalar which
52435245
// requires a VectorSplat on Arg0 or Arg1
5244-
S->Diag(BuiltinLoc, diag::err_vec_builtin_non_vector_all)
5245-
<< TheCall->getDirectCallee()
5246+
S->Diag(BuiltinLoc, diag::err_vec_builtin_non_vector)
5247+
<< TheCall->getDirectCallee() << /*useAllTerminology*/ true
52465248
<< SourceRange(TheCall->getArg(0)->getBeginLoc(),
52475249
TheCall->getArg(1)->getEndLoc());
52485250
return true;
@@ -9472,15 +9474,15 @@ bool Sema::SemaBuiltinVSX(CallExpr *TheCall) {
94729474
if ((!Arg1Ty->isVectorType() && !Arg1Ty->isDependentType()) ||
94739475
(!Arg2Ty->isVectorType() && !Arg2Ty->isDependentType())) {
94749476
return Diag(BuiltinLoc, diag::err_vec_builtin_non_vector)
9475-
<< TheCall->getDirectCallee()
9477+
<< TheCall->getDirectCallee() << /*isMorethantwoArgs*/ false
94769478
<< SourceRange(TheCall->getArg(0)->getBeginLoc(),
94779479
TheCall->getArg(1)->getEndLoc());
94789480
}
94799481

94809482
// Check the first two arguments are the same type.
94819483
if (!Context.hasSameUnqualifiedType(Arg1Ty, Arg2Ty)) {
94829484
return Diag(BuiltinLoc, diag::err_vec_builtin_incompatible_vector)
9483-
<< TheCall->getDirectCallee()
9485+
<< TheCall->getDirectCallee() << /*isMorethantwoArgs*/ false
94849486
<< SourceRange(TheCall->getArg(0)->getBeginLoc(),
94859487
TheCall->getArg(1)->getEndLoc());
94869488
}
@@ -9516,7 +9518,7 @@ ExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) {
95169518
if (!LHSType->isVectorType() || !RHSType->isVectorType())
95179519
return ExprError(
95189520
Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_non_vector)
9519-
<< TheCall->getDirectCallee()
9521+
<< TheCall->getDirectCallee() << /*isMorethantwoArgs*/ false
95209522
<< SourceRange(TheCall->getArg(0)->getBeginLoc(),
95219523
TheCall->getArg(1)->getEndLoc()));
95229524

@@ -9532,12 +9534,14 @@ ExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) {
95329534
return ExprError(Diag(TheCall->getBeginLoc(),
95339535
diag::err_vec_builtin_incompatible_vector)
95349536
<< TheCall->getDirectCallee()
9537+
<< /*isMorethantwoArgs*/ false
95359538
<< SourceRange(TheCall->getArg(1)->getBeginLoc(),
95369539
TheCall->getArg(1)->getEndLoc()));
95379540
} else if (!Context.hasSameUnqualifiedType(LHSType, RHSType)) {
95389541
return ExprError(Diag(TheCall->getBeginLoc(),
95399542
diag::err_vec_builtin_incompatible_vector)
95409543
<< TheCall->getDirectCallee()
9544+
<< /*isMorethantwoArgs*/ false
95419545
<< SourceRange(TheCall->getArg(0)->getBeginLoc(),
95429546
TheCall->getArg(1)->getEndLoc()));
95439547
} else if (numElements != numResElements) {

clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ float test_dot_vector_size_mismatch(float3 p0, float2 p1) {
2222

2323
float test_dot_builtin_vector_size_mismatch(float3 p0, float2 p1) {
2424
return __builtin_hlsl_dot(p0, p1);
25-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}}
25+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
2626
}
2727

2828
float test_dot_scalar_mismatch(float p0, int p1) {
@@ -38,39 +38,39 @@ float test_dot_element_type_mismatch(int2 p0, float2 p1) {
3838
//NOTE: for all the *_promotion we are intentionally not handling type promotion in builtins
3939
float test_builtin_dot_vec_int_to_float_promotion(int2 p0, float2 p1) {
4040
return __builtin_hlsl_dot(p0, p1);
41-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}}
41+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
4242
}
4343

4444
int64_t test_builtin_dot_vec_int_to_int64_promotion(int64_t2 p0, int2 p1) {
4545
return __builtin_hlsl_dot(p0, p1);
46-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}}
46+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
4747
}
4848

4949
float test_builtin_dot_vec_half_to_float_promotion(float2 p0, half2 p1) {
5050
return __builtin_hlsl_dot(p0, p1);
51-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}}
51+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
5252
}
5353

5454
#ifdef __HLSL_ENABLE_16_BIT
5555
float test_builtin_dot_vec_int16_to_float_promotion(float2 p0, int16_t2 p1) {
5656
return __builtin_hlsl_dot(p0, p1);
57-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}}
57+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
5858
}
5959

6060
half test_builtin_dot_vec_int16_to_half_promotion(half2 p0, int16_t2 p1) {
6161
return __builtin_hlsl_dot(p0, p1);
62-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}}
62+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
6363
}
6464

6565
int test_builtin_dot_vec_int16_to_int_promotion(int2 p0, int16_t2 p1) {
6666
return __builtin_hlsl_dot(p0, p1);
67-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}}
67+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
6868
}
6969

7070
int64_t test_builtin_dot_vec_int16_to_int64_promotion(int64_t2 p0,
7171
int16_t2 p1) {
7272
return __builtin_hlsl_dot(p0, p1);
73-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}}
73+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
7474
}
7575
#endif
7676

clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ float2 test_lerp_vector_size_mismatch(float3 p0, float2 p1) {
2727

2828
float2 test_lerp_builtin_vector_size_mismatch(float3 p0, float2 p1) {
2929
return __builtin_hlsl_lerp(p0, p1, p1);
30-
// expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have vectors of the same type}}
30+
// expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}}
3131
}
3232

3333
float test_lerp_scalar_mismatch(float p0, half p1) {

0 commit comments

Comments
 (0)