[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)
Farzon Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 17 09:51:10 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,
----------------
farzonl wrote:
Well for one we only emit one diagnostic for `CheckScalarOrVector` even though there are multiple overloads, the example i give lets us specify a diagnostic per overload like you mentioned in the `cross` example for half or float which was one of the issue you raised earlier.
Second issue I think we can do better with how we are using `CheckScalarOrVector` for example see `BI__builtin_hlsl_elementwise_splitdouble` We could reduce the 3 function calls here to one if we take qual types as a list.
```cpp
if (CheckScalarOrVector(&SemaRef, TheCall, SemaRef.Context.DoubleTy, 0) ||
CheckScalarOrVector(&SemaRef, TheCall, SemaRef.Context.UnsignedIntTy,
1) ||
CheckScalarOrVector(&SemaRef, TheCall, SemaRef.Context.UnsignedIntTy,
2))
```
https://github.com/llvm/llvm-project/pull/127098
More information about the cfe-commits
mailing list