From 8c4222adbc0fd22928e751be6a75328fc9283a72 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 8 Jan 2013 21:30:32 +0000 Subject: [PATCH] Don't crash when trying to apply the availability attribute to a block. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171899 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclAttr.cpp | 7 ++++++- test/Sema/attr-availability.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index b62a4e86b1..75268b8cc5 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -2131,6 +2131,12 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, S.Diag(PlatformLoc, diag::warn_availability_unknown_platform) << Platform; + NamedDecl *ND = dyn_cast(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(D); ND->ClearLVCache(); } } diff --git a/test/Sema/attr-availability.c b/test/Sema/attr-availability.c index 1d4b0efed6..805aef804b 100644 --- a/test/Sema/attr-availability.c +++ b/test/Sema/attr-availability.c @@ -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}} +} -- 2.40.0