Skip to content

Commit

Permalink
update diag message
Browse files Browse the repository at this point in the history
  • Loading branch information
bob80905 committed Sep 30, 2024
1 parent f31ecc6 commit 81aa399
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,6 @@ def err_invalid_vector_long_double_decl_spec : Error<
"cannot use 'long double' with '__vector'">;
def err_invalid_vector_complex_decl_spec : Error<
"cannot use '_Complex' with '__vector'">;
def err_invalid_vector_size : Error<
"expected vector size of '%0', but vector size is '%1'">;
def warn_vector_long_decl_spec_combination : Warning<
"use of 'long' with '__vector' is deprecated">, InGroup<Deprecated>;

Expand Down Expand Up @@ -10508,7 +10506,9 @@ def err_second_argument_to_cwsc_not_pointer : Error<
"second argument to __builtin_call_with_static_chain must be of pointer type">;

def err_vector_incorrect_num_initializers : Error<
"%select{too many|too few}0 elements in vector initialization (expected %1 elements, have %2)">;
"%select{too many|too few}0 elements in vector %select{initialization|operand}3 (expected %1 elements, have %2)">;
def err_incorrect_vector_element_count : Error<
err_vector_incorrect_num_initializers.Summary>;
def err_altivec_empty_initializer : Error<"expected initializer">;

def err_invalid_neon_type_code : Error<
Expand Down
14 changes: 10 additions & 4 deletions clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1840,14 +1840,20 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
TheCall->getArg(0)->getType()->getAs<VectorType>()->getNumElements();
int NumElementsArg2 =
TheCall->getArg(1)->getType()->getAs<VectorType>()->getNumElements();

if (NumElementsArg1 != 3) {
SemaRef.Diag(TheCall->getBeginLoc(), diag::err_invalid_vector_size)
<< NumElementsArg1 << 3;
int LessOrMore = NumElementsArg1 > 3 ? 1 : 0;
SemaRef.Diag(TheCall->getBeginLoc(),
diag::err_vector_incorrect_num_initializers)
<< LessOrMore << 3 << NumElementsArg1 << 1;
return true;
}
if (NumElementsArg2 != 3) {
SemaRef.Diag(TheCall->getBeginLoc(), diag::err_invalid_vector_size)
<< NumElementsArg2 << 3;
int LessOrMore = NumElementsArg1 > 3 ? 1 : 0;

SemaRef.Diag(TheCall->getBeginLoc(),
diag::err_vector_incorrect_num_initializers)
<< LessOrMore << 3 << NumElementsArg2 << 1;
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,7 @@ void InitListChecker::CheckVectorType(const InitializedEntity &Entity,
if (!VerifyOnly)
SemaRef.Diag(IList->getBeginLoc(),
diag::err_vector_incorrect_num_initializers)
<< (numEltsInit < maxElements) << maxElements << numEltsInit;
<< (numEltsInit < maxElements) << maxElements << numEltsInit << 0;
hadError = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/SemaHLSL/BuiltIns/cross-errors.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool2 builtin_cross_int2_to_float2_promotion(int2 p1)
float2 builtin_cross_float2(float2 p1, float2 p2)
{
return __builtin_hlsl_cross(p1, p2);
// expected-error@-1 {{expected vector size of '2', but vector size is '3'}}
// expected-error@-1 {{too many elements in vector operand (expected 3 elements, have 2)}}
}

float3 builtin_cross_float3_int3(float3 p1, int3 p2)
Expand Down

0 comments on commit 81aa399

Please sign in to comment.