[cfe-commits] r120855 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaExprObjC.cpp test/SemaObjC/property-impl-misuse.m

Fariborz Jahanian fjahanian at apple.com
Fri Dec 3 15:37:09 PST 2010


Author: fjahanian
Date: Fri Dec  3 17:37:08 2010
New Revision: 120855

URL: http://llvm.org/viewvc/llvm-project?rev=120855&view=rev
Log:
Diagnose when accessing property in a class method and
no property accessor class method to be found, instead of
crashing in IRGen. // rdar://8703553

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/test/SemaObjC/property-impl-misuse.m

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=120855&r1=120854&r2=120855&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Dec  3 17:37:08 2010
@@ -639,7 +639,7 @@
   ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
   
   // Lookup a method in the classes implementation hierarchy.
-  ObjCMethodDecl *lookupPrivateInstanceMethod(const Selector &Sel);
+  ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, bool Instance=true);
 
   // Location information, modeled after the Stmt API.
   SourceLocation getLocStart() const { return getLocation(); } // '@'interface

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=120855&r1=120854&r2=120855&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Dec  3 17:37:08 2010
@@ -311,14 +311,16 @@
   return NULL;
 }
 
-ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateInstanceMethod(
-                                   const Selector &Sel) {
+ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod(
+                                   const Selector &Sel,
+                                   bool Instance) {
   ObjCMethodDecl *Method = 0;
   if (ObjCImplementationDecl *ImpDecl = getImplementation())
-    Method = ImpDecl->getInstanceMethod(Sel);
+    Method = Instance ? ImpDecl->getInstanceMethod(Sel) 
+                      : ImpDecl->getClassMethod(Sel);
   
   if (!Method && getSuperClass())
-    return getSuperClass()->lookupPrivateInstanceMethod(Sel);
+    return getSuperClass()->lookupPrivateMethod(Sel, Instance);
   return Method;
 }
 

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=120855&r1=120854&r2=120855&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Dec  3 17:37:08 2010
@@ -3498,12 +3498,13 @@
     if (ObjCMethodDecl *MD = getCurMethodDecl()) {
       ObjCInterfaceDecl *IFace = MD->getClassInterface();
       ObjCMethodDecl *Getter;
-      // FIXME: need to also look locally in the implementation.
       if ((Getter = IFace->lookupClassMethod(Sel))) {
         // Check the use of this method.
         if (DiagnoseUseOfDecl(Getter, MemberLoc))
           return ExprError();
       }
+      else
+        Getter = IFace->lookupPrivateMethod(Sel, false);
       // If we found a getter then this may be a valid dot-reference, we
       // will look for the matching setter, in case it is needed.
       Selector SetterSel =
@@ -3513,7 +3514,7 @@
       if (!Setter) {
         // If this reference is in an @implementation, also check for 'private'
         // methods.
-        Setter = IFace->lookupPrivateInstanceMethod(SetterSel);
+        Setter = IFace->lookupPrivateMethod(SetterSel, false);
       }
       // Look through local category implementations associated with the class.
       if (!Setter)

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=120855&r1=120854&r2=120855&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Fri Dec  3 17:37:08 2010
@@ -402,7 +402,7 @@
 
   // If this reference is in an @implementation, check for 'private' methods.
   if (!Getter)
-    Getter = IFace->lookupPrivateInstanceMethod(Sel);
+    Getter = IFace->lookupPrivateMethod(Sel);
 
   // Look through local category implementations associated with the class.
   if (!Getter)
@@ -421,7 +421,7 @@
   if (!Setter) {
     // If this reference is in an @implementation, also check for 'private'
     // methods.
-    Setter = IFace->lookupPrivateInstanceMethod(SetterSel);
+    Setter = IFace->lookupPrivateMethod(SetterSel);
   }
   // Look through local category implementations associated with the class.
   if (!Setter)

Modified: cfe/trunk/test/SemaObjC/property-impl-misuse.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-impl-misuse.m?rev=120855&r1=120854&r2=120855&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-impl-misuse.m (original)
+++ cfe/trunk/test/SemaObjC/property-impl-misuse.m Fri Dec  3 17:37:08 2010
@@ -14,3 +14,23 @@
 @synthesize Y; // expected-note {{previous use is here}}
 @synthesize Z=Y; // expected-error {{synthesized properties 'Z' and 'Y' both claim ivar 'Y'}}
 @end
+
+// rdar://8703553
+ at interface IDEPathCell 
+{
+ at private
+    id _gradientStyle;
+}
+
+ at property (readwrite, assign, nonatomic) id gradientStyle;
+ at end
+
+ at implementation IDEPathCell
+
+ at synthesize gradientStyle = _gradientStyle;
+- (void)setGradientStyle:(id)value { }
+
++ (void)_componentCellWithRepresentedObject {
+    self.gradientStyle; // expected-error {{property 'gradientStyle' not found on object of type 'Class'}}
+}
+ at end





More information about the cfe-commits mailing list