Skip to content

Commit 26fe3fe

Browse files
committed
Use CheckScalarOrVector for better diagnostics
1 parent f4c6443 commit 26fe3fe

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,20 +2250,8 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
22502250
return true;
22512251
if (CheckVectorElementCallArgs(&SemaRef, TheCall))
22522252
return true;
2253-
2254-
// check that the arguments are bools or, if vectors,
2255-
// vectors of bools
2256-
QualType ArgTy = TheCall->getArg(0)->getType();
2257-
if (const auto *VecTy = ArgTy->getAs<VectorType>()) {
2258-
ArgTy = VecTy->getElementType();
2259-
}
2260-
if (!getASTContext().hasSameUnqualifiedType(ArgTy,
2261-
getASTContext().BoolTy)) {
2262-
SemaRef.Diag(TheCall->getBeginLoc(),
2263-
diag::err_typecheck_convert_incompatible)
2264-
<< ArgTy << getASTContext().BoolTy << 1 << 0 << 0;
2253+
if (CheckScalarOrVector(&SemaRef, TheCall, getASTContext().BoolTy, 0))
22652254
return true;
2266-
}
22672255

22682256
ExprResult A = TheCall->getArg(0);
22692257
QualType ArgTyA = A.get()->getType();

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ bool2 test_mismatched_args(bool2 a, bool3 b) {
1717
// expected-error@-1 {{all arguments to '__builtin_hlsl_and' must have the same type}}
1818
}
1919

20-
struct S {
21-
bool a;
22-
};
23-
24-
bool test_invalid_type_conversion(S s) {
25-
return __builtin_hlsl_and(s, s);
26-
// expected-error@-1{{passing 'S' to parameter of incompatible type 'bool'}}
20+
bool test_incorrect_type(int a) {
21+
return __builtin_hlsl_and(a, a);
22+
// expected-error@-1{{invalid operand of type 'int' where 'bool' or a vector of such type is required}}
2723
}

0 commit comments

Comments
 (0)