Skip to content

Commit d2b315a

Browse files
committed
Add a new sema diag message for AddUint64
1 parent 39f17d5 commit d2b315a

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10623,7 +10623,7 @@ def err_second_argument_to_cwsc_not_pointer : Error<
1062310623
"second argument to __builtin_call_with_static_chain must be of pointer type">;
1062410624

1062510625
def err_vector_incorrect_num_elements : Error<
10626-
"%select{too many|too few|incorrect number of}0 elements in vector %select{initialization|operand}3 (expected %1 elements, have %2)">;
10626+
"%select{too many|too few}0 elements in vector %select{initialization|operand}3 (expected %1 elements, have %2)">;
1062710627
def err_altivec_empty_initializer : Error<"expected initializer">;
1062810628

1062910629
def err_invalid_neon_type_code : Error<
@@ -12553,6 +12553,8 @@ def err_std_initializer_list_malformed : Error<
1255312553
"%0 layout not recognized. Must be a non-polymorphic class type with no bases and two fields: a 'const E *' and either another 'const E *' or a 'std::size_t'">;
1255412554

1255512555
// HLSL Diagnostics
12556+
def err_hlsl_adduint64_invalid_arguments: Error<
12557+
"%select{scalar provided to a vector operand|invalid number of elements in vector operand}0 (expected a uint vector of 2 or 4 elements)">;
1255612558
def err_hlsl_attr_unsupported_in_stage : Error<"attribute %0 is unsupported in '%1' shaders, requires %select{|one of the following: }2%3">;
1255712559
def err_hlsl_attr_invalid_type : Error<
1255812560
"attribute %0 only applies to a field or parameter of type '%1'">;

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,17 +2241,18 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
22412241
// ensure both args are vectors
22422242
auto *VTy = TheCall->getArg(0)->getType()->getAs<VectorType>();
22432243
if (!VTy) {
2244-
SemaRef.Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_non_vector)
2245-
<< "AddUint64" << /*all*/ 1;
2244+
SemaRef.Diag(TheCall->getBeginLoc(),
2245+
diag::err_hlsl_adduint64_invalid_arguments)
2246+
<< /*scalar provided to a vector operand*/ 0;
22462247
return true;
22472248
}
22482249

22492250
// ensure both args have 2 elements, or both args have 4 elements
22502251
int NumElementsArg = VTy->getNumElements();
22512252
if (NumElementsArg != 2 && NumElementsArg != 4) {
22522253
SemaRef.Diag(TheCall->getBeginLoc(),
2253-
diag::err_vector_incorrect_num_elements)
2254-
<< 2 << "2 or 4" << NumElementsArg << /*operand*/ 1;
2254+
diag::err_hlsl_adduint64_invalid_arguments)
2255+
<< /*invalid number of elements in vector operand*/ 1;
22552256
return true;
22562257
}
22572258

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ uint2 test_mismatched_arg_types(uint2 a, uint4 b) {
1717

1818
uint2 test_bad_num_arg_elements(uint3 a, uint3 b) {
1919
return __builtin_hlsl_adduint64(a, b);
20-
// expected-error@-1 {{incorrect number of elements in vector operand (expected 2 or 4 elements, have 3)}}
20+
// expected-error@-1 {{invalid number of elements in vector operand (expected a uint vector of 2 or 4 elements}}
2121
}
2222

2323
uint2 test_scalar_arg_type(uint a) {
2424
return __builtin_hlsl_adduint64(a, a);
25-
// expected-error@-1 {{all arguments to AddUint64 must be vectors}}
25+
// expected-error@-1 {{scalar provided to a vector operand (expected a uint vector of 2 or 4 elements)}}
2626
}
2727

2828
uint2 test_signed_integer_args(int2 a, int2 b) {

0 commit comments

Comments
 (0)