From 2c21a073525cdfa68e4439b7af551385dc2796ab Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 21 Nov 2008 18:44:24 +0000 Subject: [PATCH] merge some simple call diagnostics. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59831 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticKinds.def | 8 ++------ lib/Sema/SemaChecking.cpp | 16 +++++++++------- lib/Sema/SemaExpr.cpp | 24 +++++++++--------------- lib/Sema/SemaExprObjC.cpp | 2 +- test/Sema/builtins.c | 2 +- test/SemaObjC/message.m | 2 +- 6 files changed, 23 insertions(+), 31 deletions(-) diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 443e311462..6a85df0e18 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -1252,13 +1252,9 @@ DIAG(err_block_decl_ref_not_modifiable_lvalue, ERROR, DIAG(err_typecheck_call_not_function, ERROR, "called object type '%0' is not a function or function pointer") DIAG(err_typecheck_call_too_few_args, ERROR, - "too few arguments to function") -DIAG(err_typecheck_block_too_few_args, ERROR, - "too few arguments to block") + "too few arguments to %select{function|block|method}0 call") DIAG(err_typecheck_call_too_many_args, ERROR, - "too many arguments to function") -DIAG(err_typecheck_block_too_many_args, ERROR, - "too many arguments to block call") + "too many arguments to %select{function|block|method}0 call") DIAG(err_typecheck_closure_too_many_args, ERROR, "too many arguments to closure call") DIAG(err_typecheck_call_invalid_ordered_compare, ERROR, diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index eb961d14fa..09474452a2 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -153,9 +153,9 @@ bool Sema::CheckBuiltinCFStringArgument(Expr* Arg) { bool Sema::SemaBuiltinVAStart(CallExpr *TheCall) { Expr *Fn = TheCall->getCallee(); if (TheCall->getNumArgs() > 2) { - Diag(TheCall->getArg(2)->getLocStart(), + Diag(TheCall->getArg(2)->getLocStart(), diag::err_typecheck_call_too_many_args) - << Fn->getSourceRange() + << 0 /*function call*/ << Fn->getSourceRange() << SourceRange(TheCall->getArg(2)->getLocStart(), (*(TheCall->arg_end()-1))->getLocEnd()); return true; @@ -202,10 +202,12 @@ bool Sema::SemaBuiltinVAStart(CallExpr *TheCall) { /// friends. This is declared to take (...), so we have to check everything. bool Sema::SemaBuiltinUnorderedCompare(CallExpr *TheCall) { if (TheCall->getNumArgs() < 2) - return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args); + return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args) + << 0 /*function call*/; if (TheCall->getNumArgs() > 2) return Diag(TheCall->getArg(2)->getLocStart(), diag::err_typecheck_call_too_many_args) + << 0 /*function call*/ << SourceRange(TheCall->getArg(2)->getLocStart(), (*(TheCall->arg_end()-1))->getLocEnd()); @@ -242,7 +244,7 @@ bool Sema::SemaBuiltinStackAddress(CallExpr *TheCall) { Action::ExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) { if (TheCall->getNumArgs() < 3) return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args) - << TheCall->getSourceRange(); + << 0 /*function call*/ << TheCall->getSourceRange(); QualType FAType = TheCall->getArg(0)->getType(); QualType SAType = TheCall->getArg(1)->getType(); @@ -266,9 +268,9 @@ Action::ExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) { if (TheCall->getNumArgs() != numElements+2) { if (TheCall->getNumArgs() < numElements+2) return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args) - << TheCall->getSourceRange(); + << 0 /*function call*/ << TheCall->getSourceRange(); return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_many_args) - << TheCall->getSourceRange(); + << 0 /*function call*/ << TheCall->getSourceRange(); } for (unsigned i = 2; i < TheCall->getNumArgs(); i++) { @@ -304,7 +306,7 @@ bool Sema::SemaBuiltinPrefetch(CallExpr *TheCall) { if (NumArgs > 3) return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_many_args) - << TheCall->getSourceRange(); + << 0 /*function call*/ << TheCall->getSourceRange(); // Argument 0 is checked for us and the remaining arguments must be // constant integers. diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 7c4c15e0dd..ba1bb2544d 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1369,27 +1369,21 @@ ActOnCallExpr(ExprTy *fn, SourceLocation LParenLoc, // If too few arguments are available (and we don't have default // arguments for the remaining parameters), don't make the call. if (NumArgs < NumArgsInProto) { - if (FDecl && NumArgs >= FDecl->getMinRequiredArguments()) { - // Use default arguments for missing arguments - NumArgsToCheck = NumArgsInProto; - TheCall->setNumArgs(NumArgsInProto); - } else - return Diag(RParenLoc, - !Fn->getType()->isBlockPointerType() - ? diag::err_typecheck_call_too_few_args - : diag::err_typecheck_block_too_few_args) - << Fn->getSourceRange(); + if (!FDecl || NumArgs < FDecl->getMinRequiredArguments()) + return Diag(RParenLoc, diag::err_typecheck_call_too_few_args) + << Fn->getType()->isBlockPointerType() << Fn->getSourceRange(); + // Use default arguments for missing arguments + NumArgsToCheck = NumArgsInProto; + TheCall->setNumArgs(NumArgsInProto); } // If too many are passed and not variadic, error on the extras and drop // them. if (NumArgs > NumArgsInProto) { if (!Proto->isVariadic()) { - Diag(Args[NumArgsInProto]->getLocStart(), - !Fn->getType()->isBlockPointerType() - ? diag::err_typecheck_call_too_many_args - : diag::err_typecheck_block_too_many_args) - << Fn->getSourceRange() + Diag(Args[NumArgsInProto]->getLocStart(), + diag::err_typecheck_call_too_many_args) + << Fn->getType()->isBlockPointerType() << Fn->getSourceRange() << SourceRange(Args[NumArgsInProto]->getLocStart(), Args[NumArgs-1]->getLocEnd()); // This deletes the extra arguments. diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index b73449e930..d09279353b 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -161,7 +161,7 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, if (NumArgs != NumNamedArgs) { Diag(Args[NumNamedArgs]->getLocStart(), diag::err_typecheck_call_too_many_args) - << Method->getSourceRange() + << 2 /*method*/ << Method->getSourceRange() << SourceRange(Args[NumNamedArgs]->getLocStart(), Args[NumArgs-1]->getLocEnd()); } diff --git a/test/Sema/builtins.c b/test/Sema/builtins.c index d02adf3165..bbbad421cf 100644 --- a/test/Sema/builtins.c +++ b/test/Sema/builtins.c @@ -28,7 +28,7 @@ void cfstring() { CFSTR("\242"); // expected-warning {{ CFString literal contains non-ASCII character }} CFSTR("\0"); // expected-warning {{ CFString literal contains NUL character }} CFSTR(242); // expected-error {{ CFString literal is not a string constant }} expected-warning {{incompatible integer to pointer conversion}} - CFSTR("foo", "bar"); // expected-error {{ error: too many arguments to function }} + CFSTR("foo", "bar"); // expected-error {{too many arguments to function call}} } diff --git a/test/SemaObjC/message.m b/test/SemaObjC/message.m index 69a6535a4a..274885d37c 100644 --- a/test/SemaObjC/message.m +++ b/test/SemaObjC/message.m @@ -66,5 +66,5 @@ extern Class NSClassFromObject(id object); @end int f0(I0 *ob) { - [ ob nonVararg: 0, 1, 2]; // expected-error {{too many arguments to function}} + [ ob nonVararg: 0, 1, 2]; // expected-error {{too many arguments to method call}} } -- 2.40.0