[cfe-commits] r71788 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaExpr.cpp test/Sema/sentinel-attribute.c
Fariborz Jahanian
fjahanian at apple.com
Thu May 14 13:53:53 PDT 2009
Author: fjahanian
Date: Thu May 14 15:53:39 2009
New Revision: 71788
URL: http://llvm.org/viewvc/llvm-project?rev=71788&view=rev
Log:
Adds recognition of sentinel attribute on block declarations.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/sentinel-attribute.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=71788&r1=71787&r2=71788&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu May 14 15:53:39 2009
@@ -440,7 +440,8 @@
"'weak_import' attribute cannot be specified on a definition">;
def warn_attribute_wrong_decl_type : Warning<
"%0 attribute only applies to %select{function|union|"
- "variable and function|function or method|parameter|parameter or Objective-C method}1 types">;
+ "variable and function|function or method|parameter|parameter or Objective-C method |"
+ "function, method or block}1 types">;
def warn_gnu_inline_attribute_requires_inline : Warning<
"'gnu_inline' attribute requires function to be marked 'inline',"
" attribute ignored">;
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=71788&r1=71787&r2=71788&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu May 14 15:53:39 2009
@@ -719,10 +719,32 @@
if (!MD->isVariadic()) {
S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic);
return;
- }
+ }
+ } else if (isa<BlockDecl>(d)) {
+ // Note! BlockDecl is typeless. Variadic diagnostics
+ // will be issued by the caller.
+ ;
+ } else if (const VarDecl *V = dyn_cast<VarDecl>(d)) {
+ // FIXME: share code with case of BlockDecl.
+ QualType Ty = V->getType();
+ if (Ty->isBlockPointerType()) {
+ const BlockPointerType *BPT = Ty->getAsBlockPointerType();
+ QualType FnType = BPT->getPointeeType();
+ const FunctionType *FT = FnType->getAsFunctionType();
+ assert(FT && "Block has non-function type?");
+ if (!cast<FunctionProtoType>(FT)->isVariadic()) {
+ S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic);
+ return;
+ }
+ }
+ else {
+ S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+ << Attr.getName() << 6 /*function, method or */;
+ return;
+ }
} else {
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
- << Attr.getName() << 3 /*function or method*/;
+ << Attr.getName() << 6 /*function, method or */;
return;
}
d->addAttr(::new (S.Context) SentinelAttr(sentinel, nullPos));
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=71788&r1=71787&r2=71788&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu May 14 15:53:39 2009
@@ -5038,7 +5038,12 @@
CurBlock->hasPrototype = true;
CurBlock->isVariadic = false;
-
+ // Check for a valid sentinel attribute on this block.
+ if (CurBlock->TheDecl->getAttr<SentinelAttr>()) {
+ Diag(ParamInfo.getAttributes()->getLoc(),
+ diag::warn_attribute_sentinel_not_variadic);
+ // FIXME: remove the attribute.
+ }
QualType RetTy = T.getTypePtr()->getAsFunctionType()->getResultType();
// Do not allow returning a objc interface by-value.
@@ -5080,6 +5085,13 @@
if ((*AI)->getIdentifier())
PushOnScopeChains(*AI, CurBlock->TheScope);
+ // Check for a valid sentinel attribute on this block.
+ if (!CurBlock->isVariadic && CurBlock->TheDecl->getAttr<SentinelAttr>()) {
+ Diag(ParamInfo.getAttributes()->getLoc(),
+ diag::warn_attribute_sentinel_not_variadic);
+ // FIXME: remove the attribute.
+ }
+
// Analyze the return type.
QualType T = GetTypeForDeclarator(ParamInfo, CurScope);
QualType RetTy = T->getAsFunctionType()->getResultType();
Modified: cfe/trunk/test/Sema/sentinel-attribute.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/sentinel-attribute.c?rev=71788&r1=71787&r2=71788&view=diff
==============================================================================
--- cfe/trunk/test/Sema/sentinel-attribute.c (original)
+++ cfe/trunk/test/Sema/sentinel-attribute.c Thu May 14 15:53:39 2009
@@ -1,5 +1,5 @@
// RUN: clang-cc -fsyntax-only -verify %s
-int x __attribute__((sentinel)); //expected-warning{{'sentinel' attribute only applies to function or method types}}
+int x __attribute__((sentinel)); //expected-warning{{'sentinel' attribute only applies to function, method or block types}}
void f1(int a, ...) __attribute__ ((sentinel));
void f2(int a, ...) __attribute__ ((sentinel(1)));
More information about the cfe-commits
mailing list