https://github.com/spall created https://github.com/llvm/llvm-project/pull/138429
Update how Sema Checking is done for HLSL builtins to allow for better error messages, mainly using 'err_builtin_invalid_arg_type'. Try to follow the formula outlined in issue #134721 Closes #134721 >From 1139101e277f8f4d327fd7b422959dc4a3a43dbe Mon Sep 17 00:00:00 2001 From: Sarah Spall <sarahsp...@microsoft.com> Date: Tue, 18 Mar 2025 11:04:11 -0700 Subject: [PATCH] update error messaging --- .../clang/Basic/DiagnosticSemaKinds.td | 2 +- clang/lib/Sema/SemaHLSL.cpp | 316 ++++++++---------- .../SemaHLSL/BuiltIns/AddUint64-errors.hlsl | 6 +- .../SemaHLSL/BuiltIns/asdouble-errors.hlsl | 10 + .../test/SemaHLSL/BuiltIns/clamp-errors.hlsl | 27 +- .../test/SemaHLSL/BuiltIns/cross-errors.hlsl | 12 +- .../SemaHLSL/BuiltIns/degrees-errors.hlsl | 6 +- clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl | 33 +- clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl | 8 +- .../BuiltIns/half-float-only-errors.hlsl | 4 +- .../BuiltIns/half-float-only-errors2.hlsl | 4 +- .../test/SemaHLSL/BuiltIns/isinf-errors.hlsl | 12 +- clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl | 20 +- .../BuiltIns/logical-operator-errors.hlsl | 6 + clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl | 22 +- .../SemaHLSL/BuiltIns/normalize-errors.hlsl | 8 +- .../SemaHLSL/BuiltIns/radians-errors.hlsl | 8 +- clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl | 9 +- .../SemaHLSL/BuiltIns/reversebits-errors.hlsl | 2 +- .../test/SemaHLSL/BuiltIns/rsqrt-errors.hlsl | 11 +- clang/test/SemaHLSL/BuiltIns/step-errors.hlsl | 8 +- 21 files changed, 253 insertions(+), 281 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index ccb14e9927adf..c94d34e0259be 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12649,7 +12649,7 @@ def err_builtin_invalid_arg_type: Error< // An 'or' if non-empty second and third components are combined "%plural{0:|:%plural{0:|:or }2}3" // Third component: floating-point types - "%select{|floating-point}3" + "%select{|floating-point|16 or 32 bit floating-point}3" // A space after a non-empty third component "%plural{0:|: }3" "%plural{[0,3]:type|:types}1 (was %4)">; diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 70aacaa2aadbe..6486ef765f32e 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -2005,68 +2005,6 @@ void SemaHLSL::diagnoseAvailabilityViolations(TranslationUnitDecl *TU) { DiagnoseHLSLAvailability(SemaRef).RunOnTranslationUnit(TU); } -// Helper function for CheckHLSLBuiltinFunctionCall -static bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) { - assert(TheCall->getNumArgs() > 1); - ExprResult A = TheCall->getArg(0); - - QualType ArgTyA = A.get()->getType(); - - auto *VecTyA = ArgTyA->getAs<VectorType>(); - SourceLocation BuiltinLoc = TheCall->getBeginLoc(); - - bool AllBArgAreVectors = true; - for (unsigned i = 1; i < TheCall->getNumArgs(); ++i) { - ExprResult B = TheCall->getArg(i); - QualType ArgTyB = B.get()->getType(); - auto *VecTyB = ArgTyB->getAs<VectorType>(); - if (VecTyB == nullptr) - AllBArgAreVectors &= false; - if (VecTyA && VecTyB == nullptr) { - // Note: if we get here 'B' is scalar which - // requires a VectorSplat on ArgN - S->Diag(BuiltinLoc, diag::err_vec_builtin_non_vector) - << TheCall->getDirectCallee() << /*useAllTerminology*/ true - << SourceRange(A.get()->getBeginLoc(), B.get()->getEndLoc()); - return true; - } - if (VecTyA && VecTyB) { - bool retValue = false; - if (!S->Context.hasSameUnqualifiedType(VecTyA->getElementType(), - VecTyB->getElementType())) { - // Note: type promotion is intended to be handeled via the intrinsics - // and not the builtin itself. - S->Diag(TheCall->getBeginLoc(), - diag::err_vec_builtin_incompatible_vector) - << TheCall->getDirectCallee() << /*useAllTerminology*/ true - << SourceRange(A.get()->getBeginLoc(), B.get()->getEndLoc()); - retValue = true; - } - if (VecTyA->getNumElements() != VecTyB->getNumElements()) { - // You should only be hitting this case if you are calling the builtin - // directly. HLSL intrinsics should avoid this case via a - // HLSLVectorTruncation. - S->Diag(BuiltinLoc, diag::err_vec_builtin_incompatible_vector) - << TheCall->getDirectCallee() << /*useAllTerminology*/ true - << SourceRange(A.get()->getBeginLoc(), B.get()->getEndLoc()); - retValue = true; - } - if (retValue) - return retValue; - } - } - - if (VecTyA == nullptr && AllBArgAreVectors) { - // Note: if we get here 'A' is a scalar which - // requires a VectorSplat on Arg0 - S->Diag(BuiltinLoc, diag::err_vec_builtin_non_vector) - << TheCall->getDirectCallee() << /*useAllTerminology*/ true - << SourceRange(A.get()->getBeginLoc(), A.get()->getEndLoc()); - return true; - } - return false; -} - static bool CheckAllArgsHaveSameType(Sema *S, CallExpr *TheCall) { assert(TheCall->getNumArgs() > 1); QualType ArgTy0 = TheCall->getArg(0)->getType(); @@ -2094,63 +2032,46 @@ static bool CheckArgTypeMatches(Sema *S, Expr *Arg, QualType ExpectedType) { return false; } -static bool CheckArgTypeIsCorrect( - Sema *S, Expr *Arg, QualType ExpectedType, - llvm::function_ref<bool(clang::QualType PassedType)> Check) { - QualType PassedType = Arg->getType(); - if (Check(PassedType)) { - if (auto *VecTyA = PassedType->getAs<VectorType>()) - ExpectedType = S->Context.getVectorType( - ExpectedType, VecTyA->getNumElements(), VecTyA->getVectorKind()); - S->Diag(Arg->getBeginLoc(), diag::err_typecheck_convert_incompatible) - << PassedType << ExpectedType << 1 << 0 << 0; - return true; - } - return false; -} - static bool CheckAllArgTypesAreCorrect( - Sema *S, CallExpr *TheCall, QualType ExpectedType, - llvm::function_ref<bool(clang::QualType PassedType)> Check) { - for (unsigned i = 0; i < TheCall->getNumArgs(); ++i) { - Expr *Arg = TheCall->getArg(i); - if (CheckArgTypeIsCorrect(S, Arg, ExpectedType, Check)) { + Sema *S, CallExpr *TheCall, + llvm::function_ref<bool(Sema *S, SourceLocation Loc, int ArgOrdinal, + clang::QualType PassedType)> + Check) { + for (unsigned I = 0; I < TheCall->getNumArgs(); ++I) { + Expr *Arg = TheCall->getArg(I); + if (Check(S, Arg->getBeginLoc(), I + 1, Arg->getType())) return true; - } } return false; } -static bool CheckAllArgsHaveFloatRepresentation(Sema *S, CallExpr *TheCall) { - auto checkAllFloatTypes = [](clang::QualType PassedType) -> bool { - return !PassedType->hasFloatingRepresentation(); - }; - return CheckAllArgTypesAreCorrect(S, TheCall, S->Context.FloatTy, - checkAllFloatTypes); -} +static bool CheckFloatOrHalfVecRepresentation(Sema *S, SourceLocation Loc, + int ArgOrdinal, + clang::QualType PassedType) { + QualType EltTy = PassedType; + if (auto *VecTy = EltTy->getAs<VectorType>()) + EltTy = VecTy->getElementType(); -static bool CheckUnsignedIntRepresentations(Sema *S, CallExpr *TheCall) { - auto checkUnsignedInteger = [](clang::QualType PassedType) -> bool { - clang::QualType BaseType = - PassedType->isVectorType() - ? PassedType->getAs<clang::VectorType>()->getElementType() - : PassedType; - return !BaseType->isUnsignedIntegerType(); - }; - return CheckAllArgTypesAreCorrect(S, TheCall, S->Context.UnsignedIntTy, - checkUnsignedInteger); + if (!PassedType->getAs<VectorType>() || + !(EltTy->isHalfType() || EltTy->isFloat32Type())) + return S->Diag(Loc, diag::err_builtin_invalid_arg_type) + << ArgOrdinal << /* vector of */ 4 << /* no int */ 0 + << /* half or float */ 2 << PassedType; + return false; } -static bool CheckFloatOrHalfRepresentations(Sema *S, CallExpr *TheCall) { - auto checkFloatorHalf = [](clang::QualType PassedType) -> bool { - clang::QualType BaseType = - PassedType->isVectorType() - ? PassedType->getAs<clang::VectorType>()->getElementType() - : PassedType; - return !BaseType->isHalfType() && !BaseType->isFloat32Type(); - }; - return CheckAllArgTypesAreCorrect(S, TheCall, S->Context.FloatTy, - checkFloatorHalf); +static bool CheckFloatOrHalfRepresentation(Sema *S, SourceLocation Loc, + int ArgOrdinal, + clang::QualType PassedType) { + clang::QualType BaseType = + PassedType->isVectorType() + ? PassedType->getAs<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 CheckModifiableLValue(Sema *S, CallExpr *TheCall, @@ -2164,30 +2085,49 @@ 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; } -static bool CheckFloatingOrIntRepresentation(Sema *S, CallExpr *TheCall) { - auto checkAllSignedTypes = [](clang::QualType PassedType) -> bool { - return !PassedType->hasIntegerRepresentation() && - !PassedType->hasFloatingRepresentation(); - }; - return CheckAllArgTypesAreCorrect(S, TheCall, S->Context.IntTy, - checkAllSignedTypes); + +static bool CheckFloatingOrIntRepresentation(Sema *S, SourceLocation Loc, + int ArgOrdinal, + clang::QualType PassedType) { + if (!PassedType->hasIntegerRepresentation() && + !PassedType->hasFloatingRepresentation()) + return S->Diag(Loc, diag::err_builtin_invalid_arg_type) + << ArgOrdinal << /* scalar or vector of */ 5 << /* integer */ 1 + << /* fp */ 1 << PassedType; + return false; } -static bool CheckUnsignedIntRepresentation(Sema *S, CallExpr *TheCall) { - auto checkAllUnsignedTypes = [](clang::QualType PassedType) -> bool { - return !PassedType->hasUnsignedIntegerRepresentation(); - }; - return CheckAllArgTypesAreCorrect(S, TheCall, S->Context.UnsignedIntTy, - checkAllUnsignedTypes); +static bool CheckUnsignedIntVecRepresentation(Sema *S, SourceLocation Loc, + int ArgOrdinal, + clang::QualType PassedType) { + QualType EltTy = PassedType; + if (auto *VecTy = EltTy->getAs<VectorType>()) + EltTy = VecTy->getElementType(); + + if (!PassedType->getAs<VectorType>() || !EltTy->isUnsignedIntegerType()) + return S->Diag(Loc, diag::err_builtin_invalid_arg_type) + << ArgOrdinal << /* vector of */ 4 << /* uint */ 3 << /* no fp */ 0 + << PassedType; + return false; +} + +static bool CheckUnsignedIntRepresentation(Sema *S, SourceLocation Loc, + int ArgOrdinal, + clang::QualType PassedType) { + if (!PassedType->hasUnsignedIntegerRepresentation()) + return S->Diag(Loc, diag::err_builtin_invalid_arg_type) + << ArgOrdinal << /* scalar or vector of */ 5 << /* unsigned int */ 3 + << /* no fp */ 0 << PassedType; + return false; } static void SetElementTypeAsReturnType(Sema *S, CallExpr *TheCall, @@ -2343,23 +2283,12 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { case Builtin::BI__builtin_hlsl_adduint64: { if (SemaRef.checkArgCount(TheCall, 2)) return true; - if (CheckVectorElementCallArgs(&SemaRef, TheCall)) - return true; - if (CheckUnsignedIntRepresentations(&SemaRef, TheCall)) - return true; - - // CheckVectorElementCallArgs(...) guarantees both args are the same type. - assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() && - "Both args must be of the same type"); - // ensure both args are vectors - auto *VTy = TheCall->getArg(0)->getType()->getAs<VectorType>(); - if (!VTy) { - SemaRef.Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_non_vector) - << TheCall->getDirectCallee() << /*all*/ 1; + if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall, + CheckUnsignedIntVecRepresentation)) return true; - } + auto *VTy = TheCall->getArg(0)->getType()->getAs<VectorType>(); // ensure arg integers are 32-bits uint64_t ElementBitCount = getASTContext() .getTypeSizeInChars(VTy->getElementType()) @@ -2380,6 +2309,10 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { return true; } + // ensure first arg and second arg have the same type + if (CheckAllArgsHaveSameType(&SemaRef, TheCall)) + return true; + ExprResult A = TheCall->getArg(0); QualType ArgTyA = A.get()->getType(); // return type is the same as the input type @@ -2431,10 +2364,10 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { case Builtin::BI__builtin_hlsl_or: { if (SemaRef.checkArgCount(TheCall, 2)) return true; - if (CheckVectorElementCallArgs(&SemaRef, TheCall)) - return true; if (CheckScalarOrVector(&SemaRef, TheCall, getASTContext().BoolTy, 0)) return true; + if (CheckAllArgsHaveSameType(&SemaRef, TheCall)) + return true; ExprResult A = TheCall->getArg(0); QualType ArgTyA = A.get()->getType(); @@ -2446,37 +2379,41 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { case Builtin::BI__builtin_hlsl_any: { if (SemaRef.checkArgCount(TheCall, 1)) return true; + if (CheckAnyScalarOrVector(&SemaRef, TheCall, 0)) + return true; break; } case Builtin::BI__builtin_hlsl_asdouble: { if (SemaRef.checkArgCount(TheCall, 2)) return true; - if (CheckUnsignedIntRepresentation(&SemaRef, TheCall)) + if (CheckScalarOrVector(&SemaRef, TheCall, SemaRef.Context.UnsignedIntTy, + 0)) + return true; + if (CheckScalarOrVector(&SemaRef, TheCall, SemaRef.Context.UnsignedIntTy, + 1)) + return true; + if (CheckAllArgsHaveSameType(&SemaRef, TheCall)) return true; SetElementTypeAsReturnType(&SemaRef, TheCall, getASTContext().DoubleTy); break; } case Builtin::BI__builtin_hlsl_elementwise_clamp: { - if (SemaRef.checkArgCount(TheCall, 3)) - return true; - if (CheckAnyScalarOrVector(&SemaRef, TheCall, 0) || - CheckAllArgsHaveSameType(&SemaRef, TheCall)) - return true; if (SemaRef.BuiltinElementwiseTernaryMath( TheCall, /*ArgTyRestr=*/ - TheCall->getArg(0)->getType()->hasFloatingRepresentation() - ? Sema::EltwiseBuiltinArgTyRestriction::FloatTy - : Sema::EltwiseBuiltinArgTyRestriction::None)) + Sema::EltwiseBuiltinArgTyRestriction::None)) return true; break; } case Builtin::BI__builtin_hlsl_cross: { if (SemaRef.checkArgCount(TheCall, 2)) return true; - if (CheckVectorElementCallArgs(&SemaRef, TheCall)) + + // ensure args are a half3 or float3 + if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall, + CheckFloatOrHalfVecRepresentation)) return true; - if (CheckFloatOrHalfRepresentations(&SemaRef, TheCall)) + if (CheckAllArgsHaveSameType(&SemaRef, TheCall)) return true; // ensure both args have 3 elements int NumElementsArg1 = @@ -2507,13 +2444,9 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { break; } case Builtin::BI__builtin_hlsl_dot: { - if (SemaRef.checkArgCount(TheCall, 2)) - return true; - if (CheckVectorElementCallArgs(&SemaRef, TheCall)) - return true; if (SemaRef.BuiltinVectorToScalarMath(TheCall)) return true; - if (CheckNoDoubleVectors(&SemaRef, TheCall)) + if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall, CheckNoDoubleVectors)) return true; break; } @@ -2560,8 +2493,15 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { } case Builtin::BI__builtin_hlsl_elementwise_saturate: case Builtin::BI__builtin_hlsl_elementwise_rcp: { - if (CheckAllArgsHaveFloatRepresentation(&SemaRef, TheCall)) + if (SemaRef.checkArgCount(TheCall, 1)) return true; + if (!TheCall->getArg(0) + ->getType() + ->hasFloatingRepresentation()) // half or float or double + return SemaRef.Diag(TheCall->getArg(0)->getBeginLoc(), + diag::err_builtin_invalid_arg_type) + << /* ordinal */ 1 << /* scalar or vector */ 5 << /* no int */ 0 + << /* fp */ 1 << TheCall->getArg(0)->getType(); if (SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall)) return true; break; @@ -2570,14 +2510,20 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { case Builtin::BI__builtin_hlsl_elementwise_radians: case Builtin::BI__builtin_hlsl_elementwise_rsqrt: case Builtin::BI__builtin_hlsl_elementwise_frac: { - if (CheckFloatOrHalfRepresentations(&SemaRef, TheCall)) + if (SemaRef.checkArgCount(TheCall, 1)) + return true; + if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall, + CheckFloatOrHalfRepresentation)) return true; if (SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall)) return true; break; } case Builtin::BI__builtin_hlsl_elementwise_isinf: { - if (CheckFloatOrHalfRepresentations(&SemaRef, TheCall)) + if (SemaRef.checkArgCount(TheCall, 1)) + return true; + if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall, + CheckFloatOrHalfRepresentation)) return true; if (SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall)) return true; @@ -2587,34 +2533,28 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { case Builtin::BI__builtin_hlsl_lerp: { if (SemaRef.checkArgCount(TheCall, 3)) return true; - if (CheckAnyScalarOrVector(&SemaRef, TheCall, 0) || - CheckAllArgsHaveSameType(&SemaRef, TheCall)) + if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall, + CheckFloatOrHalfRepresentation)) return true; - if (SemaRef.BuiltinElementwiseTernaryMath(TheCall)) + if (CheckAllArgsHaveSameType(&SemaRef, TheCall)) return true; - if (CheckFloatOrHalfRepresentations(&SemaRef, TheCall)) + if (SemaRef.BuiltinElementwiseTernaryMath(TheCall)) return true; break; } case Builtin::BI__builtin_hlsl_mad: { - if (SemaRef.checkArgCount(TheCall, 3)) - return true; - if (CheckVectorElementCallArgs(&SemaRef, TheCall)) - return true; if (SemaRef.BuiltinElementwiseTernaryMath( TheCall, /*ArgTyRestr=*/ - TheCall->getArg(0)->getType()->hasFloatingRepresentation() - ? Sema::EltwiseBuiltinArgTyRestriction::FloatTy - : Sema::EltwiseBuiltinArgTyRestriction::None)) + Sema::EltwiseBuiltinArgTyRestriction::None)) return true; break; } case Builtin::BI__builtin_hlsl_normalize: { - if (CheckFloatOrHalfRepresentations(&SemaRef, TheCall)) - return true; if (SemaRef.checkArgCount(TheCall, 1)) return true; - + if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall, + CheckFloatOrHalfRepresentation)) + return true; ExprResult A = TheCall->getArg(0); QualType ArgTyA = A.get()->getType(); // return type is the same as the input type @@ -2622,17 +2562,19 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { break; } case Builtin::BI__builtin_hlsl_elementwise_sign: { - if (CheckFloatingOrIntRepresentation(&SemaRef, TheCall)) - return true; if (SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall)) return true; + if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall, + CheckFloatingOrIntRepresentation)) + return true; SetElementTypeAsReturnType(&SemaRef, TheCall, getASTContext().IntTy); break; } case Builtin::BI__builtin_hlsl_step: { if (SemaRef.checkArgCount(TheCall, 2)) return true; - if (CheckFloatOrHalfRepresentations(&SemaRef, TheCall)) + if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall, + CheckFloatOrHalfRepresentation)) return true; ExprResult A = TheCall->getArg(0); @@ -2659,7 +2601,10 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { // Note these are llvm builtins that we want to catch invalid intrinsic // generation. Normal handling of these builitns will occur elsewhere. case Builtin::BI__builtin_elementwise_bitreverse: { - if (CheckUnsignedIntRepresentation(&SemaRef, TheCall)) + // does not include a check for number of arguments + // because that is done previously + if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall, + CheckUnsignedIntRepresentation)) return true; break; } @@ -2738,7 +2683,8 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { case Builtin::BI__builtin_elementwise_tan: case Builtin::BI__builtin_elementwise_tanh: case Builtin::BI__builtin_elementwise_trunc: { - if (CheckFloatOrHalfRepresentations(&SemaRef, TheCall)) + if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall, + CheckFloatOrHalfRepresentation)) return true; break; } diff --git a/clang/test/SemaHLSL/BuiltIns/AddUint64-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/AddUint64-errors.hlsl index 1f9e92da90ca5..b4ef0550bf88a 100644 --- a/clang/test/SemaHLSL/BuiltIns/AddUint64-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/AddUint64-errors.hlsl @@ -22,7 +22,7 @@ uint2 test_bad_num_arg_elements(uint3 a, uint3 b) { uint2 test_scalar_arg_type(uint a) { return __builtin_hlsl_adduint64(a, a); - // expected-error@-1 {{all arguments to '__builtin_hlsl_adduint64' must be vectors}} + // expected-error@-1 {{1st argument must be a vector of unsigned integer types (was 'uint' (aka 'unsigned int'))}} } uint2 test_uint64_args(uint16_t2 a) { @@ -32,7 +32,7 @@ uint2 test_uint64_args(uint16_t2 a) { uint2 test_signed_integer_args(int2 a, int2 b) { return __builtin_hlsl_adduint64(a, b); -// expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values)}} +// expected-error@-1 {{1st argument must be a vector of unsigned integer types (was 'int2' (aka 'vector<int, 2>'))}} } struct S { @@ -41,6 +41,6 @@ struct S { uint2 test_incorrect_arg_type(S a) { return __builtin_hlsl_adduint64(a, a); - // expected-error@-1 {{passing 'S' to parameter of incompatible type 'unsigned int'}} + // expected-error@-1 {{1st argument must be a vector of unsigned integer types (was 'S')}} } diff --git a/clang/test/SemaHLSL/BuiltIns/asdouble-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/asdouble-errors.hlsl index c6b57c76a1e2b..f658c335b9582 100644 --- a/clang/test/SemaHLSL/BuiltIns/asdouble-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/asdouble-errors.hlsl @@ -14,3 +14,13 @@ double test_too_many_arg(uint p0) { return __builtin_hlsl_asdouble(p0, p0, p0); // expected-error@-1 {{too many arguments to function call, expected 2, have 3}} } + +double test_non_matching(uint p0, uint2 p1) { + return __builtin_hlsl_asdouble(p0, p1); + // expected-error@-1 {{all arguments to '__builtin_hlsl_asdouble' must have the same type}} +} + +double test_non_uint(uint64_t p0) { + return __builtin_hlsl_asdouble(p0, p0); + // expected-error@-1 {{invalid operand of type 'uint64_t' (aka 'unsigned long') where 'unsigned int' or a vector of such type is required}} +} diff --git a/clang/test/SemaHLSL/BuiltIns/clamp-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/clamp-errors.hlsl index fba7820e4f4df..93e37075773f5 100644 --- a/clang/test/SemaHLSL/BuiltIns/clamp-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/clamp-errors.hlsl @@ -37,7 +37,7 @@ float2 test_scalar_first_arg3(float p0, float2 p1) { float3 test_clamp_vector_size_last_arg_mismatch(float3 p0, float2 p1) { return clamp(p0, p0, p1); - // expected-error@-1 {{all arguments to 'clamp' must have the same type}} + // expected-error@-1 {{arguments are of different types ('vector<[...], 3>' vs 'vector<[...], 2>')}} } typedef float float5 __attribute__((ext_vector_type(5))); @@ -55,7 +55,7 @@ float2 test_clamp_vector_size_ret_mismatch(float3 p0, float3 p1) { float2 test_clamp_builtin_vector_size_first_arg_mismatch(float3 p0, float2 p1) { return __builtin_hlsl_elementwise_clamp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_elementwise_clamp' must have the same type}} + // expected-error@-1 {{arguments are of different types ('vector<[...], 3>' vs 'vector<[...], 2>')}} } float test_clamp_scalar_mismatch(float p0, half p1) { @@ -70,32 +70,32 @@ float2 test_clamp_element_type_mismatch(half2 p0, float2 p1) { float2 test_builtin_clamp_float2_splat(float p0, float2 p1) { return __builtin_hlsl_elementwise_clamp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_elementwise_clamp' must have the same type}} + // expected-error@-1 {{arguments are of different types ('float' vs 'float2' (aka 'vector<float, 2>'))}} } float3 test_builtin_clamp_float3_splat(float p0, float3 p1) { return __builtin_hlsl_elementwise_clamp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_elementwise_clamp' must have the same type}} + // expected-error@-1 {{arguments are of different types ('float' vs 'float3' (aka 'vector<float, 3>'))}} } float4 test_builtin_clamp_float4_splat(float p0, float4 p1) { return __builtin_hlsl_elementwise_clamp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_elementwise_clamp' must have the same type}} + // expected-error@-1 {{arguments are of different types ('float' vs 'float4' (aka 'vector<float, 4>'))}} } float2 test_clamp_float2_int_splat(float2 p0, int p1) { return __builtin_hlsl_elementwise_clamp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_elementwise_clamp' must have the same type}} + // expected-error@-1 {{arguments are of different types ('float2' (aka 'vector<float, 2>') vs 'int')}} } float3 test_clamp_float3_int_splat(float3 p0, int p1) { return __builtin_hlsl_elementwise_clamp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_elementwise_clamp' must have the same type}} + // expected-error@-1 {{arguments are of different types ('float3' (aka 'vector<float, 3>') vs 'int')}} } float2 test_builtin_clamp_int_vect_to_float_vec_promotion(int2 p0, float p1) { return __builtin_hlsl_elementwise_clamp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_elementwise_clamp' must have the same type}} + // expected-error@-1 {{arguments are of different types ('int2' (aka 'vector<int, 2>') vs 'float')}} } float test_builtin_clamp_bool_type_promotion(bool p0) { @@ -105,15 +105,20 @@ float test_builtin_clamp_bool_type_promotion(bool p0) { float builtin_bool_to_float_type_promotion(float p0, bool p1) { return __builtin_hlsl_elementwise_clamp(p0, p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_elementwise_clamp' must have the same type}} + // expected-error@-1 {{3rd argument must be a vector, integer or floating-point type (was 'bool')}} } float builtin_bool_to_float_type_promotion2(bool p0, float p1) { return __builtin_hlsl_elementwise_clamp(p1, p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_elementwise_clamp' must have the same type}} + // expected-error@-1 {{2nd argument must be a vector, integer or floating-point type (was 'bool')}} } float builtin_clamp_int_to_float_promotion(float p0, int p1) { return __builtin_hlsl_elementwise_clamp(p0, p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_elementwise_clamp' must have the same type}} + // expected-error@-1 {{arguments are of different types ('float' vs 'int')}} +} + +float builtin_clamp_reject_array(int Arr[2]) { + return __builtin_hlsl_elementwise_clamp(Arr, Arr, Arr); + // expected-error@-1 {{1st argument must be a vector, integer or floating-point type (was 'int *')}} } diff --git a/clang/test/SemaHLSL/BuiltIns/cross-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/cross-errors.hlsl index 423f5bac9471f..18b645a328041 100644 --- a/clang/test/SemaHLSL/BuiltIns/cross-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/cross-errors.hlsl @@ -15,19 +15,19 @@ void test_too_many_arg(float3 p0) bool builtin_bool_to_float_type_promotion(bool p1) { return __builtin_hlsl_cross(p1, p1); - // expected-error@-1 {{passing 'bool' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a vector of 16 or 32 bit floating-point types (was 'bool')}} } bool builtin_cross_int_to_float_promotion(int p1) { return __builtin_hlsl_cross(p1, p1); - // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a vector of 16 or 32 bit floating-point types (was 'int')}} } bool2 builtin_cross_int2_to_float2_promotion(int2 p1) { return __builtin_hlsl_cross(p1, p1); - // expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} + // expected-error@-1 {{1st argument must be a vector of 16 or 32 bit floating-point types (was 'int2' (aka 'vector<int, 2>'))}} } float2 builtin_cross_float2(float2 p1, float2 p2) @@ -39,5 +39,11 @@ float2 builtin_cross_float2(float2 p1, float2 p2) float3 builtin_cross_float3_int3(float3 p1, int3 p2) { return __builtin_hlsl_cross(p1, p2); + // expected-error@-1 {{2nd argument must be a vector of 16 or 32 bit floating-point types (was 'int3' (aka 'vector<int, 3>'))}} +} + +half3 builtin_cross_same_type(half3 p0, float3 p1) +{ + return __builtin_hlsl_cross(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_cross' must have the same type}} } diff --git a/clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl index 9e981f6973572..637a6eecfb35a 100644 --- a/clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl @@ -12,15 +12,15 @@ float2 test_too_many_arg(float2 p0) { float builtin_bool_to_float_type_promotion(bool p1) { return __builtin_hlsl_elementwise_degrees(p1); - // expected-error@-1 {{passing 'bool' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} } float builtin_degrees_int_to_float_promotion(int p1) { return __builtin_hlsl_elementwise_degrees(p1); - // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} } float2 builtin_degrees_int2_to_float2_promotion(int2 p1) { return __builtin_hlsl_elementwise_degrees(p1); - // expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int2' (aka 'vector<int, 2>'))}} } diff --git a/clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl index d8a7e0c640b68..606194692931f 100644 --- a/clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl @@ -17,12 +17,12 @@ float test_dot_no_second_arg(float2 p0) { float test_dot_vector_size_mismatch(float3 p0, float2 p1) { return dot(p0, p1); - // expected-error@-1 {{all arguments to 'dot' must have the same type}} + // expected-error@-1 {{arguments are of different types ('vector<[...], 3>' vs 'vector<[...], 2>')}} } float test_dot_builtin_vector_size_mismatch(float3 p0, float2 p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}} + // expected-error@-1 {{arguments are of different types ('vector<[...], 3>' vs 'vector<[...], 2>')}} } float test_dot_scalar_mismatch(float p0, int p1) { @@ -38,70 +38,70 @@ float test_dot_element_type_mismatch(int2 p0, float2 p1) { //NOTE: for all the *_promotion we are intentionally not handling type promotion in builtins float test_builtin_dot_vec_int_to_float_promotion(int2 p0, float2 p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}} + // expected-error@-1 {{arguments are of different types ('vector<int, [...]>' vs 'vector<float, [...]>')}} } int64_t test_builtin_dot_vec_int_to_int64_promotion(int64_t2 p0, int2 p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}} + // expected-error@-1 {{arguments are of different types ('vector<int64_t, [...]>' vs 'vector<int, [...]>')}} } float test_builtin_dot_vec_half_to_float_promotion(float2 p0, half2 p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}} + // expected-error@-1 {{arguments are of different types ('vector<float, [...]>' vs 'vector<half, [...]>')}} } #ifdef __HLSL_ENABLE_16_BIT float test_builtin_dot_vec_int16_to_float_promotion(float2 p0, int16_t2 p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}} + // expected-error@-1 {{arguments are of different types ('vector<float, [...]>' vs 'vector<int16_t, [...]>')}} } half test_builtin_dot_vec_int16_to_half_promotion(half2 p0, int16_t2 p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}} + // expected-error@-1 {{arguments are of different types ('vector<half, [...]>' vs 'vector<int16_t, [...]>')}} } int test_builtin_dot_vec_int16_to_int_promotion(int2 p0, int16_t2 p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}} + // expected-error@-1 {{arguments are of different types ('vector<int, [...]>' vs 'vector<int16_t, [...]>')}} } int64_t test_builtin_dot_vec_int16_to_int64_promotion(int64_t2 p0, int16_t2 p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}} + // expected-error@-1 {{arguments are of different types ('vector<int64_t, [...]>' vs 'vector<int16_t, [...]>')}} } #endif float test_builtin_dot_float2_splat(float p0, float2 p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}} + // expected-error@-1 {{arguments are of different types ('float' vs 'float2' (aka 'vector<float, 2>'))}} } float test_builtin_dot_float3_splat(float p0, float3 p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}} + // expected-error@-1 {{arguments are of different types ('float' vs 'float3' (aka 'vector<float, 3>'))}} } float test_builtin_dot_float4_splat(float p0, float4 p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}} + // expected-error@-1 {{arguments are of different types ('float' vs 'float4' (aka 'vector<float, 4>'))}} } float test_dot_float2_int_splat(float2 p0, int p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}} + // expected-error@-1 {{arguments are of different types ('float2' (aka 'vector<float, 2>') vs 'int')}} } float test_dot_float3_int_splat(float3 p0, int p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}} + // expected-error@-1 {{arguments are of different types ('float3' (aka 'vector<float, 3>') vs 'int')}} } float test_builtin_dot_int_vect_to_float_vec_promotion(int2 p0, float p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}} + // expected-error@-1 {{arguments are of different types ('int2' (aka 'vector<int, 2>') vs 'float')}} } int test_builtin_dot_bool_type_promotion(bool p0, float p1) { @@ -113,9 +113,10 @@ double test_dot_double(double2 p0, double2 p1) { return dot(p0, p1); // expected-error@-1 {{call to 'dot' is ambiguous}} } + double test_dot_double_builtin(double2 p0, double2 p1) { return __builtin_hlsl_dot(p0, p1); - // expected-error@-1 {{passing 'double2' (aka 'vector<double, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} + // expected-error@-1 {{1st argument must be a scalar floating-point type (was 'double2' (aka 'vector<double, 2>'))}} } float builtin_bool_to_float_type_promotion ( float p0, bool p1 ) { diff --git a/clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl index 81c134e1ce4af..1e277186f22c4 100644 --- a/clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify float test_too_few_arg() { return __builtin_hlsl_elementwise_frac(); @@ -13,16 +13,16 @@ float2 test_too_many_arg(float2 p0) { float builtin_bool_to_float_type_promotion(bool p1) { return __builtin_hlsl_elementwise_frac(p1); - // expected-error@-1 {{passing 'bool' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} } float builtin_frac_int_to_float_promotion(int p1) { return __builtin_hlsl_elementwise_frac(p1); - // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} } float2 builtin_frac_int2_to_float2_promotion(int2 p1) { return __builtin_hlsl_elementwise_frac(p1); - // expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int2' (aka 'vector<int, 2>'))}} } diff --git a/clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl index 763368153e38f..bf044797c3acb 100644 --- a/clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl @@ -23,10 +23,10 @@ double test_double_builtin(double p0) { return TEST_FUNC(p0); - // expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double')}} } double2 test_vec_double_builtin(double2 p0) { return TEST_FUNC(p0); - // expected-error@-1 {{passing 'double2' (aka 'vector<double, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double2' (aka 'vector<double, 2>'))}} } diff --git a/clang/test/SemaHLSL/BuiltIns/half-float-only-errors2.hlsl b/clang/test/SemaHLSL/BuiltIns/half-float-only-errors2.hlsl index bfbd8b28257a3..e45ca106aa7dc 100644 --- a/clang/test/SemaHLSL/BuiltIns/half-float-only-errors2.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/half-float-only-errors2.hlsl @@ -4,10 +4,10 @@ double test_double_builtin(double p0, double p1) { return TEST_FUNC(p0, p1); - // expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double')}} } double2 test_vec_double_builtin(double2 p0, double2 p1) { return TEST_FUNC(p0, p1); - // expected-error@-1 {{passing 'double2' (aka 'vector<double, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double2' (aka 'vector<double, 2>'))}} } diff --git a/clang/test/SemaHLSL/BuiltIns/isinf-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/isinf-errors.hlsl index e2f03812705fd..8d14df91f1409 100644 --- a/clang/test/SemaHLSL/BuiltIns/isinf-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/isinf-errors.hlsl @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify bool test_too_few_arg() { return __builtin_hlsl_elementwise_isinf(); @@ -13,26 +13,26 @@ bool2 test_too_many_arg(float2 p0) { bool builtin_bool_to_float_type_promotion(bool p1) { return __builtin_hlsl_elementwise_isinf(p1); - // expected-error@-1 {passing 'bool' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} } bool builtin_isinf_int_to_float_promotion(int p1) { return __builtin_hlsl_elementwise_isinf(p1); - // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} } bool2 builtin_isinf_int2_to_float2_promotion(int2 p1) { return __builtin_hlsl_elementwise_isinf(p1); - // expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int2' (aka 'vector<int, 2>'))}} } // builtins are variadic functions and so are subject to DefaultVariadicArgumentPromotion half builtin_isinf_half_scalar (half p0) { return __builtin_hlsl_elementwise_isinf (p0); - // expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double')}} } float builtin_isinf_float_scalar ( float p0) { return __builtin_hlsl_elementwise_isinf (p0); - // expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double')}} } diff --git a/clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl index b4734a985f31c..9592d8766dada 100644 --- a/clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl @@ -67,12 +67,12 @@ float2 test_builtin_lerp_float2_splat(float p0, float2 p1) { float2 test_builtin_lerp_float2_splat2(double p0, double2 p1) { return __builtin_hlsl_lerp(p1, p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double2' (aka 'vector<double, 2>'))}} } float2 test_builtin_lerp_float2_splat3(double p0, double2 p1) { return __builtin_hlsl_lerp(p1, p1, p0); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double2' (aka 'vector<double, 2>'))}} } float3 test_builtin_lerp_float3_splat(float p0, float3 p1) { @@ -87,40 +87,40 @@ float4 test_builtin_lerp_float4_splat(float p0, float4 p1) { float2 test_lerp_float2_int_splat(float2 p0, int p1) { return __builtin_hlsl_lerp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} + // expected-error@-1 {{2nd argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} } float3 test_lerp_float3_int_splat(float3 p0, int p1) { return __builtin_hlsl_lerp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} + // expected-error@-1 {{2nd argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} } float2 test_builtin_lerp_int_vect_to_float_vec_promotion(int2 p0, float p1) { return __builtin_hlsl_lerp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int2' (aka 'vector<int, 2>'))}} } float test_builtin_lerp_bool_type_promotion(bool p0) { return __builtin_hlsl_lerp(p0, p0, p0); - // expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'bool')}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} } float builtin_bool_to_float_type_promotion(float p0, bool p1) { return __builtin_hlsl_lerp(p0, p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} + // expected-error@-1 {{3rd argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} } float builtin_bool_to_float_type_promotion2(bool p0, float p1) { return __builtin_hlsl_lerp(p1, p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} + // expected-error@-1 {{2nd argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} } float builtin_lerp_int_to_float_promotion(float p0, int p1) { return __builtin_hlsl_lerp(p0, p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} + // expected-error@-1 {{3rd argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} } float4 test_lerp_int4(int4 p0, int4 p1, int4 p2) { return __builtin_hlsl_lerp(p0, p1, p2); - // expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'int4' (aka 'vector<int, 4>'))}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int4' (aka 'vector<int, 4>'))}} } diff --git a/clang/test/SemaHLSL/BuiltIns/logical-operator-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/logical-operator-errors.hlsl index c314c1b2b83ab..be791e97daca7 100644 --- a/clang/test/SemaHLSL/BuiltIns/logical-operator-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/logical-operator-errors.hlsl @@ -25,3 +25,9 @@ bool test_incorrect_type(int a) return TEST_FUNC(a, a); // expected-error@-1{{invalid operand of type 'int' where 'bool' or a vector of such type is required}} } + +bool test_mismatched_scalars(bool a, int b) +{ + return TEST_FUNC(a, b); + // expected-error@-1{{all arguments to}}{{_builtin_hlsl_or|_builtin_hlsl_and }}{{must have the same type}} +} diff --git a/clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl index 5feb147d1d632..3e9ffb696aeab 100644 --- a/clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected=note,warning float2 test_no_second_arg(float2 p0) { return __builtin_hlsl_mad(p0); @@ -27,7 +27,7 @@ float2 test_mad_vector_size_mismatch(float3 p0, float2 p1) { float2 test_mad_builtin_vector_size_mismatch(float3 p0, float2 p1) { return __builtin_hlsl_mad(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must have the same type}} + // expected-error@-1 {{arguments are of different types ('vector<[...], 3>' vs 'vector<[...], 2>')}} } float test_mad_scalar_mismatch(float p0, half p1) { @@ -42,47 +42,47 @@ float2 test_mad_element_type_mismatch(half2 p0, float2 p1) { float2 test_builtin_mad_float2_splat(float p0, float2 p1) { return __builtin_hlsl_mad(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must be vectors}} + // expected-error@-1 {{arguments are of different types ('double' vs 'float2' (aka 'vector<float, 2>'))}} } float3 test_builtin_mad_float3_splat(float p0, float3 p1) { return __builtin_hlsl_mad(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must be vectors}} + // expected-error@-1 {{arguments are of different types ('double' vs 'float3' (aka 'vector<float, 3>'))}} } float4 test_builtin_mad_float4_splat(float p0, float4 p1) { return __builtin_hlsl_mad(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must be vectors}} + // expected-error@-1 {{arguments are of different types ('double' vs 'float4' (aka 'vector<float, 4>'))}} } float2 test_mad_float2_int_splat(float2 p0, int p1) { return __builtin_hlsl_mad(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must be vectors}} + // expected-error@-1 {{arguments are of different types ('float2' (aka 'vector<float, 2>') vs 'int')}} } float3 test_mad_float3_int_splat(float3 p0, int p1) { return __builtin_hlsl_mad(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must be vectors}} + // expected-error@-1 {{arguments are of different types ('float3' (aka 'vector<float, 3>') vs 'int')}} } float2 test_builtin_mad_int_vect_to_float_vec_promotion(int2 p0, float p1) { return __builtin_hlsl_mad(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_mad' must be vectors}} + // expected-error@-1 {{arguments are of different types ('int2' (aka 'vector<int, 2>') vs 'double')}} } float builtin_bool_to_float_type_promotion(float p0, bool p1) { return __builtin_hlsl_mad(p0, p0, p1); - // expected-error@-1 {{3rd argument must be a scalar or vector of floating-point types (was 'bool')}} + // expected-error@-1 {{3rd argument must be a vector, integer or floating-point type (was 'bool')}} } float builtin_bool_to_float_type_promotion2(bool p0, float p1) { return __builtin_hlsl_mad(p1, p0, p1); - // expected-error@-1 {{2nd argument must be a scalar or vector of floating-point types (was 'bool')}} + // expected-error@-1 {{2nd argument must be a vector, integer or floating-point type (was 'bool')}} } float builtin_mad_int_to_float_promotion(float p0, int p1) { return __builtin_hlsl_mad(p0, p0, p1); - // expected-error@-1 {{3rd argument must be a scalar or vector of floating-point types (was 'int')}} + // expected-error@-1 {{arguments are of different types ('double' vs 'int')}} } int builtin_mad_mixed_enums() { diff --git a/clang/test/SemaHLSL/BuiltIns/normalize-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/normalize-errors.hlsl index fc48c9b2589f7..f339826d2cb96 100644 --- a/clang/test/SemaHLSL/BuiltIns/normalize-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/normalize-errors.hlsl @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -disable-llvm-passes -verify -verify-ignore-unexpected +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -disable-llvm-passes -verify void test_too_few_arg() { @@ -15,17 +15,17 @@ void test_too_many_arg(float2 p0) bool builtin_bool_to_float_type_promotion(bool p1) { return __builtin_hlsl_normalize(p1); - // expected-error@-1 {passing 'bool' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} } bool builtin_normalize_int_to_float_promotion(int p1) { return __builtin_hlsl_normalize(p1); - // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} } bool2 builtin_normalize_int2_to_float2_promotion(int2 p1) { return __builtin_hlsl_normalize(p1); - // expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int2' (aka 'vector<int, 2>'))}} } diff --git a/clang/test/SemaHLSL/BuiltIns/radians-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/radians-errors.hlsl index 1d315c486d725..dbffce226b54e 100644 --- a/clang/test/SemaHLSL/BuiltIns/radians-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/radians-errors.hlsl @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify float test_too_few_arg() { return __builtin_hlsl_elementwise_radians(); @@ -12,16 +12,16 @@ float2 test_too_many_arg(float2 p0) { float builtin_bool_to_float_type_promotion(bool p1) { return __builtin_hlsl_elementwise_radians(p1); - // expected-error@-1 {passing 'bool' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} } float builtin_radians_int_to_float_promotion(int p1) { return __builtin_hlsl_elementwise_radians(p1); - // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} } float2 builtin_radians_int2_to_float2_promotion(int2 p1) { return __builtin_hlsl_elementwise_radians(p1); - // expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int2' (aka 'vector<int, 2>'))}} } diff --git a/clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl index 6bc5b9bed3047..01876240e82d0 100644 --- a/clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/rcp-errors.hlsl @@ -1,5 +1,4 @@ - -// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify float test_too_few_arg() { return __builtin_hlsl_elementwise_rcp(); @@ -13,15 +12,15 @@ float2 test_too_many_arg(float2 p0) { float builtin_bool_to_float_type_promotion(bool p1) { return __builtin_hlsl_elementwise_rcp(p1); - // expected-error@-1 {passing 'bool' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'bool')}} } float builtin_rcp_int_to_float_promotion(int p1) { return __builtin_hlsl_elementwise_rcp(p1); - // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'int')}} } float2 builtin_rcp_int2_to_float2_promotion(int2 p1) { return __builtin_hlsl_elementwise_rcp(p1); - // expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} + // expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'int2' (aka 'vector<int, 2>'))}} } diff --git a/clang/test/SemaHLSL/BuiltIns/reversebits-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/reversebits-errors.hlsl index 76ebe66d0d119..1ac275beba642 100644 --- a/clang/test/SemaHLSL/BuiltIns/reversebits-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/reversebits-errors.hlsl @@ -8,5 +8,5 @@ double2 test_int_builtin(double2 p0) { int2 test_int_builtin(int2 p0) { return __builtin_elementwise_bitreverse(p0); - // expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values)}} + // expected-error@-1 {{1st argument must be a scalar or vector of unsigned integer types (was 'int2' (aka 'vector<int, 2>'))}} } diff --git a/clang/test/SemaHLSL/BuiltIns/rsqrt-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/rsqrt-errors.hlsl index d528b4b5a3989..1f81c51207bc3 100644 --- a/clang/test/SemaHLSL/BuiltIns/rsqrt-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/rsqrt-errors.hlsl @@ -1,5 +1,4 @@ - -// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify float test_too_few_arg() { return __builtin_hlsl_elementwise_rsqrt(); @@ -13,20 +12,20 @@ float2 test_too_many_arg(float2 p0) { float builtin_bool_to_float_type_promotion(bool p1) { return __builtin_hlsl_elementwise_rsqrt(p1); - // expected-error@-1 {{passing 'bool' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} } float builtin_rsqrt_int_to_float_promotion(int p1) { return __builtin_hlsl_elementwise_rsqrt(p1); - // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} } float2 builtin_rsqrt_int2_to_float2_promotion(int2 p1) { return __builtin_hlsl_elementwise_rsqrt(p1); - // expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int2' (aka 'vector<int, 2>'))}} } double builtin_rsqrt_double(double p0) { return __builtin_hlsl_elementwise_rsqrt(p0); - // expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double')}} } diff --git a/clang/test/SemaHLSL/BuiltIns/step-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/step-errors.hlsl index 823585201ca62..cfceb0623451f 100644 --- a/clang/test/SemaHLSL/BuiltIns/step-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/step-errors.hlsl @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -disable-llvm-passes -verify -verify-ignore-unexpected +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -disable-llvm-passes -verify void test_too_few_arg() { @@ -15,17 +15,17 @@ void test_too_many_arg(float2 p0) bool builtin_bool_to_float_type_promotion(bool p1) { return __builtin_hlsl_step(p1, p1); - // expected-error@-1 {passing 'bool' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} } bool builtin_step_int_to_float_promotion(int p1) { return __builtin_hlsl_step(p1, p1); - // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} } bool2 builtin_step_int2_to_float2_promotion(int2 p1) { return __builtin_hlsl_step(p1, p1); - // expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} + // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int2' (aka 'vector<int, 2>'))}} } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits