[cfe-commits] r155036 - in /cfe/trunk: lib/Sema/SemaPseudoObject.cpp test/SemaObjC/error-implicit-property.m
Fariborz Jahanian
fjahanian at apple.com
Wed Apr 18 12:13:24 PDT 2012
Author: fjahanian
Date: Wed Apr 18 14:13:23 2012
New Revision: 155036
URL: http://llvm.org/viewvc/llvm-project?rev=155036&view=rev
Log:
objective-c: Issue diagnostic when an implicit
property accessor (getter) missing, instead of crashing.
// rdar://11273060
Added:
cfe/trunk/test/SemaObjC/error-implicit-property.m
Modified:
cfe/trunk/lib/Sema/SemaPseudoObject.cpp
Modified: cfe/trunk/lib/Sema/SemaPseudoObject.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaPseudoObject.cpp?rev=155036&r1=155035&r2=155036&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaPseudoObject.cpp (original)
+++ cfe/trunk/lib/Sema/SemaPseudoObject.cpp Wed Apr 18 14:13:23 2012
@@ -214,6 +214,7 @@
ObjCMethodDecl *Setter;
Selector SetterSelector;
+ Selector GetterSelector;
public:
ObjCPropertyOpBuilder(Sema &S, ObjCPropertyRefExpr *refExpr) :
@@ -475,8 +476,24 @@
// For implicit properties, just trust the lookup we already did.
if (RefExpr->isImplicitProperty()) {
- Getter = RefExpr->getImplicitPropertyGetter();
- return (Getter != 0);
+ if ((Getter = RefExpr->getImplicitPropertyGetter())) {
+ GetterSelector = Getter->getSelector();
+ return true;
+ }
+ else {
+ // Must build the getter selector the hard way.
+ ObjCMethodDecl *setter = RefExpr->getImplicitPropertySetter();
+ assert(setter && "both setter and getter are null - cannot happen");
+ IdentifierInfo *setterName =
+ setter->getSelector().getIdentifierInfoForSlot(0);
+ const char *compStr = setterName->getNameStart();
+ compStr += 3;
+ IdentifierInfo *getterName = &S.Context.Idents.get(compStr);
+ GetterSelector =
+ S.PP.getSelectorTable().getNullarySelector(getterName);
+ return false;
+
+ }
}
ObjCPropertyDecl *prop = RefExpr->getExplicitProperty();
@@ -776,7 +793,7 @@
assert(RefExpr->isImplicitProperty());
S.Diag(opcLoc, diag::err_nogetter_property_incdec)
<< unsigned(UnaryOperator::isDecrementOp(opcode))
- << RefExpr->getImplicitPropertyGetter()->getSelector() // FIXME!
+ << GetterSelector
<< op->getSourceRange();
return ExprError();
}
Added: cfe/trunk/test/SemaObjC/error-implicit-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/error-implicit-property.m?rev=155036&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/error-implicit-property.m (added)
+++ cfe/trunk/test/SemaObjC/error-implicit-property.m Wed Apr 18 14:13:23 2012
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -verify %s
+// rdar://11273060
+
+ at interface I
+- (void) setP : (int)arg;
+ at end
+
+ at interface J
+ - (int) P;
+ at end
+
+ at interface K @end
+
+ at interface II @end
+
+ at implementation II
+- (void) Meth : (I*) arg {
+ arg.P++; // expected-error {{no getter method 'P' for increment of property}}
+ --arg.P; // expected-error {{no getter method 'P' for decrement of property}}
+}
+- (void) Meth1 : (J*) arg {
+ arg.P++; // expected-error {{no setter method 'setP:' for increment of property}}
+ arg.P--; // expected-error {{no setter method 'setP:' for decrement of property}}
+}
+
+- (void) Meth2 : (K*) arg {
+ arg.P++; // expected-error {{property 'P' not found on object of type 'K *'}}
+ arg.P--; // expected-error {{property 'P' not found on object of type 'K *'}}
+}
+ at end
More information about the cfe-commits
mailing list