From: Eli Friedman Date: Thu, 29 Nov 2012 03:13:49 +0000 (+0000) Subject: Fix crash-on-invalid. . X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a70779f6b9a8135c3459bdeb1f0197b82ea0cb2a;p=clang Fix crash-on-invalid. . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168851 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index b31fb6b9b7..0ee99f5ced 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -4182,7 +4182,7 @@ def err_property_not_found : Error< def err_invalid_property_name : Error< "%0 is not a valid property name (accessing an object of type %1)">; def err_getter_not_found : Error< - "expected getter method not found on object of type %0">; + "no getter method for read from property">; def err_objc_subscript_method_not_found : Error< "expected method to %select{read|write}1 %select{dictionary|array}2 element not " "found on object of type %0">; diff --git a/lib/Sema/SemaPseudoObject.cpp b/lib/Sema/SemaPseudoObject.cpp index 74d0818b0e..67bf742384 100644 --- a/lib/Sema/SemaPseudoObject.cpp +++ b/lib/Sema/SemaPseudoObject.cpp @@ -113,7 +113,7 @@ namespace { Expr *rebuildSpecific(ObjCPropertyRefExpr *refExpr) { // Fortunately, the constraint that we're rebuilding something // with a base limits the number of cases here. - assert(refExpr->getBase()); + assert(refExpr->isObjectReceiver()); if (refExpr->isExplicitProperty()) { return new (S.Context) @@ -713,10 +713,9 @@ ExprResult ObjCPropertyOpBuilder::buildSet(Expr *op, SourceLocation opcLoc, ExprResult ObjCPropertyOpBuilder::buildRValueOperation(Expr *op) { // Explicit properties always have getters, but implicit ones don't. // Check that before proceeding. - if (RefExpr->isImplicitProperty() && - !RefExpr->getImplicitPropertyGetter()) { + if (RefExpr->isImplicitProperty() && !RefExpr->getImplicitPropertyGetter()) { S.Diag(RefExpr->getLocation(), diag::err_getter_not_found) - << RefExpr->getBase()->getType(); + << RefExpr->getSourceRange(); return ExprError(); } diff --git a/test/SemaObjC/error-missing-getter.m b/test/SemaObjC/error-missing-getter.m index 3c91ab2ffc..3dce858837 100644 --- a/test/SemaObjC/error-missing-getter.m +++ b/test/SemaObjC/error-missing-getter.m @@ -9,11 +9,34 @@ @end int func (int arg, Subclass *x) { - if (x.setterOnly) { // expected-error {{expected getter method not found on object of type 'Subclass *'}} + if (x.setterOnly) { // expected-error {{no getter method for read from property}} x.setterOnly = 1; } - func(x.setterOnly + 1, x); // expected-error {{expected getter method not found on object of type 'Subclass *'}} - int i = x.setterOnly + 1; // expected-error {{expected getter method not found on object of type 'Subclass *'}} - return x.setterOnly + 1; // expected-error {{expected getter method not found on object of type 'Subclass *'}} + func(x.setterOnly + 1, x); // expected-error {{no getter method for read from property}} + int i = x.setterOnly + 1; // expected-error {{no getter method for read from property}} + return x.setterOnly + 1; // expected-error {{no getter method for read from property}} } +// + +@interface TestClass ++ (void) setSetterOnly : (int) arg; +@end + +int func2 (int arg) { + if (TestClass.setterOnly) { // expected-error {{no getter method for read from property}} + TestClass.setterOnly = 1; + } + func(TestClass.setterOnly + 1, x); // expected-error {{no getter method for read from property}} + int i = TestClass.setterOnly + 1; // expected-error {{no getter method for read from property}} + return TestClass.setterOnly + 1; // expected-error {{no getter method for read from property}} +} + +@interface Sub : Subclass +- (int) func3; +@end +@implementation Sub +- (int) func3 { + return super.setterOnly; // expected-error {{no getter method for read from property}} +} +@end diff --git a/test/SemaObjC/property-user-setter.m b/test/SemaObjC/property-user-setter.m index 9ebad6048d..cda983c9ec 100644 --- a/test/SemaObjC/property-user-setter.m +++ b/test/SemaObjC/property-user-setter.m @@ -89,7 +89,7 @@ void g(int); // expected-note {{passing argument to parameter here}} void f(C *c) { c.Foo = 17; // OK - g(c.Foo); // expected-error {{expected getter method not found on object of type 'C *'}} + g(c.Foo); // expected-error {{no getter method for read from property}} } @@ -132,7 +132,7 @@ int main (void) { self.Pxyz = 0; // expected-error {{synthesized properties 'Pxyz' and 'pxyz' both claim setter 'setPxyz:'}} self.pxyz = 0; // expected-error {{synthesized properties 'pxyz' and 'Pxyz' both claim setter 'setPxyz:'}} self.R = 0; - return self.R; // expected-error {{expected getter method not found on object of type 'rdar11363363 *'}} + return self.R; // expected-error {{no getter method for read from property}} } @end diff --git a/test/SemaObjCXX/properties.mm b/test/SemaObjCXX/properties.mm index 0783eebc11..804d6829b1 100644 --- a/test/SemaObjCXX/properties.mm +++ b/test/SemaObjCXX/properties.mm @@ -28,7 +28,7 @@ struct X { - (int) z; @end void test2(Test2 *a) { - auto y = a.y; // expected-error {{expected getter method not found on object of type 'Test2 *'}} + auto y = a.y; // expected-error {{no getter method for read from property}} auto z = a.z; }