]> granicus.if.org Git - clang/commitdiff
Don't crash when trying to apply the availability attribute to a block.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 8 Jan 2013 21:30:32 +0000 (21:30 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 8 Jan 2013 21:30:32 +0000 (21:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171899 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/Sema/attr-availability.c

index b62a4e86b1101f4e2855a87ea69db0186707b5bd..75268b8cc5a2f0621e03dd7cd75889caaf50f187 100644 (file)
@@ -2131,6 +2131,12 @@ static void handleAvailabilityAttr(Sema &S, Decl *D,
     S.Diag(PlatformLoc, diag::warn_availability_unknown_platform)
       << Platform;
 
+  NamedDecl *ND = dyn_cast<NamedDecl>(D);
+  if (!ND) {
+    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
+    return;
+  }
+
   AvailabilityChange Introduced = Attr.getAvailabilityIntroduced();
   AvailabilityChange Deprecated = Attr.getAvailabilityDeprecated();
   AvailabilityChange Obsoleted = Attr.getAvailabilityObsoleted();
@@ -2149,7 +2155,6 @@ static void handleAvailabilityAttr(Sema &S, Decl *D,
                                                       IsUnavailable, Str);
   if (NewAttr) {
     D->addAttr(NewAttr);
-    NamedDecl *ND = cast<NamedDecl>(D);
     ND->ClearLVCache();
   }
 }
index 1d4b0efed645a69e7c5ea7f5c22f75ddc559fa78..805aef804b6e67f1df73fbf2574dc69f78f4fe06 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -fblocks -verify %s
 
 void f0() __attribute__((availability(macosx,introduced=10.4,deprecated=10.2))); // expected-warning{{feature cannot be deprecated in OS X version 10.2 before it was introduced in version 10.4; attribute ignored}}
 void f1() __attribute__((availability(ios,obsoleted=2.1,deprecated=3.0)));  // expected-warning{{feature cannot be obsoleted in iOS version 2.1 before it was deprecated in version 3.0; attribute ignored}}
@@ -46,3 +46,8 @@ void f7(int) __attribute__((availability(ios,deprecated=4.0))); // expected-warn
 
 extern int x __attribute__((availability(macosx,introduced=10.5)));
 extern int x;
+
+void f8() {
+  int (^b)(int);
+  b = ^ (int i) __attribute__((availability(macosx,introduced=10.2))) { return 1; }; // expected-warning {{'availability' attribute ignored}}
+}