[cfe-commits] r54082 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Parse/ParseDecl.cpp test/Sema/bogus-gcc-protocol-extension.m test/Sema/objc-protocol-1.m

Chris Lattner sabre at nondot.org
Fri Jul 25 17:20:23 PDT 2008


Author: lattner
Date: Fri Jul 25 19:20:22 2008
New Revision: 54082

URL: http://llvm.org/viewvc/llvm-project?rev=54082&view=rev
Log:
improve handling of the horrible GCC objc extension that treats "<foo>" 
like "id<foo>".  This 1) fixes an infinite loop in the parser on things
like "short<foo>" 2) emits a warning about this bogus construct and 3)
changes the testcase to be substantially reduced.

Added:
    cfe/trunk/test/Sema/objc-protocol-1.m
Removed:
    cfe/trunk/test/Sema/bogus-gcc-protocol-extension.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Parse/ParseDecl.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=54082&r1=54081&r2=54082&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Jul 25 19:20:22 2008
@@ -401,6 +401,9 @@
      "attributes may not be specified on a category")
 DIAG(err_objc_missing_end, ERROR,
      "missing @end")
+DIAG(warn_objc_protocol_qualifier_missing_id, WARNING,
+     "protocol qualifiers without 'id' is archaic")
+
 DIAG(err_objc_illegal_visibility_spec, ERROR,
      "illegal visibility specification")
 DIAG(err_objc_illegal_interface_qual, ERROR,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=54082&r1=54081&r2=54082&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Jul 25 19:20:22 2008
@@ -430,6 +430,7 @@
       }
       // FALL THROUGH.
     default:
+    DoneWithDeclSpec:
       // If this is not a declaration specifier token, we're done reading decl
       // specifiers.  First verify that DeclSpec's are consistent.
       DS.Finish(Diags, PP.getSourceManager(), getLang());
@@ -552,20 +553,27 @@
       isInvalid = DS.SetFunctionSpecInline(Loc, PrevSpec);
       break;
       
-    // Gross GCC-ism that we are forced support. FIXME: make an extension?
     case tok::less:
-      if (!DS.hasTypeSpecifier()) {
-        SourceLocation endProtoLoc;
+      // GCC supports types like "<SomeProtocol>" as a synonym for
+      // "id<SomeProtocol>".  This is hopelessly old fashioned and dangerous,
+      // but we support it.
+      if (DS.hasTypeSpecifier())
+        goto DoneWithDeclSpec;
+        
+      {
+        SourceLocation EndProtoLoc;
         llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;
-        ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc);
+        ParseObjCProtocolReferences(ProtocolRefs, EndProtoLoc);
         llvm::SmallVector<DeclTy *, 8> *ProtocolDecl = 
                 new llvm::SmallVector<DeclTy *, 8>;
         DS.setProtocolQualifiers(ProtocolDecl);
         Actions.FindProtocolDeclaration(Loc, 
-                  &ProtocolRefs[0], ProtocolRefs.size(),
-                  *ProtocolDecl);
+                                        &ProtocolRefs[0], ProtocolRefs.size(),
+                                        *ProtocolDecl);
+        Diag(Loc, diag::warn_objc_protocol_qualifier_missing_id,
+             SourceRange(Loc, EndProtoLoc));
+        continue;
       }
