diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-05-18 21:05:18 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-05-18 21:05:18 +0000 |
commit | 725165f2846bd37d3aaf863747fa30126992085e (patch) | |
tree | 10cfacfdd05f0ce06d68f2d75c867256aa467393 /lib/Sema/SemaChecking.cpp | |
parent | d86d3361924a89d6c67ddbb3a2307af4008889ab (diff) |
more printf attribute on block declaration and
checking when block is envoked. In progress.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72039 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 22dcc49b55..a76463fac8 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -181,6 +181,34 @@ Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) { return move(TheCallResult); } +Action::OwningExprResult +Sema::CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall) { + + OwningExprResult TheCallResult(Owned(TheCall)); + // Printf checking. + const FormatAttr *Format = NDecl->getAttr<FormatAttr>(); + if (!Format) + return move(TheCallResult); + const VarDecl *V = dyn_cast<VarDecl>(NDecl); + if (!V) + return move(TheCallResult); + QualType Ty = V->getType(); + if (!Ty->isBlockPointerType()) + return move(TheCallResult); + if (Format->getType() == "printf") { + bool HasVAListArg = Format->getFirstArg() == 0; + if (!HasVAListArg) { + const FunctionType *FT = + Ty->getAsBlockPointerType()->getPointeeType()->getAsFunctionType(); + if (const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FT)) + HasVAListArg = !Proto->isVariadic(); + } + CheckPrintfArguments(TheCall, HasVAListArg, Format->getFormatIdx() - 1, + HasVAListArg ? 0 : Format->getFirstArg() - 1); + } + return move(TheCallResult); +} + /// SemaBuiltinAtomicOverloaded - We have a call to a function like /// __sync_fetch_and_add, which is an overloaded function based on the pointer /// type of its first argument. The main ActOnCallExpr routines have already |