Make error handling for va_start a bit more robust. Fixes PR3213.

llvm-svn: 61055
This commit is contained in:
Eli Friedman 2008-12-15 22:05:35 +00:00
parent 48ee658562
commit bb2b3be9e1
2 changed files with 23 additions and 5 deletions

View File

@ -160,14 +160,23 @@ bool Sema::SemaBuiltinVAStart(CallExpr *TheCall) {
(*(TheCall->arg_end()-1))->getLocEnd());
return true;
}
if (TheCall->getNumArgs() < 2) {
return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args)
<< 0 /*function call*/;
}
// Determine whether the current function is variadic or not.
bool isVariadic;
if (getCurFunctionDecl())
isVariadic =
cast<FunctionTypeProto>(getCurFunctionDecl()->getType())->isVariadic();
else
if (getCurFunctionDecl()) {
if (FunctionTypeProto* FTP =
dyn_cast<FunctionTypeProto>(getCurFunctionDecl()->getType()))
isVariadic = FTP->isVariadic();
else
isVariadic = false;
} else {
isVariadic = getCurMethodDecl()->isVariadic();
}
if (!isVariadic) {
Diag(Fn->getLocStart(), diag::err_va_start_used_in_non_variadic_function);

View File

@ -34,3 +34,12 @@ void f4(const char *msg, ...) {
__builtin_va_end (ap);
}
void f5() {
__builtin_va_list ap;
__builtin_va_start(ap,ap); // expected-error {{'va_start' used in function with fixed args}}
}
void f6(int a, ...) {
__builtin_va_list ap;
__builtin_va_start(ap); // expected-error {{too few arguments to function}}
}