[PATCH] D102459: [clang][ObjC] Allow different availability annotation on a method when implementing an optional protocol requirement

2021-05-19 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG50be48b0f3c8: [clang][ObjC] Allow different availability 
annotation on a method (authored by arphaman).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102459/new/

https://reviews.llvm.org/D102459

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/attr-availability.m
  clang/test/SemaObjC/override-opt-prop-availability.m

Index: clang/test/SemaObjC/override-opt-prop-availability.m
===
--- /dev/null
+++ clang/test/SemaObjC/override-opt-prop-availability.m
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -fsyntax-only -verify %s
+
+@protocol P
+
+@property (nonatomic) int reqProp __attribute__((availability(ios, introduced=12.0))); // expected-note 2 {{is here}}
+
+
+
+@optional
+@property (nonatomic) int myProp __attribute__((availability(ios, introduced=12.0))); // expected-note {{has been marked as being introduced in}}
+
+@optional
+@property (nonatomic, readonly) int depProp __attribute__((availability(ios, introduced=8.0, deprecated=12.0))); // expected-note {{protocol method is here}}
+
+@optional
+@property (nonatomic) int obsProp __attribute__((availability(ios, introduced=8.0, obsoleted=12.0)));
+
+@optional
+- (void) unavaibleInClass __attribute__((availability(ios, introduced=12.0))); // expected-note {{method is here}}
+
+@end
+
+@interface X 
+
+@property (nonatomic) int myProp __attribute__((availability(ios, introduced=13.0))); // expected-note 2 {{has been marked as being introduced in}}
+
+@property (nonatomic) int reqProp __attribute__((availability(ios, introduced=13.0))); // expected-warning 2 {{method introduced after the protocol method it implements on iOS}}
+
+@property (nonatomic, readonly) int depProp __attribute__((availability(ios, introduced=8.0, deprecated=10.0))); // expected-warning {{method deprecated before the protocol method it implements on iOS (12.0 vs. 10.0)}} expected-note {{been explicitly marked deprecated here}}
+
+@property (nonatomic) int obsProp __attribute__((availability(ios, introduced=8.0, obsoleted=10.0))); // expected-note {{been explicitly marked unavailable here}}
+
+- (void) unavaibleInClass __attribute__((availability(ios, unavailable))); // expected-warning {{method cannot be unavailable on iOS when the protocol method it implements is available}}
+
+@end
+
+
+void test(X *x) {
+  int i =  x.myProp;  // expected-warning {{'myProp' is only available on iOS 13.0 or newer}} expected-note {{enclose}}
+  x.myProp = i;   // expected-warning {{'setMyProp:' is only available on iOS 13.0 or newer}} expected-note {{enclose}}
+  int i2 = x.depProp; // expected-warning {{'depProp' is deprecated: first deprecated in iOS 10.0}}
+  int i3 = x.obsProp; // expected-error {{'obsProp' is unavailable: obsoleted in iOS 10.0}}
+}
+
+void testProto(id x) {
+  int i = x.myProp; // expected-warning {{'myProp' is only available on iOS 12.0 or newer}} expected-note {{enclose}}
+}
Index: clang/test/SemaObjC/attr-availability.m
===
--- clang/test/SemaObjC/attr-availability.m
+++ clang/test/SemaObjC/attr-availability.m
@@ -229,8 +229,7 @@
 // inherited be implementations of those protocol methods.
 @protocol AvailabilityP2
 @optional
--(void)methodA __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note 4{{'methodA' has been explicitly marked deprecated here}} \
-// expected-note 2{{protocol method is here}}
+-(void)methodA __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note 4{{'methodA' has been explicitly marked deprecated here}}
 -(void)methodB __attribute__((unavailable)); // expected-note 4{{'methodB' has been explicitly marked unavailable here}}
 -(void)methodC;
 @end
@@ -279,7 +278,7 @@
 
 __attribute__((objc_root_class))
 @interface ImplementsAvailabilityP2c 
--(void)methodA __attribute__((availability(macosx,introduced=10.2))); // expected-warning{{method introduced after the protocol method it implements on macOS (10.2 vs. 10.1)}}
+-(void)methodA __attribute__((availability(macosx,introduced=10.2)));
 -(void)methodB __attribute__((unavailable));
 @end
 
@@ -288,7 +287,7 @@
 @end
 
 @implementation ImplementsAvailabilityP2d
--(void)methodA __attribute__((availability(macosx,introduced=10.2))) // expected-warning{{method introduced after the protocol method it implements on macOS (10.2 vs. 10.1)}}
+-(void)methodA __attribute__((availability(macosx,introduced=10.2)))
 {
 }
 -(void)methodB __attribute__((unavailable)) {
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2300,6 +2300,7 @@
 

[PATCH] D102459: [clang][ObjC] Allow different availability annotation on a method when implementing an optional protocol requirement

2021-05-14 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington accepted this revision.
erik.pilkington added a comment.
This revision is now accepted and ready to land.

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102459/new/

https://reviews.llvm.org/D102459

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102459: [clang][ObjC] Allow different availability annotation on a method when implementing an optional protocol requirement

2021-05-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 345529.
arphaman added a comment.

Do not apply this to 'deprecated' availability annotations - the user has no 
way to check for deprecated as `respondsToSelector` will still return true even 
if the class has marked the method as deprecated.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102459/new/

https://reviews.llvm.org/D102459

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/attr-availability.m
  clang/test/SemaObjC/override-opt-prop-availability.m

Index: clang/test/SemaObjC/override-opt-prop-availability.m
===
--- /dev/null
+++ clang/test/SemaObjC/override-opt-prop-availability.m
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -fsyntax-only -verify %s
+
+@protocol P
+
+@property (nonatomic) int reqProp __attribute__((availability(ios, introduced=12.0))); // expected-note 2 {{is here}}
+
+
+
+@optional
+@property (nonatomic) int myProp __attribute__((availability(ios, introduced=12.0))); // expected-note {{has been marked as being introduced in}}
+
+@optional
+@property (nonatomic, readonly) int depProp __attribute__((availability(ios, introduced=8.0, deprecated=12.0))); // expected-note {{protocol method is here}}
+
+@optional
+@property (nonatomic) int obsProp __attribute__((availability(ios, introduced=8.0, obsoleted=12.0)));
+
+@optional
+- (void) unavaibleInClass __attribute__((availability(ios, introduced=12.0))); // expected-note {{method is here}}
+
+@end
+
+@interface X 
+
+@property (nonatomic) int myProp __attribute__((availability(ios, introduced=13.0))); // expected-note 2 {{has been marked as being introduced in}}
+
+@property (nonatomic) int reqProp __attribute__((availability(ios, introduced=13.0))); // expected-warning 2 {{method introduced after the protocol method it implements on iOS}}
+
+@property (nonatomic, readonly) int depProp __attribute__((availability(ios, introduced=8.0, deprecated=10.0))); // expected-warning {{method deprecated before the protocol method it implements on iOS (12.0 vs. 10.0)}} expected-note {{been explicitly marked deprecated here}}
+
+@property (nonatomic) int obsProp __attribute__((availability(ios, introduced=8.0, obsoleted=10.0))); // expected-note {{been explicitly marked unavailable here}}
+
+- (void) unavaibleInClass __attribute__((availability(ios, unavailable))); // expected-warning {{method cannot be unavailable on iOS when the protocol method it implements is available}}
+
+@end
+
+
+void test(X *x) {
+  int i =  x.myProp;  // expected-warning {{'myProp' is only available on iOS 13.0 or newer}} expected-note {{enclose}}
+  x.myProp = i;   // expected-warning {{'setMyProp:' is only available on iOS 13.0 or newer}} expected-note {{enclose}}
+  int i2 = x.depProp; // expected-warning {{'depProp' is deprecated: first deprecated in iOS 10.0}}
+  int i3 = x.obsProp; // expected-error {{'obsProp' is unavailable: obsoleted in iOS 10.0}}
+}
+
+void testProto(id x) {
+  int i = x.myProp; // expected-warning {{'myProp' is only available on iOS 12.0 or newer}} expected-note {{enclose}}
+}
Index: clang/test/SemaObjC/attr-availability.m
===
--- clang/test/SemaObjC/attr-availability.m
+++ clang/test/SemaObjC/attr-availability.m
@@ -229,8 +229,7 @@
 // inherited be implementations of those protocol methods.
 @protocol AvailabilityP2
 @optional
--(void)methodA __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note 4{{'methodA' has been explicitly marked deprecated here}} \
-// expected-note 2{{protocol method is here}}
+-(void)methodA __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note 4{{'methodA' has been explicitly marked deprecated here}}
 -(void)methodB __attribute__((unavailable)); // expected-note 4{{'methodB' has been explicitly marked unavailable here}}
 -(void)methodC;
 @end
@@ -279,7 +278,7 @@
 
 __attribute__((objc_root_class))
 @interface ImplementsAvailabilityP2c 
--(void)methodA __attribute__((availability(macosx,introduced=10.2))); // expected-warning{{method introduced after the protocol method it implements on macOS (10.2 vs. 10.1)}}
+-(void)methodA __attribute__((availability(macosx,introduced=10.2)));
 -(void)methodB __attribute__((unavailable));
 @end
 
@@ -288,7 +287,7 @@
 @end
 
 @implementation ImplementsAvailabilityP2d
--(void)methodA __attribute__((availability(macosx,introduced=10.2))) // expected-warning{{method introduced after the protocol method it implements on macOS (10.2 vs. 10.1)}}
+-(void)methodA __attribute__((availability(macosx,introduced=10.2)))
 {
 }
 -(void)methodB __attribute__((unavailable)) {
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ 

[PATCH] D102459: [clang][ObjC] Allow different availability annotation on a method when implementing an optional protocol requirement

2021-05-13 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added a reviewer: erik.pilkington.
Herald added subscribers: ributzka, jfb.
Herald added a reviewer: aaron.ballman.
arphaman requested review of this revision.

When an Objective-C method implements an optional protocol requirement,
allow the method to use a newer introduced or older deprecated / obsoleted
availability version than what's specified on the method in the protocol 
itself. 
This allows SDK adopters to adopt an optional method from a
protocol later than when the method is introduced in the protocol. The users
that call an optional method on an object that conforms to this protocol
are supposed to check whether the object implements the method or not,
so a lack of appropriate `if (@available)` check for a new OS version
is not a cause of concern as there's already another runtime check that's 
required.


https://reviews.llvm.org/D102459

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/attr-availability.m
  clang/test/SemaObjC/override-opt-prop-availability.m

Index: clang/test/SemaObjC/override-opt-prop-availability.m
===
--- /dev/null
+++ clang/test/SemaObjC/override-opt-prop-availability.m
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -fsyntax-only -verify %s
+
+@protocol P
+
+@property (nonatomic) int reqProp __attribute__((availability(ios, introduced=12.0))); // expected-note 2 {{is here}}
+
+
+
+@optional
+@property (nonatomic) int myProp __attribute__((availability(ios, introduced=12.0))); // expected-note {{has been marked as being introduced in}}
+
+@optional
+@property (nonatomic) int depProp __attribute__((availability(ios, introduced=8.0, deprecated=12.0)));
+
+@optional
+@property (nonatomic) int obsProp __attribute__((availability(ios, introduced=8.0, obsoleted=12.0)));
+
+@optional
+- (void) unavaibleInClass __attribute__((availability(ios, introduced=12.0))); // expected-note {{method is here}}
+
+@end
+
+@interface X 
+
+@property (nonatomic) int myProp __attribute__((availability(ios, introduced=13.0))); // expected-note 2 {{has been marked as being introduced in}}
+
+@property (nonatomic) int reqProp __attribute__((availability(ios, introduced=13.0))); // expected-warning 2 {{method introduced after the protocol method it implements on iOS}}
+
+@property (nonatomic) int depProp __attribute__((availability(ios, introduced=8.0, deprecated=10.0))); // expected-note {{has been explicitly marked deprecated here}}
+
+@property (nonatomic) int obsProp __attribute__((availability(ios, introduced=8.0, obsoleted=10.0))); // expected-note {{been explicitly marked unavailable here}}
+
+- (void) unavaibleInClass __attribute__((availability(ios, unavailable))); // expected-warning {{method cannot be unavailable on iOS when the protocol method it implements is available}}
+
+@end
+
+
+void test(X *x) {
+  int i =  x.myProp;  // expected-warning {{'myProp' is only available on iOS 13.0 or newer}} expected-note {{enclose}}
+  x.myProp = i;   // expected-warning {{'setMyProp:' is only available on iOS 13.0 or newer}} expected-note {{enclose}}
+  int i2 = x.depProp; // expected-warning {{'depProp' is deprecated: first deprecated in iOS 10.0}}
+  int i3 = x.obsProp; // expected-error {{'obsProp' is unavailable: obsoleted in iOS 10.0}}
+}
+
+void testProto(id x) {
+  int i = x.myProp; // expected-warning {{'myProp' is only available on iOS 12.0 or newer}} expected-note {{enclose}}
+}
Index: clang/test/SemaObjC/attr-availability.m
===
--- clang/test/SemaObjC/attr-availability.m
+++ clang/test/SemaObjC/attr-availability.m
@@ -229,8 +229,7 @@
 // inherited be implementations of those protocol methods.
 @protocol AvailabilityP2
 @optional
--(void)methodA __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note 4{{'methodA' has been explicitly marked deprecated here}} \
-// expected-note 2{{protocol method is here}}
+-(void)methodA __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note 4{{'methodA' has been explicitly marked deprecated here}}
 -(void)methodB __attribute__((unavailable)); // expected-note 4{{'methodB' has been explicitly marked unavailable here}}
 -(void)methodC;
 @end
@@ -279,7 +278,7 @@
 
 __attribute__((objc_root_class))
 @interface ImplementsAvailabilityP2c 
--(void)methodA __attribute__((availability(macosx,introduced=10.2))); // expected-warning{{method introduced after the protocol method it implements on macOS (10.2 vs. 10.1)}}
+-(void)methodA __attribute__((availability(macosx,introduced=10.2)));
 -(void)methodB __attribute__((unavailable));
 @end
 
@@ -288,7 +287,7 @@
 @end
 
 @implementation ImplementsAvailabilityP2d
--(void)methodA __attribute__((availability(macosx,introduced=10.2))) // expected-warning{{method introduced after the protocol