Skip to content

Commit 28b7eb8

Browse files
committed
Address PR comments and rename some symbols
- Rename CheckUnsignedIntegerRepresentation to CheckUnsignedIntRepresentations to more closely match the name of existing functions (There is a function named CheckUnsignedIntRepresentation in the same file) - Rename NumElementsArg1 to NumElementsArg since we are only checking one arg, with the assertion that the other arg has the same type - Change diag message displayed when a scalar is passed as an argument. It now uses diag::err_vec_builtin_non_vector to say that AddUint64 expects all its arguments to be vectors - Remove unintended include `#include "clang/Basic/DiagnosticParse.h"`
1 parent 27348ce commit 28b7eb8

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "clang/AST/Type.h"
2222
#include "clang/AST/TypeLoc.h"
2323
#include "clang/Basic/Builtins.h"
24-
#include "clang/Basic/DiagnosticParse.h"
2524
#include "clang/Basic/DiagnosticSema.h"
2625
#include "clang/Basic/IdentifierTable.h"
2726
#include "clang/Basic/LLVM.h"
@@ -2024,7 +2023,7 @@ static bool CheckAllArgsHaveFloatRepresentation(Sema *S, CallExpr *TheCall) {
20242023
checkAllFloatTypes);
20252024
}
20262025

2027-
static bool CheckUnsignedIntegerRepresentation(Sema *S, CallExpr *TheCall) {
2026+
static bool CheckUnsignedIntRepresentations(Sema *S, CallExpr *TheCall) {
20282027
auto checkUnsignedInteger = [](clang::QualType PassedType) -> bool {
20292028
clang::QualType BaseType =
20302029
PassedType->isVectorType()
@@ -2232,7 +2231,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
22322231
return true;
22332232
if (CheckVectorElementCallArgs(&SemaRef, TheCall))
22342233
return true;
2235-
if (CheckUnsignedIntegerRepresentation(&SemaRef, TheCall))
2234+
if (CheckUnsignedIntRepresentations(&SemaRef, TheCall))
22362235
return true;
22372236

22382237
// CheckVectorElementCallArgs(...) guarantees both args are the same type.
@@ -2242,18 +2241,17 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
22422241
// ensure both args are vectors
22432242
auto *VTy = TheCall->getArg(0)->getType()->getAs<VectorType>();
22442243
if (!VTy) {
2245-
SemaRef.Diag(TheCall->getBeginLoc(),
2246-
diag::err_vector_incorrect_num_elements)
2247-
<< 2 << "2 or 4" << 1 << /*operand*/ 1;
2244+
SemaRef.Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_non_vector)
2245+
<< "AddUint64" << /*all*/ 1;
22482246
return true;
22492247
}
22502248

22512249
// ensure both args have 2 elements, or both args have 4 elements
2252-
int NumElementsArg1 = VTy->getNumElements();
2253-
if (NumElementsArg1 != 2 && NumElementsArg1 != 4) {
2250+
int NumElementsArg = VTy->getNumElements();
2251+
if (NumElementsArg != 2 && NumElementsArg != 4) {
22542252
SemaRef.Diag(TheCall->getBeginLoc(),
22552253
diag::err_vector_incorrect_num_elements)
2256-
<< 2 << "2 or 4" << NumElementsArg1 << /*operand*/ 1;
2254+
<< 2 << "2 or 4" << NumElementsArg << /*operand*/ 1;
22572255
return true;
22582256
}
22592257

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,14 @@ uint2 test_mismatched_arg_types(uint2 a, uint4 b) {
1515
// expected-error@-1 {{all arguments to '__builtin_hlsl_adduint64' must have the same type}}
1616
}
1717

18-
uint2 test_too_many_arg_elements(uint3 a, uint3 b) {
19-
return __builtin_hlsl_adduint64(a, b);
20-
// expected-error@-1 {{incorrect number of elements in vector operand (expected 2 or 4 elements, have 3)}}
21-
}
22-
23-
uint4 test_too_few_arg_elements(uint3 a, uint3 b) {
18+
uint2 test_bad_num_arg_elements(uint3 a, uint3 b) {
2419
return __builtin_hlsl_adduint64(a, b);
2520
// expected-error@-1 {{incorrect number of elements in vector operand (expected 2 or 4 elements, have 3)}}
2621
}
2722

2823
uint2 test_scalar_arg_type(uint a) {
2924
return __builtin_hlsl_adduint64(a, a);
30-
// expected-error@-1 {{incorrect number of elements in vector operand (expected 2 or 4 elements, have 1)}}
25+
// expected-error@-1 {{all arguments to AddUint64 must be vectors}}
3126
}
3227

3328
uint2 test_signed_integer_args(int2 a, int2 b) {

0 commit comments

Comments
 (0)