[clang] [clang][Sema][NFC] Consolidate checking for SPIR-V builtins (PR #239060)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 4 18:51:48 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Chen Miao (ChenMiaoi)
<details>
<summary>Changes</summary>
Share identical semantic checks between smoothstep and faceforward, and between distance and reflect. Preserve diagnostics and select the result type separately for distance and reflect.
---
Full diff: https://github.com/llvm/llvm-project/pull/239060.diff
1 Files Affected:
- (modified) clang/lib/Sema/SemaSPIRV.cpp (+6-56)
``````````diff
diff --git a/clang/lib/Sema/SemaSPIRV.cpp b/clang/lib/Sema/SemaSPIRV.cpp
index 8c2af5053bde2..51ad1414b8f5b 100644
--- a/clang/lib/Sema/SemaSPIRV.cpp
+++ b/clang/lib/Sema/SemaSPIRV.cpp
@@ -196,7 +196,8 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(const TargetInfo &TI,
}
switch (BuiltinID) {
- case SPIRV::BI__builtin_spirv_distance: {
+ case SPIRV::BI__builtin_spirv_distance:
+ case SPIRV::BI__builtin_spirv_reflect: {
if (SemaRef.checkArgCount(TheCall, 2))
return true;
@@ -224,8 +225,9 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(const TargetInfo &TI,
return true;
}
- QualType RetTy = VTyA->getElementType();
- TheCall->setType(RetTy);
+ TheCall->setType(BuiltinID == SPIRV::BI__builtin_spirv_distance
+ ? VTyA->getElementType()
+ : ArgTyA);
break;
}
case SPIRV::BI__builtin_spirv_length: {
@@ -246,38 +248,6 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(const TargetInfo &TI,
TheCall->setType(RetTy);
break;
}
- case SPIRV::BI__builtin_spirv_reflect: {
- if (SemaRef.checkArgCount(TheCall, 2))
- return true;
-
- ExprResult A = TheCall->getArg(0);
- QualType ArgTyA = A.get()->getType();
- auto *VTyA = ArgTyA->getAs<VectorType>();
- if (VTyA == nullptr) {
- SemaRef.Diag(A.get()->getBeginLoc(),
- diag::err_typecheck_convert_incompatible)
- << ArgTyA
- << SemaRef.Context.getVectorType(ArgTyA, 2, VectorKind::Generic) << 1
- << 0 << 0;
- return true;
- }
-
- ExprResult B = TheCall->getArg(1);
- QualType ArgTyB = B.get()->getType();
- auto *VTyB = ArgTyB->getAs<VectorType>();
- if (VTyB == nullptr) {
- SemaRef.Diag(A.get()->getBeginLoc(),
- diag::err_typecheck_convert_incompatible)
- << ArgTyB
- << SemaRef.Context.getVectorType(ArgTyB, 2, VectorKind::Generic) << 1
- << 0 << 0;
- return true;
- }
-
- QualType RetTy = ArgTyA;
- TheCall->setType(RetTy);
- break;
- }
case SPIRV::BI__builtin_spirv_refract: {
if (SemaRef.checkArgCount(TheCall, 3))
return true;
@@ -315,27 +285,7 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(const TargetInfo &TI,
TheCall->setType(RetTy);
break;
}
- case SPIRV::BI__builtin_spirv_smoothstep: {
- if (SemaRef.checkArgCount(TheCall, 3))
- return true;
-
- // Check if first argument has floating representation
- ExprResult A = TheCall->getArg(0);
- QualType ArgTyA = A.get()->getType();
- if (!ArgTyA->hasFloatingRepresentation()) {
- SemaRef.Diag(A.get()->getBeginLoc(), diag::err_builtin_invalid_arg_type)
- << /* ordinal */ 1 << /* scalar or vector */ 5 << /* no int */ 0
- << /* fp */ 1 << ArgTyA;
- return true;
- }
-
- if (CheckAllArgsHaveSameType(&SemaRef, TheCall))
- return true;
-
- QualType RetTy = ArgTyA;
- TheCall->setType(RetTy);
- break;
- }
+ case SPIRV::BI__builtin_spirv_smoothstep:
case SPIRV::BI__builtin_spirv_faceforward: {
if (SemaRef.checkArgCount(TheCall, 3))
return true;
``````````
</details>
https://github.com/llvm/llvm-project/pull/239060
More information about the cfe-commits
mailing list