diff options
author | Chris Lattner <sabre@nondot.org> | 2007-07-21 03:09:58 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-07-21 03:09:58 +0000 |
commit | d472b31d8037b506fd98531daf40aa5f85afb5e8 (patch) | |
tree | 098cc64ab409020f1183a4d5c47fdeed0ae74163 | |
parent | 74c469fef477e32e00c58dffbd734fde1001f03e (diff) |
Fix off-by-one error when emitting diagnostics. Also, make diagnostic
a bit nicer for people who pass lots of extra arguments to calls by
selecting them all instead of just the first one:
arg-duplicate.c:13:13: error: too many arguments to function
f3 (1, 1, 2, 3, 4); // expected-error {{too many arguments to function}}
^~~~~~~
This implements test/Sema/arg-duplicate.c, thanks to Neil for pointing
out this crash.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40136 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Sema/SemaExpr.cpp | 5 | ||||
-rw-r--r-- | test/Sema/arg-duplicate.c | 15 |
2 files changed, 18 insertions, 2 deletions
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index bfb2d17143..fc4bc865cc 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -409,9 +409,10 @@ ParseCallExpr(ExprTy *fn, SourceLocation LParenLoc, Fn->getSourceRange()); else if (NumArgsInCall > NumArgsInProto) { if (!proto->isVariadic()) { - Diag(Args[NumArgsInProto+1]->getLocStart(), + Diag(Args[NumArgsInProto]->getLocStart(), diag::err_typecheck_call_too_many_args, Fn->getSourceRange(), - Args[NumArgsInProto+1]->getSourceRange()); + SourceRange(Args[NumArgsInProto]->getLocStart(), + Args[NumArgsInCall-1]->getLocEnd())); } NumArgsToCheck = NumArgsInProto; } diff --git a/test/Sema/arg-duplicate.c b/test/Sema/arg-duplicate.c new file mode 100644 index 0000000000..5d44a72ecb --- /dev/null +++ b/test/Sema/arg-duplicate.c @@ -0,0 +1,15 @@ +// RUN: clang -parse-ast-check %s + +typedef int x; +int f3(y, x, + x) // expected-error {{redefinition of parameter}} + int y, x, + x; // expected-error {{redefinition of parameter}} +{ + return x + y; +} + +void f4(void) { + f3 (1, 1, 2, 3, 4); // expected-error {{too many arguments to function}} +} + |