[clang] [HLSL] Update Sema Checking Diagnostics for builtins (PR #138429)
Farzon Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Thu May 15 11:50:10 PDT 2025
================
@@ -2164,30 +2083,48 @@ static bool CheckModifiableLValue(Sema *S, CallExpr *TheCall,
return true;
}
-static bool CheckNoDoubleVectors(Sema *S, CallExpr *TheCall) {
- auto checkDoubleVector = [](clang::QualType PassedType) -> bool {
- if (const auto *VecTy = PassedType->getAs<VectorType>())
- return VecTy->getElementType()->isDoubleType();
- return false;
- };
- return CheckAllArgTypesAreCorrect(S, TheCall, S->Context.FloatTy,
- checkDoubleVector);
+static bool CheckNoDoubleVectors(Sema *S, SourceLocation Loc, int ArgOrdinal,
+ clang::QualType PassedType) {
+ if (const auto *VecTy = PassedType->getAs<VectorType>())
+ if (VecTy->getElementType()->isDoubleType())
+ return S->Diag(Loc, diag::err_builtin_invalid_arg_type)
+ << ArgOrdinal << /* scalar */ 1 << /* no int */ 0 << /* fp */ 1
+ << PassedType;
+ return false;
}
----------------
farzonl wrote:
Small Nit: I really like to try to avoid nesting if possible. seems like we might be able to if we do the negation checks first.
```suggestion
static bool CheckNoDoubleVectors(Sema *S, SourceLocation Loc, int ArgOrdinal,
clang::QualType PassedType) {
const auto *VecTy = PassedType->getAs<VectorType>();
if (!VecTy)
return false;
if (!VecTy->getElementType()->isDoubleType())
return false;
return S->Diag(Loc, diag::err_builtin_invalid_arg_type)
<< ArgOrdinal << /* scalar */ 1 << /* no int */ 0 << /* fp */ 1
<< PassedType;
}
```
https://github.com/llvm/llvm-project/pull/138429
More information about the cfe-commits
mailing list