================ @@ -46,6 +46,59 @@ static bool CheckAllArgsHaveSameType(Sema *S, CallExpr *TheCall) { return false; } +static bool CheckAllArgTypesAreCorrect( + Sema *S, CallExpr *TheCall, + llvm::ArrayRef< + llvm::function_ref<bool(Sema *, SourceLocation, int, QualType)>> + Checks) { + unsigned NumArgs = TheCall->getNumArgs(); + assert(Checks.size() == NumArgs && + "Wrong number of checks for Number of args."); + // Apply each check to the corresponding argument + for (unsigned I = 0; I < NumArgs; ++I) { + Expr *Arg = TheCall->getArg(I); + if (Checks[I](S, Arg->getBeginLoc(), I + 1, Arg->getType())) + return true; + } + return false; +} + +static bool CheckAllArgTypesAreCorrect( + Sema *S, CallExpr *TheCall, + llvm::function_ref<bool(Sema *, SourceLocation, int, QualType)> Check) { + return CheckAllArgTypesAreCorrect( + S, TheCall, + SmallVector< + llvm::function_ref<bool(Sema *, SourceLocation, int, QualType)>, 4>( + TheCall->getNumArgs(), Check)); +} + +static bool CheckFloatOrHalfRepresentation(Sema *S, SourceLocation Loc, + int ArgOrdinal, + clang::QualType PassedType) { + clang::QualType BaseType = + PassedType->isVectorType() + ? PassedType->castAs<clang::VectorType>()->getElementType() + : PassedType; + if (!BaseType->isHalfType() && !BaseType->isFloat32Type()) + return S->Diag(Loc, diag::err_builtin_invalid_arg_type) + << ArgOrdinal << /* scalar or vector of */ 5 << /* no int */ 0 + << /* half or float */ 2 << PassedType; + return false; +} + +static bool CheckFloatOrHalfScalarRepresentation(Sema *S, SourceLocation Loc, + int ArgOrdinal, + clang::QualType PassedType) { + const auto *VecTy = PassedType->getAs<VectorType>(); + + if (VecTy || (!PassedType->isHalfType() && !PassedType->isFloat32Type())) ---------------- spall wrote:
You don't need the VecTy check here, isHalfType() and isFloat32Type() should both return false if PassedType is a vector. https://github.com/llvm/llvm-project/pull/147342 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits