[cfe-commits] r72111 - in /cfe/trunk: include/clang/AST/Decl.h lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaExpr.cpp test/Sema/block-printf-attribute-1.c
Fariborz Jahanian
fjahanian at apple.com
Tue May 19 10:09:00 PDT 2009
Author: fjahanian
Date: Tue May 19 12:08:59 2009
New Revision: 72111
URL: http://llvm.org/viewvc/llvm-project?rev=72111&view=rev
Log:
Patch finishes off application of printf attribute on blocks.
Added:
cfe/trunk/test/Sema/block-printf-attribute-1.c
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=72111&r1=72110&r2=72111&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue May 19 12:08:59 2009
@@ -1211,6 +1211,8 @@
/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
///
class BlockDecl : public Decl, public DeclContext {
+ // FIXME: This can be packed into the bitfields in Decl.
+ bool isVariadic : 1;
/// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal
/// parameters of this function. This is null if a prototype or if there are
/// no formals.
@@ -1222,7 +1224,7 @@
protected:
BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
: Decl(Block, DC, CaretLoc), DeclContext(Block),
- ParamInfo(0), NumParams(0), Body(0) {}
+ isVariadic(false), ParamInfo(0), NumParams(0), Body(0) {}
virtual ~BlockDecl();
virtual void Destroy(ASTContext& C);
@@ -1232,6 +1234,9 @@
SourceLocation getCaretLocation() const { return getLocation(); }
+ bool IsVariadic() const { return isVariadic; }
+ void setIsVariadic(bool value) { isVariadic = value; }
+
CompoundStmt *getBody() const { return (CompoundStmt*) Body; }
Stmt *getBody(ASTContext &C) const { return (Stmt*) Body; }
void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=72111&r1=72110&r2=72111&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue May 19 12:08:59 2009
@@ -64,7 +64,7 @@
QualType Ty = V->getType();
return Ty->isBlockPointerType();
}
- return false;
+ return isa<BlockDecl>(d);
}
/// hasFunctionProto - Return true if the given decl has a argument
@@ -74,7 +74,7 @@
if (const FunctionType *FnTy = getFunctionType(d))
return isa<FunctionProtoType>(FnTy);
else {
- assert(isa<ObjCMethodDecl>(d));
+ assert(isa<ObjCMethodDecl>(d) || isa<BlockDecl>(d));
return true;
}
}
@@ -85,13 +85,16 @@
static unsigned getFunctionOrMethodNumArgs(Decl *d) {
if (const FunctionType *FnTy = getFunctionType(d))
return cast<FunctionProtoType>(FnTy)->getNumArgs();
+ if (const BlockDecl *BD = dyn_cast<BlockDecl>(d))
+ return BD->getNumParams();
return cast<ObjCMethodDecl>(d)->param_size();
}
static QualType getFunctionOrMethodArgType(Decl *d, unsigned Idx) {
if (const FunctionType *FnTy = getFunctionType(d))
return cast<FunctionProtoType>(FnTy)->getArgType(Idx);
-
+ if (const BlockDecl *BD = dyn_cast<BlockDecl>(d))
+ return BD->getParamDecl(Idx)->getType();
return cast<ObjCMethodDecl>(d)->param_begin()[Idx]->getType();
}
@@ -100,7 +103,9 @@
if (const FunctionType *FnTy = getFunctionType(d)) {
const FunctionProtoType *proto = cast<FunctionProtoType>(FnTy);
return proto->isVariadic();
- } else {
+ } else if (const BlockDecl *BD = dyn_cast<BlockDecl>(d))
+ return BD->IsVariadic();
+ else {
return cast<ObjCMethodDecl>(d)->isVariadic();
}
}
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=72111&r1=72110&r2=72111&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue May 19 12:08:59 2009
@@ -5140,7 +5140,7 @@
}
CurBlock->TheDecl->setParams(Context, &CurBlock->Params[0],
CurBlock->Params.size());
-
+ CurBlock->TheDecl->setIsVariadic(CurBlock->isVariadic);
ProcessDeclAttributes(CurBlock->TheDecl, ParamInfo);
for (BlockDecl::param_iterator AI = CurBlock->TheDecl->param_begin(),
E = CurBlock->TheDecl->param_end(); AI != E; ++AI)
Added: cfe/trunk/test/Sema/block-printf-attribute-1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-printf-attribute-1.c?rev=72111&view=auto
==============================================================================
--- cfe/trunk/test/Sema/block-printf-attribute-1.c (added)
+++ cfe/trunk/test/Sema/block-printf-attribute-1.c Tue May 19 12:08:59 2009
@@ -0,0 +1,15 @@
+// RUN: clang-cc %s -fsyntax-only -verify -fblocks
+
+int main()
+{
+ void (^b) (int arg, const char * format, ...) __attribute__ ((__format__ (__printf__, 1, 3))) = // expected-error {{format argument not a string type}}
+ ^ __attribute__ ((__format__ (__printf__, 1, 3))) (int arg, const char * format, ...) {}; // expected-error {{format argument not a string type}}
+
+ void (^z) (int arg, const char * format, ...) __attribute__ ((__format__ (__printf__, 2, 3))) = ^ __attribute__ ((__format__ (__printf__, 2, 3))) (int arg, const char * format, ...) {};
+
+ // FIXME: argument type poking not yet supportted.
+ z(1, "%s", 1); /* { dg-warning "format \\'\%s\\' expects type \\'char \\*\\'\, but argument 3 has type \\'int\\'" } */
+ z(1, "%s", "HELLO"); // OK
+
+}
+
More information about the cfe-commits
mailing list