[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
Chris B via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 15 16:36:20 PST 2025
================
@@ -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,
----------------
llvm-beanz wrote:
Okay... I agree we should discuss this this week, but maybe not for the reason you do. The current diagnostics are _terrible_. We need to do better.
See: https://godbolt.org/z/TP3bTGWGc
Calling `__builtin_hlsl_cross` with `int4` arguments should not give the error message:
>error: passing 'int4' (aka 'vector<int, 4>') to parameter of incompatible type '__attribute__((__vector_size__(4 * sizeof(float)))) float' (vector of 4 'float' values)
Besides the fact that we've lost all type sugaring, it isn't actually helpful because it doesn't properly convey the real constraints of the builtin.
https://github.com/llvm/llvm-project/pull/127098
More information about the cfe-commits
mailing list