]> granicus.if.org Git - clang/commitdiff
Fixes a bug in ivar lookup in the new objc's default
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 19 Oct 2010 19:08:23 +0000 (19:08 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 19 Oct 2010 19:08:23 +0000 (19:08 +0000)
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

lib/Sema/SemaExpr.cpp
test/SemaObjC/provisional-ivar-lookup.m [new file with mode: 0644]

index f98aefcd562b527e3e65483fb052a05499500d85..50f023abc8e0248a53fac35b4bfa1ee4aba6de0d 100644 (file)
@@ -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 (file)
index 0000000..5267485
--- /dev/null
@@ -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
+