Skip to content

Commit eac0fe5

Browse files
committed
Make diag::err_hlsl_adduint64_invalid_arguments more generic
- Renamed diag::err_hlsl_adduint64_invalid_arguments to diag::err_invalid_even_odd_vector_element_count - The error message is now along the lines of "invalid element count of X in vector initializer/operand (expected an even/odd element count in the range of Y and Z)" - Type is not included in the error message because another error handler already catches when an incorrect type is used - Switch back to using diag::err_vec_builtin_non_vector to report an error when a scalar is passed to AddUint64 instead of a vector
1 parent d2b315a commit eac0fe5

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10624,6 +10624,8 @@ def err_second_argument_to_cwsc_not_pointer : Error<
1062410624

1062510625
def err_vector_incorrect_num_elements : Error<
1062610626
"%select{too many|too few}0 elements in vector %select{initialization|operand}3 (expected %1 elements, have %2)">;
10627+
def err_invalid_even_odd_vector_element_count : Error<
10628+
"invalid element count of %0 in vector %select{initialization|operand}4 (expected an %select{even|odd}3 element count in the range of %1 and %2)">;
1062710629
def err_altivec_empty_initializer : Error<"expected initializer">;
1062810630

1062910631
def err_invalid_neon_type_code : Error<
@@ -12553,8 +12555,6 @@ def err_std_initializer_list_malformed : Error<
1255312555
"%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'">;
1255412556

1255512557
// 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)">;
1255812558
def err_hlsl_attr_unsupported_in_stage : Error<"attribute %0 is unsupported in '%1' shaders, requires %select{|one of the following: }2%3">;
1255912559
def err_hlsl_attr_invalid_type : Error<
1256012560
"attribute %0 only applies to a field or parameter of type '%1'">;

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,17 +2242,16 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
22422242
auto *VTy = TheCall->getArg(0)->getType()->getAs<VectorType>();
22432243
if (!VTy) {
22442244
SemaRef.Diag(TheCall->getBeginLoc(),
2245-
diag::err_hlsl_adduint64_invalid_arguments)
2246-
<< /*scalar provided to a vector operand*/ 0;
2245+
diag::err_vec_builtin_non_vector) << "AddUint64" << /*all*/ 1;
22472246
return true;
22482247
}
22492248

22502249
// ensure both args have 2 elements, or both args have 4 elements
22512250
int NumElementsArg = VTy->getNumElements();
22522251
if (NumElementsArg != 2 && NumElementsArg != 4) {
22532252
SemaRef.Diag(TheCall->getBeginLoc(),
2254-
diag::err_hlsl_adduint64_invalid_arguments)
2255-
<< /*invalid number of elements in vector operand*/ 1;
2253+
diag::err_invalid_even_odd_vector_element_count)
2254+
<< NumElementsArg << 2 << 4 << /*even*/ 0 << /*operand*/ 1;
22562255
return true;
22572256
}
22582257

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 {{invalid number of elements in vector operand (expected a uint vector of 2 or 4 elements}}
20+
// expected-error@-1 {{invalid element count of 3 in vector operand (expected an even element count in the range of 2 and 4)}}
2121
}
2222

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

2828
uint2 test_signed_integer_args(int2 a, int2 b) {

0 commit comments

Comments
 (0)