Make error handling for va_start a bit more robust. Fixes PR3213.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61055 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 0c7da0e..14aa996 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -160,14 +160,23 @@
(*(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);