-      continue;
     }
     // If the specifier combination wasn't legal, issue a diagnostic.
     if (isInvalid) {

Removed: cfe/trunk/test/Sema/bogus-gcc-protocol-extension.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/bogus-gcc-protocol-extension.m?rev=54081&view=auto

==============================================================================
--- cfe/trunk/test/Sema/bogus-gcc-protocol-extension.m (original)
+++ cfe/trunk/test/Sema/bogus-gcc-protocol-extension.m (removed)
@@ -1,300 +0,0 @@
-// RUN: clang -fsyntax-only -verify %s
-typedef struct objc_selector *SEL;
-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;
-- (BOOL)conformsToProtocol:(Protocol *)aProtocol;
- 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> {}
-
-- (void)dealloc;
- at end
-
-extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
-
-typedef struct _NSSize {} NSRect;
-typedef struct {} NSFastEnumerationState;
-
- at protocol NSFastEnumeration
-- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
- at end
-
- at class NSString;
- at interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>  
-- (NSUInteger)length;
-- (BOOL)isEqualToString:(NSString *)aString;
- at end
-
- at interface NSSimpleCString : NSString {} @end
-
- at interface NSConstantString : NSSimpleCString @end
-
-extern void *_NSConstantStringClassReference;
-
- at interface NSSet : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
-- (NSUInteger)count;
- at end
-
- at interface NSMutableSet : NSSet
-- (void)addObject:(id)object;
- at end
-
- at class NSArray, NSDictionary, NSMapTable;
- at interface NSResponder : NSObject <NSCoding> {} @end
-
- at protocol NSAnimatablePropertyContainer    
-- (id)animator;
- at end
-
-extern NSString *NSAnimationTriggerOrderIn ;
- at interface NSView : NSResponder  <NSAnimatablePropertyContainer> {} @end
-
-extern NSString * const NSFullScreenModeAllScreens;
-typedef NSUInteger NSControlTint;
-
- at interface NSCell : NSObject <NSCopying, NSCoding> {}
-- (NSRect)imageRectForBounds:(NSRect)theRect;
- at end
-
- at protocol NSValidatedUserInterfaceItem
-- (SEL)action;
- at end
-
- at protocol NSUserInterfaceValidations
-- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem;
- at end
-
- at class NSCell, NSFont, NSTextView, NSNotification, NSAttributedString, NSFormatter;
- at interface NSControl : NSView {} @end
-
- at class NSColor, NSClipView, NSRulerView, NSScroller;
- at interface NSWindowController : NSResponder <NSCoding> {} @end
-
- at class NSTableHeaderView;
- at class NSTableColumn;
- at interface NSTableView : NSControl <NSUserInterfaceValidations> {}
-
-- (NSInteger)columnWithIdentifier:(id)identifier;
-- (NSRect)frameOfCellAtColumn:(NSInteger)column row:(NSInteger)row;
- at end
-
- at class NSButtonCell;
- at interface NSOutlineView : NSTableView {}
-- (NSInteger)rowForItem:(id)item;
- at end
-
- at class NSArray, NSDictionary, NSMutableArray, NSNotification, NSString, NSToolbarItem, NSWindow;
- at protocol XCProxyObjectProtocol
-- (id) representedObject;
- at end
-
- at interface PBXObject : NSObject {} @end
-typedef enum
-{
-    PBXNoItemChanged = 0x00,     PBXProjectItemChanged = 0x01,     PBXReferenceChanged = 0x02,     PBXGroupChanged = 0x04,     PBXTargetChanged = 0x08,     PBXBuildPhaseChanged = 0x10,     PBXBuildFileChanged = 0x20,     PBXBreakpointChanged = 0x40,
-}
-
-PBXChangedItemMask;
- at protocol PBXChangeNotification 
-- (void)willChange;
- at end
-
- at class PBXContainer, PBXProject;
- at interface PBXContainerItem : PBXObject <PBXChangeNotification> {} @end
-
- at interface PBXProjectItem : PBXContainerItem {} @end
-
- at class XCObjectGraphPath;
- at protocol XCCompatibilityChecking  
-- (void)findFeaturesInUseAndAddToSet:(NSMutableSet *)featureSet usingPathPrefix:(XCObjectGraphPath *)pathPrefix;
-- (NSString *)identifier;
- at end
-
- at protocol XCConfigurationInspectables <NSObject> 
-- (NSString *)name;
- at end
-
- at class PBXProject, PBXFileReference, PBXBuildPhase, PBXBuildSettingsDictionary, PBXExecutable, PBXBuildFile, PBXTargetDependency, PBXBuildLog, PBXBuildRule, XCCommandLineToolSpecification, XCProductTypeSpecification, PBXPackageTypeSpecification, PBXTargetBuildContext, XCBuildConfiguration, XCConfigurationList, XCHeadersBuildPhaseDGSnapshot, XCResourcesBuildPhaseDGSnapshot, XCSourcesBuildPhaseDGSnapshot, XCFrameworksBuildPhaseDGSnapshot, XCRezBuildPhaseDGSnapshot, XCJavaArchiveBuildPhaseDGSnapshot, XCBuildFileRefDGSnapshot, XCWorkQueue, XCBuildOperation, XCStringList, XCPropertyExpansionContext, XCWorkQueueOperation, XCTargetDGSnapshot, XCTargetHeadermapCreationInfo, XCPropertyInfoContext, XCConfigurationInspectionContext, PBXReference;
- at interface PBXTarget : PBXProjectItem <XCCompatibilityChecking, XCConfigurationInspectables> {} @end
-
-extern NSString * const XCTargetDGSnapshotContextKey_BuildAction;
- at interface PBXBookmarkItem : PBXProjectItem {} @end
-
- at interface PBXReference : PBXContainerItem {} @end
-
-extern BOOL PBX_getUsesTabsPreference();
- at interface PBXGroup : PBXReference <XCCompatibilityChecking> {} @end
-
- at class PBXFileReference, PBXTarget, PBXProject;
- at interface PBXExecutable : PBXProjectItem {} @end
-
- at class XCSCMRevisionInfo;
- at interface PBXBookmark : PBXBookmarkItem {} @end
-
- at class XCSCMInfo;
- at interface PBXFileReference : PBXReference {} @end
-
- at interface PBXLegacyTarget : PBXTarget {} @end
-
- at interface PBXVariantGroup : PBXGroup {} @end
-
-typedef enum
-{
-    PBXBuildMessageType_None,     PBXBuildMessageType_Notice,     PBXBuildMessageType_Warning,     PBXBuildMessageType_Error,
-}
-
-PBXBuildMessageType;
- at interface PBXBuildMessage : NSObject {} @end
-
- at class PBXBreakpoint, PBXFileReference, PBXProject, PBXTextBookmark;
- at protocol PBXMarkerDelegateProtocol <NSObject>
-- (void) setLineNumber:(NSUInteger)newLineNumber;
- at end
-
-typedef enum
-{
-    PBXBreakpointIgnoreCountType = 0,  PBXBreakpointMultipleCountType
-}
-
-PBXBreakpointCountType;
-
- at interface PBXBreakpoint : PBXProjectItem {} @end
- at interface PBXFileBreakpoint : PBXBreakpoint <NSCopying, PBXMarkerDelegateProtocol> {} @end
-
-extern NSString *XCBreakpointActionsWereUpdated;
- at protocol PBXNodeEditingProtocol
-- (BOOL) canRename;
- at end
-
- at protocol XCFosterParentHostProtocol
-- (void) reloadDataForProxies;
- at end
-
- at interface PBXBuildLogItem : NSObject {} @end
-
- at interface PBXBuildLogMessageItem : PBXBuildLogItem {} @end
-
-extern NSString *PBXWindowDidChangeFirstResponderNotification;
- at interface PBXModule : NSWindowController {} @end
-typedef enum
-{
-    PBXPanelCanChooseFiles,     PBXPanelCanChooseFolders,     PBXPanelCanChooseBoth,     PBXPanelCanChooseOnlyExistingFolders
-}
-
-PBXPanelSelection;
- at interface XCSelection : NSResponder {} @end
-
- at protocol XCSelectionSource
-- (XCSelection *) xcSelection;
- at end
-typedef enum
-{
-    PBXFindMatchContains,     PBXFindMatchStartsWith,     PBXFindMatchWholeWords,     PBXFindMatchEndsWith
-}
-
-PBXFindMatchStyle;
- at protocol PBXSelectableText
-- (NSString *)selectedString;
- at end
-
- at protocol PBXFindableText <PBXSelectableText>  
-- (BOOL)findText:(NSString *)string ignoreCase:(BOOL)ignoreCase matchStyle:(PBXFindMatchStyle)matchStyle backwards:(BOOL)backwards wrap:(BOOL)wrap;
- at end
-
- at class PBXProjectDocument, PBXProject, PBXAttributedStatusView;
- at interface PBXProjectModule : PBXModule <PBXFindableText> {} @end
-
- at class PBXExtendedOutlineView, PBXFileReference, PBXGroup, PBXProject, PBXProjectDocument, PBXReference, PBXOutlineDataSourceSplitter, XCSCMInfo;
-extern NSString * const PBXGroupTreeMainColumnIdentifier;
- at interface PBXGroupTreeModule : PBXProjectModule {} @end
-
- at protocol PBXTableColumnProvider  
-- (NSArray *) optionalColumnIdentifiers:(NSTableView *)tableView;
- at end
-
-extern NSString *PBXSmartGroupTreeModuleColumnsKey;
- at interface PBXSmartGroupTreeModule : PBXGroupTreeModule <PBXTableColumnProvider, XCSelectionSource, XCFosterParentHostProtocol> {} @end
-
- at class PBXBookmark, PBXProjectModule, PBXProjectDocument, PBXSmartGroupTreeModule, PBXBreakpoint, XCBreakpointsBucket, PBXFileNavigator;
- at interface PBXFosterParent : PBXGroup <XCProxyObjectProtocol, PBXNodeEditingProtocol> {} @end
-
- at class NSString, NSAttributedString, PBXBookmark, PBXFileDocument, PBXSymbol, PBXDocBookmark;
- at interface PBXFindResult : NSObject {} @end
-
- at protocol PBXBookmarkSupport
-- (PBXBookmark *) bookmark;
- at end
-
- at interface PBXReference (BookmarkSupportAPI) <PBXBookmarkSupport> @end
-
- at interface PBXBookmark (BookmarkSupportAPI) <PBXBookmarkSupport> @end
-
- at interface PBXFileReference (BookmarkSupportAPI) <PBXBookmarkSupport> @end
-
- at interface PBXTarget (BookmarkSupportAPI) <PBXBookmarkSupport> @end
-
- at interface PBXLegacyTarget (BookmarkSupportAPI) <PBXBookmarkSupport> @end
-
- at interface PBXExecutable (BookmarkSupportAPI) <PBXBookmarkSupport> @end
-
- at interface PBXFosterParent (BookmarkSupportAPI) <PBXBookmarkSupport> @end
-
- at interface PBXVariantGroup (BookmarkSupportAPI) <PBXBookmarkSupport> @end
-
- at interface PBXFindResult (BookmarkSupportAPI) <PBXBookmarkSupport> @end
-
- at interface PBXBuildMessage (BookmarkSupportAPI) <PBXBookmarkSupport> @end
-
- at interface PBXBuildLogMessageItem (BookmarkSupportAPI) <PBXBookmarkSupport> @end
-
- at interface PBXFileBreakpoint (BookmarkSupportAPI) <PBXBookmarkSupport> @end
-
-extern BOOL PBXShouldIncludeReference(id ref);
- at class PBXSmartGroupDataSource, PBXModule, PBXSmartGroupBinding, PBXProjectModule, PBXFosterParent, PBXExtendedOutlineView, PBXOutlineViewCell, PBXProjectWorkspaceModule;
- at protocol XCOutlineViewCheckBoxProtocol
-- (void) toggleEnabledState;
-- (void) storeCheckBoxBounds:(NSRect)bounds;
- at end
-
-extern NSControlTint _NSDefaultControlTint(void);
- at implementation PBXSmartGroupTreeModule
-- (void) dealloc
-{
-    [super dealloc];
-}
-
-- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBXOutlineViewCell *)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
-{
-    if ([[tableColumn identifier] isEqualToString: PBXGroupTreeMainColumnIdentifier])
-    {
-        if ([item conformsToProtocol:@protocol(XCOutlineViewCheckBoxProtocol)])
-        {
-            NSInteger columnIndex = [outlineView columnWithIdentifier:[tableColumn identifier]];
-            NSInteger row = [outlineView rowForItem:item];
-            <XCOutlineViewCheckBoxProtocol> xxx;
-            if (row > -1 && columnIndex > -1)
-            {
-                // FIXME: need to associate the correct type with this.
-                [(<XCOutlineViewCheckBoxProtocol>)item storeCheckBoxBounds:[cell imageRectForBounds:[outlineView frameOfCellAtColumn:columnIndex row:row]]]; // expected-error{{bad receiver type 'int'}}
-            }
-        }
-    }
-}
-

Added: cfe/trunk/test/Sema/objc-protocol-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-protocol-1.m?rev=54082&view=auto

==============================================================================
--- cfe/trunk/test/Sema/objc-protocol-1.m (added)
+++ cfe/trunk/test/Sema/objc-protocol-1.m Fri Jul 25 19:20:22 2008
@@ -0,0 +1,10 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at protocol SomeProtocol
+ at end
+
+void foo(id x) {
+  bar((short<SomeProtocol>)x); // expected-error {{expected ')'}} expected-error {{to match this '('}}
+  bar((<SomeProtocol>)x);      // expected-warning {{protocol qualifiers without 'id' is archaic}}
+}
+





More information about the cfe-commits mailing list