From: Ted Kremenek Date: Thu, 29 Apr 2010 16:49:01 +0000 (+0000) Subject: Add FunctionDecl::isVariadic() to match BlockDecl::isVariadic() and ObjCMethodDecl... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9498d388810d284d3970aef0d69fa4d069fd6caf;p=clang Add FunctionDecl::isVariadic() to match BlockDecl::isVariadic() and ObjCMethodDecl::isVariadic(). Do some minor refactoring along the way. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102635 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 7390007391..3211ce8d45 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -1138,6 +1138,9 @@ public: void setBody(Stmt *B); void setLazyBody(uint64_t Offset) { Body = Offset; } + /// Whether this function is variadic. + bool isVariadic() const; + /// Whether this function is marked as virtual explicitly. bool isVirtualAsWritten() const { return IsVirtualAsWritten; } void setVirtualAsWritten(bool V) { IsVirtualAsWritten = V; } diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 62420de7a7..fc805451cb 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -906,6 +906,12 @@ void FunctionDecl::getNameForDiagnostic(std::string &S, } +bool FunctionDecl::isVariadic() const { + if (const FunctionProtoType *FT = getType()->getAs()) + return FT->isVariadic(); + return false; +} + Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const { for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) { if (I->Body) { diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 91a3cbe071..7029711d44 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -511,15 +511,10 @@ bool Sema::SemaBuiltinVAStart(CallExpr *TheCall) { bool isVariadic; if (CurBlock) isVariadic = CurBlock->isVariadic; - else if (getCurFunctionDecl()) { - if (FunctionProtoType* FTP = - dyn_cast(getCurFunctionDecl()->getType())) - isVariadic = FTP->isVariadic(); - else - isVariadic = false; - } else { + else if (FunctionDecl *FD = getCurFunctionDecl()) + isVariadic = FD->isVariadic(); + else isVariadic = getCurMethodDecl()->isVariadic(); - } if (!isVariadic) { Diag(Fn->getLocStart(), diag::err_va_start_used_in_non_variadic_function);