================
@@ -2245,6 +2245,36 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 
     break;
   }
+  case Builtin::BI__builtin_hlsl_and: {
+    if (SemaRef.checkArgCount(TheCall, 2))
+      return true;
+    if (CheckVectorElementCallArgs(&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");
+
+    // check that the arguments are bools or, if vectors,
+    // vectors of bools
+    QualType ArgTy = TheCall->getArg(0)->getType();
+    if (const auto *VecTy = ArgTy->getAs<VectorType>()) {
+      ArgTy = VecTy->getElementType();
+    }
+    if (!getASTContext().hasSameUnqualifiedType(ArgTy,
----------------
farzonl wrote:

Please refer back to the change I proposed. Expected types would refer back to 
the float and half overloads we support for cross in `hlsl_intrinsics.h`. This 
change would address your concerns about cross and do diagnostic errors for 
both half and float. This isn’t any less usable than what you want to do. Its 
literally the same diagnostic just done in one place where we can improve every 
builtin. Further it would allow us to consolidate CheckScalarOrVector.
> ```c++
> static bool CheckArgTypeIsCorrect(
>     Sema *S, Expr *Arg, llvm::SmallVectorImpl<QualType> ExpectedTypes,
>     llvm::function_ref<bool(clang::QualType PassedType)> Check) {
>   QualType PassedType = Arg->getType();
>   if (Check(PassedType)) {
>     for (const clang::QualType &ExpectedType : ExpectedTypes)
>       S->Diag(Arg->getBeginLoc(),
>             diag::err_typecheck_expect_scalar_or_vector)
>         << PassedType << ExpectedType;
>     return true;
>   }
>   return false;
> }
> ```

https://github.com/llvm/llvm-project/pull/127098
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to