diff options
author | Jean-Daniel Dupas <devlists@shadowlab.org> | 2012-02-07 19:01:42 +0000 |
---|---|---|
committer | Jean-Daniel Dupas <devlists@shadowlab.org> | 2012-02-07 19:01:42 +0000 |
commit | 52aabafeee9e8634eceb46b1a3fdbd3cd22b1cf7 (patch) | |
tree | 5f6168570d02bd6ef6904e7e7a6a26c0dd1d0c11 /lib/Sema/SemaChecking.cpp | |
parent | 7fb8630e76fe2c4e7e048c7c8a448baf282390cd (diff) |
Implements support of format_arg attribute on C++ member.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149998 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index a619293f88..c3b957cb60 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -1459,21 +1459,20 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, Expr **Args, return false; } - case Stmt::CallExprClass: { + case Stmt::CallExprClass: + case Stmt::CXXMemberCallExprClass: { const CallExpr *CE = cast<CallExpr>(E); - if (const ImplicitCastExpr *ICE - = dyn_cast<ImplicitCastExpr>(CE->getCallee())) { - if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr())) { - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) { - if (const FormatArgAttr *FA = FD->getAttr<FormatArgAttr>()) { - unsigned ArgIndex = FA->getFormatIdx(); - const Expr *Arg = CE->getArg(ArgIndex - 1); - - return SemaCheckStringLiteral(Arg, Args, NumArgs, HasVAListArg, - format_idx, firstDataArg, Type, - inFunctionCall); - } - } + if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl())) { + if (const FormatArgAttr *FA = ND->getAttr<FormatArgAttr>()) { + unsigned ArgIndex = FA->getFormatIdx(); + if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(ND)) + if (MD->isInstance()) + --ArgIndex; + const Expr *Arg = CE->getArg(ArgIndex - 1); + + return SemaCheckStringLiteral(Arg, Args, NumArgs, HasVAListArg, + format_idx, firstDataArg, Type, + inFunctionCall); } } @@ -1534,11 +1533,7 @@ void Sema::CheckFormatArguments(const FormatAttr *Format, CallExpr *TheCall) { // The way the format attribute works in GCC, the implicit this argument // of member functions is counted. However, it doesn't appear in our own // lists, so decrement format_idx in that case. - if (isa<CXXMemberCallExpr>(TheCall)) { - const CXXMethodDecl *method_decl = - dyn_cast<CXXMethodDecl>(TheCall->getCalleeDecl()); - IsCXXMember = method_decl && method_decl->isInstance(); - } + IsCXXMember = isa<CXXMemberCallExpr>(TheCall); CheckFormatArguments(Format, TheCall->getArgs(), TheCall->getNumArgs(), IsCXXMember, TheCall->getRParenLoc(), TheCall->getCallee()->getSourceRange()); |