@@ -2485,6 +2485,22 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
24852485 VecTy->getElementType ()->isHalfType ());
24862486 return true ;
24872487 };
2488+
2489+ auto CheckArgTypeIsCorrect = [](
2490+ Sema *S, Expr *Arg, QualType ExpectedType,
2491+ llvm::function_ref<bool (clang::QualType PassedType)> Check) -> bool {
2492+ QualType PassedType = Arg->getType ();
2493+ if (Check (PassedType)) {
2494+ if (auto *VecTyA = PassedType->getAs <VectorType>())
2495+ ExpectedType = S->Context .getVectorType (
2496+ ExpectedType, VecTyA->getNumElements (), VecTyA->getVectorKind ());
2497+ S->Diag (Arg->getBeginLoc (), diag::err_typecheck_convert_incompatible)
2498+ << PassedType << ExpectedType << 1 << 0 << 0 ;
2499+ return true ;
2500+ }
2501+ return false ;
2502+ };
2503+
24882504 if (CheckArgTypeIsCorrect (&SemaRef, TheCall->getArg (0 ),
24892505 SemaRef.getASTContext ().HalfTy ,
24902506 checkHalfVectorOfSize2))
@@ -2494,8 +2510,12 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
24942510 checkHalfVectorOfSize2))
24952511 return true ;
24962512
2497- if (CheckArgTypeMatches (&SemaRef, TheCall->getArg (2 ), SemaRef.getASTContext ().FloatTy ))
2513+ if (!SemaRef.getASTContext ().hasSameUnqualifiedType (TheCall->getArg (2 )->getType (), SemaRef.getASTContext ().FloatTy )) {
2514+ SemaRef.Diag (TheCall->getArg (2 )->getBeginLoc (), diag::err_typecheck_convert_incompatible)
2515+ << TheCall->getArg (2 )->getType () << SemaRef.getASTContext ().FloatTy << 1 << 0 << 0 ;
24982516 return true ;
2517+ }
2518+
24992519 TheCall->setType (SemaRef.getASTContext ().FloatTy );
25002520 break ;
25012521 }
0 commit comments