]> granicus.if.org Git - clang/commitdiff
Sema: use PropertyDecl for property selector
authorSaleem Abdulrasool <compnerd@compnerd.org>
Mon, 20 Feb 2017 23:45:49 +0000 (23:45 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Mon, 20 Feb 2017 23:45:49 +0000 (23:45 +0000)
Using the constructed name for the class properties with dot syntax may
yield an inappropriate selector (i.e. if it is specified via property
attributes).  Prefer the declaration for the selector, falling back to
the constructed name otherwise.

Patch by David Herzka!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295683 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprObjC.cpp
test/SemaObjC/objc-class-property.m

index d770d1b5404e82b283e3fd0363f8d20c948e5c32..3039e12585afac3f09217e78505b3abd8b5e6909 100644 (file)
@@ -1984,13 +1984,24 @@ ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
     }
   }
 
+  Selector GetterSel;
+  Selector SetterSel;
+  if (auto PD = IFace->FindPropertyDeclaration(
+          &propertyName, ObjCPropertyQueryKind::OBJC_PR_query_class)) {
+    GetterSel = PD->getGetterName();
+    SetterSel = PD->getSetterName();
+  } else {
+    GetterSel = PP.getSelectorTable().getNullarySelector(&propertyName);
+    SetterSel = SelectorTable::constructSetterSelector(
+        PP.getIdentifierTable(), PP.getSelectorTable(), &propertyName);
+  }
+
   // Search for a declared property first.
-  Selector Sel = PP.getSelectorTable().getNullarySelector(&propertyName);
-  ObjCMethodDecl *Getter = IFace->lookupClassMethod(Sel);
+  ObjCMethodDecl *Getter = IFace->lookupClassMethod(GetterSel);
 
   // If this reference is in an @implementation, check for 'private' methods.
   if (!Getter)
-    Getter = IFace->lookupPrivateClassMethod(Sel);
+    Getter = IFace->lookupPrivateClassMethod(GetterSel);
 
   if (Getter) {
     // FIXME: refactor/share with ActOnMemberReference().
@@ -2000,11 +2011,6 @@ ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
   }
 
   // Look for the matching setter, in case it is needed.
-  Selector SetterSel =
-    SelectorTable::constructSetterSelector(PP.getIdentifierTable(),
-                                            PP.getSelectorTable(),
-                                           &propertyName);
-
   ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel);
   if (!Setter) {
     // If this reference is in an @implementation, also check for 'private'
index 56285976e19415115922831f1d4f746df684dc55..f8d49112766df0b4d20bb73007475d00bc693346 100644 (file)
@@ -21,6 +21,8 @@
 @property (class) int c2; // expected-note {{property declared here}} \
                           // expected-note {{property declared here}}
 @property (class) int x;
+@property (class, setter=customSet:) int customSetterProperty;
+@property (class, getter=customGet) int customGetterProperty;
 @end
 
 @implementation A // expected-warning {{class property 'c2' requires method 'c2' to be defined}} \
@@ -29,6 +31,8 @@
 @dynamic (class) x; // refers to the class property
 @synthesize z, c2; // expected-error {{@synthesize not allowed on a class property 'c2'}}
 @dynamic c; // refers to the class property
+@dynamic customSetterProperty;
+@dynamic customGetterProperty;
 @end
 
 int test() {
@@ -37,6 +41,11 @@ int test() {
   return a.x + A.c;
 }
 
+void customSelectors() {
+  A.customSetterProperty = 1;
+  (void)A.customGetterProperty;
+}
+
 void message_id(id me) {
   [me y];
 }