diff options
author | Anders Carlsson <andersca@mac.com> | 2007-10-12 17:48:41 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2007-10-12 17:48:41 +0000 |
commit | 6eda8c9cefb498ac8403bc65854e6ce411a07855 (patch) | |
tree | 3f75bd9414d7b15e0296c473582d571d4ceceab2 /Sema/SemaChecking.cpp | |
parent | bece4ac257d85e51d94212a51eb7405818247e7e (diff) |
Add some more diagnostics for va_start, fix tests so they pass with these new diags.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42917 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Sema/SemaChecking.cpp')
-rw-r--r-- | Sema/SemaChecking.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Sema/SemaChecking.cpp b/Sema/SemaChecking.cpp index ea63b7dc1c..f764d80df2 100644 --- a/Sema/SemaChecking.cpp +++ b/Sema/SemaChecking.cpp @@ -43,6 +43,37 @@ Sema::CheckFunctionCall(Expr *Fn, assert(NumArgsInCall == 1 && "Wrong number of arguments to builtin CFStringMakeConstantString"); return CheckBuiltinCFStringArgument(Args[0]); + } else if (FnInfo->getBuiltinID() == Builtin::BI__builtin_va_start) { + if (NumArgsInCall > 2) { + Diag(Args[2]->getLocStart(), + diag::err_typecheck_call_too_many_args, Fn->getSourceRange(), + SourceRange(Args[2]->getLocStart(), + Args[NumArgsInCall - 1]->getLocEnd())); + return true; + } + + FunctionTypeProto* proto = + cast<FunctionTypeProto>(CurFunctionDecl->getType()); + if (!proto->isVariadic()) { + Diag(Fn->getLocStart(), + diag::err_va_start_used_in_non_variadic_function); + return true; + } + + bool SecondArgIsLastNamedArgument = false; + if (DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Args[1])) { + if (ParmVarDecl *PV = dyn_cast<ParmVarDecl>(DR->getDecl())) { + ParmVarDecl *LastNamedArg = + CurFunctionDecl->getParamDecl(CurFunctionDecl->getNumParams() - 1); + + if (PV == LastNamedArg) + SecondArgIsLastNamedArgument = true; + } + } + + if (!SecondArgIsLastNamedArgument) + Diag(Args[1]->getLocStart(), + diag::warn_second_parameter_of_va_start_not_last_named_argument); } // Search the KnownFunctionIDs for the identifier. |