]> granicus.if.org Git - clang/commitdiff
Fix a bug in nonfragile-abi2 when attempting to diagnose
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 24 Aug 2010 18:48:05 +0000 (18:48 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 24 Aug 2010 18:48:05 +0000 (18:48 +0000)
previous use of a synthesized 'ivar' with property of same name
declared as @dynamic. In this case, 'ivar' is in the
inherited class and no diagnostics should be issued.

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

lib/Sema/SemaObjCProperty.cpp
test/SemaObjC/property-and-ivar-use.m [new file with mode: 0644]

index ccb9a15ff257b9cdbcf2dcc5542da54a591e9763..91f47ab708232f59421133fe8bbe39bf6d7a2890 100644 (file)
@@ -521,7 +521,7 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S,
     if (getLangOptions().ObjCNonFragileABI2) {
       // Diagnose if an ivar was lazily synthesdized due to a previous
       // use and if 1) property is @dynamic or 2) property is synthesized
-      // but it requires a dirreferently named ivar.
+      // but it requires an ivar of different name.
       ObjCInterfaceDecl *ClassDeclared;
       ObjCIvarDecl *Ivar = 0;
       if (!Synthesize)
@@ -530,7 +530,9 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S,
         if (PropertyIvar && PropertyIvar != PropertyId)
           Ivar = IDecl->lookupInstanceVariable(PropertyId, ClassDeclared);
       }
-      if (Ivar && Ivar->getSynthesize()) {
+      // Issue diagnostics only if Ivar belongs to current class.
+      if (Ivar && Ivar->getSynthesize() && 
+          IC->getClassInterface() == ClassDeclared) {
         Diag(Ivar->getLocation(), diag::err_undeclared_var_use) 
         << PropertyId;
         Ivar->setInvalidDecl();
diff --git a/test/SemaObjC/property-and-ivar-use.m b/test/SemaObjC/property-and-ivar-use.m
new file mode 100644 (file)
index 0000000..b9235c1
--- /dev/null
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+// Do not issue error if 'ivar' used previously belongs to the inherited class
+// and has same name as @dynalic property in current class.
+
+typedef signed char BOOL;
+
+@protocol IDEBuildable
+@property (readonly) BOOL hasRecursiveDependencyCycle;
+@end
+
+@protocol IDEBuildableProduct <IDEBuildable>
+@end
+
+@interface IDEBuildableSupportMixIn 
+@property (readonly) BOOL hasRecursiveDependencyCycle;
+@end
+
+@interface Xcode3TargetBuildable <IDEBuildable>
+{
+  IDEBuildableSupportMixIn *_buildableMixIn;
+}
+@end
+
+@interface Xcode3TargetProduct : Xcode3TargetBuildable <IDEBuildableProduct>
+@end
+
+@implementation Xcode3TargetBuildable
+- (BOOL)hasRecursiveDependencyCycle
+{
+    return [_buildableMixIn hasRecursiveDependencyCycle];
+}
+@end
+
+@implementation Xcode3TargetProduct
+@dynamic hasRecursiveDependencyCycle;
+@end