[cfe-commits] r71894 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaExpr.cpp test/Sema/block-sentinel-attribute.c

Fariborz Jahanian fjahanian at apple.com
Fri May 15 14:18:06 PDT 2009


Author: fjahanian
Date: Fri May 15 16:18:04 2009
New Revision: 71894

URL: http://llvm.org/viewvc/llvm-project?rev=71894&view=rev
Log:
improved on diagnosing misplacement of sentinel attributes.
No change in functionality.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/block-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=71894&r1=71893&r2=71894&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri May 15 16:18:04 2009
@@ -483,7 +483,7 @@
 def warn_attribute_sentinel_named_arguments : Warning<
   "'sentinel' attribute requires named arguments">;
 def warn_attribute_sentinel_not_variadic : Warning<
-  "'sentinel' attribute only supported for variadic functions">;
+  "'sentinel' attribute only supported for variadic %select{functions|blocks}0">;
 def err_attribute_sentinel_less_than_zero : Error<
   "'sentinel' parameter 1 less than zero">;
 def err_attribute_sentinel_not_zero_or_one : Error<

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=71894&r1=71893&r2=71894&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri May 15 16:18:04 2009
@@ -712,12 +712,12 @@
     }
     
     if (!cast<FunctionProtoType>(FT)->isVariadic()) {
-      S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic);
+      S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
       return;
     }    
   } else if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(d)) {
     if (!MD->isVariadic()) {
-      S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic);
+      S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
       return;
     }
   } else if (isa<BlockDecl>(d)) {
@@ -730,7 +730,8 @@
       const FunctionType *FT = Ty->isFunctionPointerType() ? getFunctionType(d) 
         : Ty->getAsBlockPointerType()->getPointeeType()->getAsFunctionType();
       if (!cast<FunctionProtoType>(FT)->isVariadic()) {
-        S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic);
+        int m = Ty->isFunctionPointerType() ? 0 : 1;
+        S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
         return;
       }
     }

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=71894&r1=71893&r2=71894&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri May 15 16:18:04 2009
@@ -5068,7 +5068,7 @@
     // Check for a valid sentinel attribute on this block.
     if (CurBlock->TheDecl->getAttr<SentinelAttr>()) {
       Diag(ParamInfo.getAttributes()->getLoc(), 
-           diag::warn_attribute_sentinel_not_variadic);
+           diag::warn_attribute_sentinel_not_variadic) << 1;
       // FIXME: remove the attribute.
     }
     QualType RetTy = T.getTypePtr()->getAsFunctionType()->getResultType();
@@ -5115,7 +5115,7 @@
   // 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);
+         diag::warn_attribute_sentinel_not_variadic) << 1;
     // FIXME: remove the attribute.
   }
   

Modified: cfe/trunk/test/Sema/block-sentinel-attribute.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-sentinel-attribute.c?rev=71894&r1=71893&r2=71894&view=diff

==============================================================================
--- cfe/trunk/test/Sema/block-sentinel-attribute.c (original)
+++ cfe/trunk/test/Sema/block-sentinel-attribute.c Fri May 15 16:18:04 2009
@@ -4,6 +4,7 @@
 
 int main()
 {
+        void (^bbad) (int arg, const char * format) __attribute__ ((__sentinel__)) ; // expected-warning {{sentinel' attribute only supported for variadic blocks}}
         void (^b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)) =  // expected-note {{block has been explicitly marked sentinel here}}
 						^ __attribute__ ((__sentinel__)) (int arg, const char * format, ...) {};
         void (^z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))) = ^ __attribute__ ((__sentinel__ (2))) (int arg, const char * format, ...) {}; // expected-note {{block has been explicitly marked sentinel here}}





More information about the cfe-commits mailing list