]> granicus.if.org Git - clang/commitdiff
more printf attribute on block declaration and
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 18 May 2009 21:05:18 +0000 (21:05 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 18 May 2009 21:05:18 +0000 (21:05 +0000)
checking when block is envoked. In progress.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72039 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaChecking.cpp
lib/Sema/SemaExpr.cpp

index 9b953a80024b4ef82807b8fc4c0535cb4ff6ff15..9df087ae68740b2a469e754c1155cdccdfece54a 100644 (file)
@@ -2700,6 +2700,8 @@ public:
 private:
   Action::OwningExprResult CheckFunctionCall(FunctionDecl *FDecl,
                                              CallExpr *TheCall);
+  
+  Action::OwningExprResult CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall);
   SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
                                                 unsigned ByteNo) const;
   bool CheckObjCString(Expr *Arg);
index 22dcc49b55458556ff350fb0eb04f686cf33d9ac..a76463fac8fd38338af784b60420baa2d17ddddc 100644 (file)
@@ -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
index e5ee363825aa66c4389ad78648a41e6be0fdb78e..0caad654ee0170f88b88ec33452f456598e99fe8 100644 (file)
@@ -2692,6 +2692,8 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc,
   // Do special checking on direct calls to functions.
   if (FDecl)
     return CheckFunctionCall(FDecl, TheCall.take());
+  if (NDecl)
+    return CheckBlockCall(NDecl, TheCall.take());
 
   return Owned(TheCall.take());
 }