[PATCH] D63176: [SemaObjC] Infer availability of stuff declared in categories from the availability of the enclosing category

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 11 17:03:01 PDT 2019


erik.pilkington created this revision.
erik.pilkington added reviewers: arphaman, steven_wu.
Herald added subscribers: dexonsmith, jkorous.
Herald added a project: clang.

These extend the class, but (unlike methods in @interfaces) can be referenced without mentioning the the category, so we don't otherwise emit a diagnostic.

rdar://51318091


Repository:
  rC Clang

https://reviews.llvm.org/D63176

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/unguarded-availability.m


Index: clang/test/SemaObjC/unguarded-availability.m
===================================================================
--- clang/test/SemaObjC/unguarded-availability.m
+++ clang/test/SemaObjC/unguarded-availability.m
@@ -353,3 +353,41 @@
 void is_destructor() {
   func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
 }
+
+ at interface HasCat
+-(void)meth;
++(void)class_meth;
+ at property int prop;
+ at end
+
+AVAILABLE_10_11
+// FIXME: The pretty-printing for categories sucks.
+ at interface HasCat () // expected-note 3 {{'' has been marked as being introduced in macOS 10.11 here, but the deployment target is macOS 10.9.0}}
+-(void)meth1;
++(void)class_meth1;
+
+ at property int prop1;
+
+ at end
+
+AVAILABLE_10_12
+ at interface HasCat (Named) // expected-note{{'Named' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9.0}}
+-(void)meth2;
+ at end
+
+ at interface HasCat (OtherNamed)
+-(void)meth3;
+ at end
+
+void test_category(HasCat *hc) {
+  [hc meth];
+  [hc meth1]; // expected-warning{{'meth1' is only available on macOS 10.11 or newer}} expected-note{{enclose 'meth1' in an @available check to silence this warning}}
+  [hc meth2]; // expected-warning{{'meth2' is only available on macOS 10.12 or newer}} expected-note{{enclose 'meth2' in an @available check to silence this warning}}
+  [hc meth3];
+
+  [HasCat class_meth];
+  [HasCat class_meth1]; // expected-warning{{'class_meth1' is only available on macOS 10.11 or newer}} expected-note{{enclose 'class_meth1' in an @available check to silence this warning}}
+
+  hc.prop = 42;
+  hc.prop1 = 42; // expected-warning{{'setProp1:' is only available on macOS 10.11 or newer}} expected-note{{enclose 'setProp1:' in an @available check to silence this warning}}
+}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -7716,6 +7716,15 @@
     }
   }
 
+  // If this entity was declared in an Objective-C category then infer its
+  // availability from the category's availability.
+  if (auto *CatDecl = dyn_cast<ObjCCategoryDecl>(D->getDeclContext())) {
+    if (Result == AR_Available) {
+      Result = CatDecl->getAvailability(Message);
+      D = CatDecl;
+    }
+  }
+
   return {Result, D};
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63176.204193.patch
Type: text/x-patch
Size: 2449 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190612/832aa8cc/attachment.bin>


More information about the cfe-commits mailing list