1010
1111#include " clang/Sema/SemaSPIRV.h"
1212#include " clang/Basic/TargetBuiltins.h"
13+ #include " clang/Sema/Common.h"
1314#include " clang/Sema/Sema.h"
15+ #include < utility>
1416
1517namespace clang {
1618
@@ -20,54 +22,12 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(unsigned BuiltinID,
2022 CallExpr *TheCall) {
2123 switch (BuiltinID) {
2224 case SPIRV::BI__builtin_spirv_distance: {
23- if (SemaRef.checkArgCount (TheCall, 2 ))
24- return true ;
25-
26- ExprResult A = TheCall->getArg (0 );
27- QualType ArgTyA = A.get ()->getType ();
28- auto *VTyA = ArgTyA->getAs <VectorType>();
29- if (VTyA == nullptr ) {
30- SemaRef.Diag (A.get ()->getBeginLoc (),
31- diag::err_typecheck_convert_incompatible)
32- << ArgTyA
33- << SemaRef.Context .getVectorType (ArgTyA, 2 , VectorKind::Generic) << 1
34- << 0 << 0 ;
35- return true ;
36- }
37-
38- ExprResult B = TheCall->getArg (1 );
39- QualType ArgTyB = B.get ()->getType ();
40- auto *VTyB = ArgTyB->getAs <VectorType>();
41- if (VTyB == nullptr ) {
42- SemaRef.Diag (A.get ()->getBeginLoc (),
43- diag::err_typecheck_convert_incompatible)
44- << ArgTyB
45- << SemaRef.Context .getVectorType (ArgTyB, 2 , VectorKind::Generic) << 1
46- << 0 << 0 ;
47- return true ;
48- }
49-
50- QualType RetTy = VTyA->getElementType ();
51- TheCall->setType (RetTy);
52- break ;
25+ return CheckAllArgTypesAreCorrect (&SemaRef, TheCall, std::nullopt ,
26+ std::make_pair (2 , 2 ));
5327 }
5428 case SPIRV::BI__builtin_spirv_length: {
55- if (SemaRef.checkArgCount (TheCall, 1 ))
56- return true ;
57- ExprResult A = TheCall->getArg (0 );
58- QualType ArgTyA = A.get ()->getType ();
59- auto *VTy = ArgTyA->getAs <VectorType>();
60- if (VTy == nullptr ) {
61- SemaRef.Diag (A.get ()->getBeginLoc (),
62- diag::err_typecheck_convert_incompatible)
63- << ArgTyA
64- << SemaRef.Context .getVectorType (ArgTyA, 2 , VectorKind::Generic) << 1
65- << 0 << 0 ;
66- return true ;
67- }
68- QualType RetTy = VTy->getElementType ();
69- TheCall->setType (RetTy);
70- break ;
29+ return CheckAllArgTypesAreCorrect (&SemaRef, TheCall, std::nullopt ,
30+ std::make_pair (1 , 2 ));
7131 }
7232 }
7333 return false ;
0 commit comments