forked from OSchip/llvm-project
Make error handling for va_start a bit more robust. Fixes PR3213.
llvm-svn: 61055
This commit is contained in:
parent
48ee658562
commit
bb2b3be9e1
|
@ -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);
|
||||
|
|
|
@ -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}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue