[clang] [HLSL] Update Sema Checking Diagnostics for builtins (PR #138429)

Sarah Spall via cfe-commits cfe-commits at lists.llvm.org
Thu May 15 12:35:35 PDT 2025


================
@@ -2446,37 +2376,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)) // only check for uint
+      return true;
+    if (CheckScalarOrVector(&SemaRef, TheCall, SemaRef.Context.UnsignedIntTy,
+                            1)) // only check for uint
+      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
----------------
spall wrote:

Yes this is a weird one to typecheck. The comment was really meant to just refer to that entire block of code below it, rather than just the CheckAllArgTypesAreCorrect.

https://github.com/llvm/llvm-project/pull/138429


More information about the cfe-commits mailing list