[cfe-commits] r51956 - in /cfe/trunk: lib/Sema/SemaExprObjC.cpp test/Sema/objc-comptypes-9.m
Fariborz Jahanian
fjahanian at apple.com
Wed Jun 4 12:00:03 PDT 2008
Author: fjahanian
Date: Wed Jun 4 14:00:03 2008
New Revision: 51956
URL: http://llvm.org/viewvc/llvm-project?rev=51956&view=rev
Log:
Fix a gcc compatibility issue which allows more protocol-qualified id on RHS to be
assigned to less protocol qualified object on LHS.
Added:
cfe/trunk/test/Sema/objc-comptypes-9.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=51956&r1=51955&r2=51956&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Jun 4 14:00:03 2008
@@ -327,13 +327,21 @@
/// lookupCategory is true).
static bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
ObjCInterfaceDecl *IDecl,
- bool lookupCategory) {
+ bool lookupCategory,
+ bool RHSIsQualifiedID = false) {
// 1st, look up the class.
ObjCProtocolDecl **protoList = IDecl->getReferencedProtocols();
for (unsigned i = 0; i < IDecl->getNumIntfRefProtocols(); i++) {
if (ProtocolCompatibleWithProtocol(lProto, protoList[i]))
return true;
+ // This is dubious and is added to be compatible with gcc.
+ // In gcc, it is also allowed assigning a protocol-qualified 'id'
+ // type to a LHS object when protocol in qualified LHS is in list
+ // of protocols in the rhs 'id' object. This IMO, should be a bug.
+ else if (RHSIsQualifiedID &&
+ ProtocolCompatibleWithProtocol(protoList[i], lProto))
+ return true;
}
// 2nd, look up the category.
@@ -350,7 +358,8 @@
// 3rd, look up the super class(s)
if (IDecl->getSuperClass())
return
- ClassImplementsProtocol(lProto, IDecl->getSuperClass(), lookupCategory);
+ ClassImplementsProtocol(lProto, IDecl->getSuperClass(), lookupCategory,
+ RHSIsQualifiedID);
return false;
}
@@ -481,7 +490,7 @@
ObjCInterfaceDecl *lhsID = IT->getDecl();
for (unsigned j = 0; j < rhsQID->getNumProtocols(); j++) {
ObjCProtocolDecl *rhsProto = rhsQID->getProtocols(j);
- if (!ClassImplementsProtocol(rhsProto, lhsID, compare))
+ if (!ClassImplementsProtocol(rhsProto, lhsID, compare, true))
return false;
}
return true;
Added: cfe/trunk/test/Sema/objc-comptypes-9.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-comptypes-9.m?rev=51956&view=auto
==============================================================================
--- cfe/trunk/test/Sema/objc-comptypes-9.m (added)
+++ cfe/trunk/test/Sema/objc-comptypes-9.m Wed Jun 4 14:00:03 2008
@@ -0,0 +1,84 @@
+// RUN: clang -fsyntax-only %s
+
+typedef signed char BOOL;
+typedef int NSInteger;
+typedef unsigned int NSUInteger;
+typedef struct _NSZone NSZone;
+ at class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
+
+ at protocol NSObject
+- (BOOL)isEqual:(id)object;
+ at end
+
+ at protocol NSCopying
+- (id)copyWithZone:(NSZone *)zone;
+ at end
+
+ at protocol NSMutableCopying
+- (id)mutableCopyWithZone:(NSZone *)zone;
+ at end
+
+ at protocol NSCoding
+- (void)encodeWithCoder:(NSCoder *)aCoder;
+ at end
+
+ at interface NSObject <NSObject> {}
+ at end
+
+ at class NSArray;
+
+typedef struct {} NSFastEnumerationState;
+
+ at protocol NSFastEnumeration
+- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
+ at end
+
+ at class NSString;
+
+ at interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
+- (NSUInteger)count;
+- (id)objectAtIndex:(NSUInteger)index;
+ at end
+
+typedef unsigned short unichar;
+
+ at interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
+- (NSUInteger)length;
+ at end
+
+ at interface NSSimpleCString : NSString
+{}
+
+ at end
+
+ at interface NSConstantString : NSSimpleCString @end
+
+extern void *_NSConstantStringClassReference;
+
+ at interface NSResponder : NSObject <NSCoding> {}
+ at end
+
+ at class NSDate, NSDictionary, NSError, NSException, NSNotification;
+
+ at interface NSWindowController : NSResponder <NSCoding> {}
+ at end
+
+ at class PBXBuildLog, PBXBuildLogItem, PBXBuildLogContainerItem, XCWorkQueueCommand, XCBuildLogContainerItemMutationState;
+
+ at protocol PBXBuildLogContainerItems <NSObject>
+- (PBXBuildLog *)buildLog;
+ at end
+
+ at interface PBXBuildLogItem : NSObject {}
+- (id <PBXBuildLogContainerItems>)superitem;
+ at end
+ at interface PBXBuildResultsModule
+ at end
+
+ at implementation PBXBuildResultsModule
+- (void) revealItems
+{
+ PBXBuildLogItem *objItem;
+ PBXBuildLogItem *superitem = [objItem superitem];
+}
+ at end
More information about the cfe-commits
mailing list