From 3bc84ca376a29e883d09c03b25127c3993cdf55a Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 29 Jul 2011 00:24:42 +0000 Subject: [PATCH] Fix an inconsistency in Sema::ConvertArgumentsForCall in that the callee note diagnostic was not emitted in the case where there were too few arguments. llvm-svn: 136437 --- .../include/clang/Basic/DiagnosticSemaKinds.td | 4 ++-- clang/lib/Sema/SemaExpr.cpp | 17 ++++++++++++----- .../dcl.meaning/dcl.fct.default/p10.cpp | 2 +- .../dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp | 2 +- clang/test/PCH/functions.c | 2 +- clang/test/Sema/exprs.c | 2 +- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 7f660e1a279f..83f232e87658 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3696,11 +3696,11 @@ def err_typecheck_call_too_few_args_at_least : Error< def err_typecheck_call_too_many_args : Error< "too many arguments to %select{function|block|method}0 call, " "expected %1, have %2">; -def note_typecheck_call_too_many_args : Note< - "%0 declared here">; def err_typecheck_call_too_many_args_at_most : Error< "too many arguments to %select{function|block|method}0 call, " "expected at most %1, have %2">; +def note_callee_decl : Note< + "%0 declared here">; def warn_call_wrong_number_of_arguments : Warning< "too %select{few|many}0 arguments in call to %1">; def err_atomic_builtin_must_be_pointer : Error< diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 9019e95747df..bfaf5460361f 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3231,10 +3231,18 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, // 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()) - return Diag(RParenLoc, diag::err_typecheck_call_too_few_args) + if (!FDecl || NumArgs < FDecl->getMinRequiredArguments()) { + Diag(RParenLoc, diag::err_typecheck_call_too_few_args) << Fn->getType()->isBlockPointerType() << NumArgsInProto << NumArgs << Fn->getSourceRange(); + + // Emit the location of the prototype. + if (FDecl && !FDecl->getBuiltinID()) + Diag(FDecl->getLocStart(), diag::note_callee_decl) + << FDecl; + + return true; + } Call->setNumArgs(Context, NumArgsInProto); } @@ -3251,9 +3259,8 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, // Emit the location of the prototype. if (FDecl && !FDecl->getBuiltinID()) - Diag(FDecl->getLocStart(), - diag::note_typecheck_call_too_many_args) - << FDecl; + Diag(FDecl->getLocStart(), diag::note_callee_decl) + << FDecl; // This deletes the extra arguments. Call->setNumArgs(Context, NumArgsInProto); diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p10.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p10.cpp index 9d26561ca8de..385e45dadfae 100644 --- a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p10.cpp +++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p10.cpp @@ -5,7 +5,7 @@ struct A { }; struct B : public A { - void f(int a); + void f(int a); // expected-note{{'f' declared here}} }; void m() { diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp index b2129b259bb3..f3dec52f63b3 100644 --- a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp +++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp @@ -41,7 +41,7 @@ namespace N1 { void m() { - void f(int, int); + void f(int, int); // expected-note{{'f' declared here}} f(4); // expected-error{{too few arguments to function call}} void f(int, int = 5); // expected-note{{previous definition}} f(4); // okay diff --git a/clang/test/PCH/functions.c b/clang/test/PCH/functions.c index 23becb60e8ed..35e39210585b 100644 --- a/clang/test/PCH/functions.c +++ b/clang/test/PCH/functions.c @@ -4,7 +4,7 @@ // Test with pch. // RUN: %clang_cc1 -emit-pch -o %t %S/functions.h // RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s - +// expected-note{{'f1' declared here}} int f0(int x0, int y0, ...) { return x0 + y0; } // expected-note{{passing argument to parameter here}} float *test_f1(int val, double x, double y) { diff --git a/clang/test/Sema/exprs.c b/clang/test/Sema/exprs.c index 9ce1481f16c5..460f72cb1742 100644 --- a/clang/test/Sema/exprs.c +++ b/clang/test/Sema/exprs.c @@ -163,7 +163,7 @@ void test17(int x) { } // PR6501 -void test18_a(int a); // expected-note {{'test18_a' declared here}} +void test18_a(int a); // expected-note 2 {{'test18_a' declared here}} void test18(int b) { test18_a(b, b); // expected-error {{too many arguments to function call, expected 1, have 2}} test18_a(); // expected-error {{too few arguments to function call, expected 1, have 0}}