From: Fariborz Jahanian Date: Tue, 19 Oct 2010 19:08:23 +0000 (+0000) Subject: Fixes a bug in ivar lookup in the new objc's default X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=43e1b46d640e9e9c9faa784fe6a6d8252f4e776a;p=clang Fixes a bug in ivar lookup in the new objc's default property synthesis mode, when dealing with legacy code. Fixes //rdar: //8565343. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116846 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index f98aefcd56..50f023abc8 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1068,9 +1068,14 @@ static ObjCIvarDecl *SynthesizeProvisionalIvar(Sema &SemaRef, ObjCPropertyDecl *property = SemaRef.LookupPropertyDecl(IDecl, II); if (!property) return 0; - if (ObjCPropertyImplDecl *PIDecl = ClassImpDecl->FindPropertyImplDecl(II)) + if (ObjCPropertyImplDecl *PIDecl = ClassImpDecl->FindPropertyImplDecl(II)) { DynamicImplSeen = (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); + // property implementation has a designated ivar. No need to assume a new + // one. + if (!DynamicImplSeen && PIDecl->getPropertyIvarDecl()) + return 0; + } if (!DynamicImplSeen) { QualType PropType = SemaRef.Context.getCanonicalType(property->getType()); ObjCIvarDecl *Ivar = ObjCIvarDecl::Create(SemaRef.Context, ClassImpDecl, diff --git a/test/SemaObjC/provisional-ivar-lookup.m b/test/SemaObjC/provisional-ivar-lookup.m new file mode 100644 index 0000000000..526748538e --- /dev/null +++ b/test/SemaObjC/provisional-ivar-lookup.m @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s + +// rdar:// 8565343 +@interface Foo { +@private + int _foo; + int _foo2; +} +@property (readwrite, nonatomic) int foo, foo1, foo2, foo3; +@property (readwrite, nonatomic) int PROP; +@end + +@implementation Foo + +@synthesize foo = _foo; +@synthesize foo1; + +- (void)setFoo:(int)value { + _foo = foo; // expected-error {{use of undeclared identifier 'foo'}} +} + +- (void)setFoo1:(int)value { + _foo = foo1; // OK +} + +- (void)setFoo2:(int)value { + _foo = foo2; // expected-error {{use of undeclared identifier 'foo2'}} +} + +- (void)setFoo3:(int)value { + _foo = foo3; // OK +} + +@synthesize foo2 = _foo2; +@synthesize foo3; + +@synthesize PROP=PROP; +- (void)setPROP:(int)value { + PROP = PROP; // OK +} + +@end +