]> granicus.if.org Git - clang/commitdiff
Minor refactoring of sentinel warning on blocks. Add a test for this warning.
authorEli Friedman <eli.friedman@gmail.com>
Fri, 6 Jan 2012 01:23:10 +0000 (01:23 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Fri, 6 Jan 2012 01:23:10 +0000 (01:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147641 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
lib/Sema/SemaExpr.cpp
test/Sema/block-sentinel-attribute.c

index 0b8e9fa2d0fb3705334ff85624087884aca38ae0..cdba6208dbc7fc7c101b77c1b3de7b341f20aa41 100644 (file)
@@ -1878,10 +1878,11 @@ static void handleSentinelAttr(Sema &S, Decl *D, const AttributeList &Attr) {
       S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
       return;
     }
-  } else if (isa<BlockDecl>(D)) {
-    // Note! BlockDecl is typeless. Variadic diagnostics will be issued by the
-    // caller.
-    ;
+  } else if (BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
+    if (!BD->isVariadic()) {
+      S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
+      return;
+    }
   } else if (const VarDecl *V = dyn_cast<VarDecl>(D)) {
     QualType Ty = V->getType();
     if (Ty->isBlockPointerType() || Ty->isFunctionPointerType()) {
index 8554e78636310dbb3766fab089f661dc88e38a8f..14d3c045ce60e728e0afb6a009471a4595b7d2f4 100644 (file)
@@ -8806,12 +8806,6 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) {
   // Finally we can process decl attributes.
   ProcessDeclAttributes(CurScope, CurBlock->TheDecl, ParamInfo);
 
-  if (!isVariadic && CurBlock->TheDecl->getAttr<SentinelAttr>()) {
-    Diag(ParamInfo.getAttributes()->getLoc(),
-         diag::warn_attribute_sentinel_not_variadic) << 1;
-    // FIXME: remove the attribute.
-  }
-
   // Put the parameter variables in scope.  We can bail out immediately
   // if we don't have any.
   if (Params.empty())
index b5ce0da15c60d9f88ab41d9fb03a9924dbba25bd..daf0a95531440eb6e0979aa7d3f3d82f99a697ef 100644 (file)
@@ -3,7 +3,8 @@
 void (^e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1)));
 
 int main() {
-  void (^bbad) (int arg, const char * format) __attribute__ ((__sentinel__)) ; // expected-warning {{sentinel' attribute only supported for variadic blocks}}
+  void (^bbad) (int arg, const char * format) __attribute__ ((__sentinel__)) ; // expected-warning {{'sentinel' attribute only supported for variadic blocks}}
+  bbad = ^void (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}}