[cfe-commits] r51969 - in /cfe/trunk: lib/Sema/SemaExprObjC.cpp test/Sema/objc-typedef-class.m

Steve Naroff snaroff at apple.com
Wed Jun 4 16:08:39 PDT 2008


Author: snaroff
Date: Wed Jun  4 18:08:38 2008
New Revision: 51969

URL: http://llvm.org/viewvc/llvm-project?rev=51969&view=rev
Log:
Fix crash identified by <rdar://problem/5986085>.


Added:
    cfe/trunk/test/Sema/objc-typedef-class.m
Modified:
    cfe/trunk/lib/Sema/SemaExprObjC.cpp

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=51969&r1=51968&r2=51969&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Jun  4 18:08:38 2008
@@ -166,19 +166,31 @@
   } else
     ClassDecl = getObjCInterfaceDecl(receiverName);
   
-  // FIXME: can ClassDecl ever be null?
-  ObjCMethodDecl *Method = ClassDecl->lookupClassMethod(Sel);
+  // ClassDecl is null in the following case.
+  //
+  //  typedef XCElementDisplayRect XCElementGraphicsRect;
+  //
+  //  @implementation XCRASlice
+  //  - whatever { // Note that XCElementGraphicsRect is a typedef name.
+  //    _sGraphicsDelegate =[[XCElementGraphicsRect alloc] init];
+  //  }
+  //
+  // FIXME: Investigate why GCC allows the above.
+  ObjCMethodDecl *Method = 0;
   QualType returnType;
-  
-  // If we have an implementation in scope, check "private" methods.
-  if (!Method) {
-    if (ObjCImplementationDecl *ImpDecl = 
-        ObjCImplementations[ClassDecl->getIdentifier()])
-      Method = ImpDecl->getClassMethod(Sel);
+  if (ClassDecl) {
+    Method = ClassDecl->lookupClassMethod(Sel);
+    
+    // If we have an implementation in scope, check "private" methods.
+    if (!Method) {
+      if (ObjCImplementationDecl *ImpDecl = 
+          ObjCImplementations[ClassDecl->getIdentifier()])
+        Method = ImpDecl->getClassMethod(Sel);
+    }
+    // Before we give up, check if the selector is an instance method.
+    if (!Method)
+      Method = ClassDecl->lookupInstanceMethod(Sel);
   }
-  // Before we give up, check if the selector is an instance method.
-  if (!Method)
-    Method = ClassDecl->lookupInstanceMethod(Sel);
   if (!Method) {
     Diag(lbrac, diag::warn_method_not_found, std::string("+"), Sel.getName(),
          SourceRange(lbrac, rbrac));

Added: cfe/trunk/test/Sema/objc-typedef-class.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-typedef-class.m?rev=51969&view=auto

==============================================================================
--- cfe/trunk/test/Sema/objc-typedef-class.m (added)
+++ cfe/trunk/test/Sema/objc-typedef-class.m Wed Jun  4 18:08:38 2008
@@ -0,0 +1,79 @@
+// RUN: clang -fsyntax-only -verify %s
+typedef signed char BOOL;
+typedef unsigned int NSUInteger;
+typedef struct _NSZone NSZone;
+
+ at class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
+
+ at protocol NSObject - (BOOL) isEqual:(id) object; @end
+ at protocol NSCopying - (id) copyWithZone:(NSZone *) zone; @end
+ at protocol NSCoding - (void) encodeWithCoder:(NSCoder *) aCoder; @end
+
+ at interface NSObject < NSObject > {}
++(id) alloc;
+ at end
+
+typedef float CGFloat;
+
+ at interface NSTask:NSObject
+- (id) init;
+ at end
+
+typedef NSUInteger NSControlSize;
+typedef struct __CFlags {} _CFlags;
+
+ at interface NSCell:NSObject < NSCopying, NSCoding > {}
+ at end
+
+ at interface NSActionCell:NSCell {} @end
+
+ at class NSAttributedString, NSFont, NSImage, NSSound;
+
+typedef struct _XCElementInset {} XCElementInset;
+
+ at protocol XCElementP < NSObject >
+-(BOOL) vertical;
+ at end
+
+ at protocol XCElementDisplayDelegateP;
+ at protocol XCElementDisplayDelegateP < NSObject >
+-(void) configureForControlSize:(NSControlSize)size font:(NSFont *)font addDefaultSpace:(XCElementInset) additionalSpace;
+ at end
+
+ at protocol XCElementSpacerP < XCElementP >
+ at end
+
+typedef NSObject < XCElementSpacerP > XCElementSpacer;
+
+ at protocol XCElementTogglerP < XCElementP > -(void) setDisplayed:(BOOL) displayed;
+ at end
+
+// FIXME: investigate this redefinition error - gcc apparently accepts it.
+typedef NSObject < XCElementTogglerP > XCElementToggler; // expected-error{{previous definition is here}}
+
+ at interface XCElementRootFace:NSObject {} @end
+
+ at interface XCElementFace:XCElementRootFace {} @end
+
+ at class XCElementToggler; // expected-error{{redefinition of 'XCElementToggler' as different kind of symbol}}
+
+ at interface XCRASlice:XCElementFace {} @end
+
+ at class XCElementSpacings;
+
+ at interface XCElementDisplay:NSObject < XCElementDisplayDelegateP > {} @end
+ at interface XCElementDisplayRect:XCElementDisplay {} @end
+
+typedef XCElementDisplayRect XCElementGraphicsRect;
+
+ at interface XCElementDisplayFillerImage:XCElementDisplay {} @end
+
+ at implementation XCRASlice
+- (void) addSliceWithLabel:(NSString *)label statusKey:(NSString *)statusKey disclosed:(BOOL)disclosed
+{
+  static XCElementGraphicsRect *_sGraphicsDelegate = ((void *) 0);
+  if (!_sGraphicsDelegate) {
+    _sGraphicsDelegate =[[XCElementGraphicsRect alloc] init]; // expected-warning{{method '+alloc' not found (return type defaults to 'id')}}
+  }
+}
+ at end





More information about the cfe-commits mailing list