[clang] 389f009 - [NFC] Sema: use checkArgCount instead of custom checking
JF Bastien via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 28 13:41:45 PDT 2020
Author: JF Bastien
Date: 2020-07-28T13:41:06-07:00
New Revision: 389f009c5757cf09c0b2d77a15b3b541fb0f2a1c
URL: https://github.com/llvm/llvm-project/commit/389f009c5757cf09c0b2d77a15b3b541fb0f2a1c
DIFF: https://github.com/llvm/llvm-project/commit/389f009c5757cf09c0b2d77a15b3b541fb0f2a1c.diff
LOG: [NFC] Sema: use checkArgCount instead of custom checking
As requested in D79279.
Differential Revision: https://reviews.llvm.org/D84666
Added:
Modified:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-ppc-error.c
clang/test/SemaOpenCL/to_addr_builtin.cl
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index adfd4c207da8..8093e7ed3fbe 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9724,8 +9724,6 @@ def err_opencl_block_ref_block : Error<
"cannot refer to a block inside block">;
// OpenCL v2.0 s6.13.9 - Address space qualifier functions.
-def err_opencl_builtin_to_addr_arg_num : Error<
- "invalid number of arguments to function: %0">;
def err_opencl_builtin_to_addr_invalid_arg : Error<
"invalid argument %0 to function: %1, expecting a generic pointer argument">;
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 77d5f3ff816e..ccdb277dda1a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1274,11 +1274,8 @@ static bool SemaBuiltinPipePackets(Sema &S, CallExpr *Call) {
// \return True if a semantic error has been found, false otherwise.
static bool SemaOpenCLBuiltinToAddr(Sema &S, unsigned BuiltinID,
CallExpr *Call) {
- if (Call->getNumArgs() != 1) {
- S.Diag(Call->getBeginLoc(), diag::err_opencl_builtin_to_addr_arg_num)
- << Call->getDirectCallee() << Call->getSourceRange();
+ if (checkArgCount(S, Call, 1))
return true;
- }
auto RT = Call->getArg(0)->getType();
if (!RT->isPointerType() || RT->getPointeeType()
@@ -5572,21 +5569,8 @@ bool Sema::SemaBuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) {
if (checkVAStartABI(*this, BuiltinID, Fn))
return true;
- if (TheCall->getNumArgs() > 2) {
- Diag(TheCall->getArg(2)->getBeginLoc(),
- diag::err_typecheck_call_too_many_args)
- << 0 /*function call*/ << 2 << TheCall->getNumArgs()
- << Fn->getSourceRange()
- << SourceRange(TheCall->getArg(2)->getBeginLoc(),
- (*(TheCall->arg_end() - 1))->getEndLoc());
+ if (checkArgCount(*this, TheCall, 2))
return true;
- }
-
- if (TheCall->getNumArgs() < 2) {
- return Diag(TheCall->getEndLoc(),
- diag::err_typecheck_call_too_few_args_at_least)
- << 0 /*function call*/ << 2 << TheCall->getNumArgs();
- }
// Type-check the first argument normally.
if (checkBuiltinArgument(*this, TheCall, 0))
@@ -5696,15 +5680,8 @@ bool Sema::SemaBuiltinVAStartARMMicrosoft(CallExpr *Call) {
/// SemaBuiltinUnorderedCompare - Handle functions like __builtin_isgreater and
/// friends. This is declared to take (...), so we have to check everything.
bool Sema::SemaBuiltinUnorderedCompare(CallExpr *TheCall) {
- if (TheCall->getNumArgs() < 2)
- return Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args)
- << 0 << 2 << TheCall->getNumArgs() /*function call*/;
- if (TheCall->getNumArgs() > 2)
- return Diag(TheCall->getArg(2)->getBeginLoc(),
- diag::err_typecheck_call_too_many_args)
- << 0 /*function call*/ << 2 << TheCall->getNumArgs()
- << SourceRange(TheCall->getArg(2)->getBeginLoc(),
- (*(TheCall->arg_end() - 1))->getEndLoc());
+ if (checkArgCount(*this, TheCall, 2))
+ return true;
ExprResult OrigArg0 = TheCall->getArg(0);
ExprResult OrigArg1 = TheCall->getArg(1);
@@ -5742,15 +5719,8 @@ bool Sema::SemaBuiltinUnorderedCompare(CallExpr *TheCall) {
/// to check everything. We expect the last argument to be a floating point
/// value.
bool Sema::SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs) {
- if (TheCall->getNumArgs() < NumArgs)
- return Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args)
- << 0 << NumArgs << TheCall->getNumArgs() /*function call*/;
- if (TheCall->getNumArgs() > NumArgs)
- return Diag(TheCall->getArg(NumArgs)->getBeginLoc(),
- diag::err_typecheck_call_too_many_args)
- << 0 /*function call*/ << NumArgs << TheCall->getNumArgs()
- << SourceRange(TheCall->getArg(NumArgs)->getBeginLoc(),
- (*(TheCall->arg_end() - 1))->getEndLoc());
+ if (checkArgCount(*this, TheCall, NumArgs))
+ return true;
// __builtin_fpclassify is the only case where NumArgs != 1, so we can count
// on all preceding parameters just being int. Try all of those.
@@ -5854,17 +5824,8 @@ bool Sema::SemaBuiltinComplex(CallExpr *TheCall) {
// vector short vec_xxsldwi(vector short, vector short, int);
bool Sema::SemaBuiltinVSX(CallExpr *TheCall) {
unsigned ExpectedNumArgs = 3;
- if (TheCall->getNumArgs() < ExpectedNumArgs)
- return Diag(TheCall->getEndLoc(),
- diag::err_typecheck_call_too_few_args_at_least)
- << 0 /*function call*/ << ExpectedNumArgs << TheCall->getNumArgs()
- << TheCall->getSourceRange();
-
- if (TheCall->getNumArgs() > ExpectedNumArgs)
- return Diag(TheCall->getEndLoc(),
- diag::err_typecheck_call_too_many_args_at_most)
- << 0 /*function call*/ << ExpectedNumArgs << TheCall->getNumArgs()
- << TheCall->getSourceRange();
+ if (checkArgCount(*this, TheCall, ExpectedNumArgs))
+ return true;
// Check the third argument is a compile time constant
if (!TheCall->getArg(2)->isIntegerConstantExpr(Context))
diff --git a/clang/test/CodeGen/builtins-ppc-error.c b/clang/test/CodeGen/builtins-ppc-error.c
index 80ca227eeb24..6557565938b0 100644
--- a/clang/test/CodeGen/builtins-ppc-error.c
+++ b/clang/test/CodeGen/builtins-ppc-error.c
@@ -32,16 +32,16 @@ void testInsertWord(void) {
}
void testXXPERMDI(int index) {
- vec_xxpermdi(vsi); //expected-error {{too few arguments to function call, expected at least 3, have 1}}
- vec_xxpermdi(vsi, vsi, 2, 4); //expected-error {{too many arguments to function call, expected at most 3, have 4}}
+ vec_xxpermdi(vsi); //expected-error {{too few arguments to function call, expected 3, have 1}}
+ vec_xxpermdi(vsi, vsi, 2, 4); //expected-error {{too many arguments to function call, expected 3, have 4}}
vec_xxpermdi(vsi, vsi, index); //expected-error {{argument 3 to '__builtin_vsx_xxpermdi' must be a 2-bit unsigned literal (i.e. 0, 1, 2 or 3)}}
vec_xxpermdi(1, 2, 3); //expected-error {{first two arguments to '__builtin_vsx_xxpermdi' must be vectors}}
vec_xxpermdi(vsi, vuc, 2); //expected-error {{first two arguments to '__builtin_vsx_xxpermdi' must have the same type}}
}
void testXXSLDWI(int index) {
- vec_xxsldwi(vsi); //expected-error {{too few arguments to function call, expected at least 3, have 1}}
- vec_xxsldwi(vsi, vsi, 2, 4); //expected-error {{too many arguments to function call, expected at most 3, have 4}}
+ vec_xxsldwi(vsi); //expected-error {{too few arguments to function call, expected 3, have 1}}
+ vec_xxsldwi(vsi, vsi, 2, 4); //expected-error {{too many arguments to function call, expected 3, have 4}}
vec_xxsldwi(vsi, vsi, index); //expected-error {{argument 3 to '__builtin_vsx_xxsldwi' must be a 2-bit unsigned literal (i.e. 0, 1, 2 or 3)}}
vec_xxsldwi(1, 2, 3); //expected-error {{first two arguments to '__builtin_vsx_xxsldwi' must be vectors}}
vec_xxsldwi(vsi, vuc, 2); //expected-error {{first two arguments to '__builtin_vsx_xxsldwi' must have the same type}}
diff --git a/clang/test/SemaOpenCL/to_addr_builtin.cl b/clang/test/SemaOpenCL/to_addr_builtin.cl
index ff2d7807356a..8f4a20ac7662 100644
--- a/clang/test/SemaOpenCL/to_addr_builtin.cl
+++ b/clang/test/SemaOpenCL/to_addr_builtin.cl
@@ -15,7 +15,7 @@ void test(void) {
// expected-error at -2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
// expected-warning at -3{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
#else
- // expected-error at -5{{invalid number of arguments to function: 'to_global'}}
+ // expected-error at -5{{too many arguments to function call, expected 1, have 2}}
#endif
int x;
More information about the cfe-commits
mailing list