[cfe-commits] r88934 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Parse/Parser.h lib/Parse/ParseObjc.cpp lib/Sema/ParseAST.cpp lib/Sema/SemaDeclObjC.cpp test/Analysis/NSString.m test/Analysis/PR3991.m test/Analysis/misc-ps.m test/Analysis/pr4209.m test/Analysis/region-1.m test/CodeGenObjC/missing-atend-metadata.m test/SemaObjC/compare-qualified-id.m test/SemaObjC/method-arg-decay.m

Fariborz Jahanian fjahanian at apple.com
Mon Nov 16 10:57:02 PST 2009


Author: fjahanian
Date: Mon Nov 16 12:57:01 2009
New Revision: 88934

URL: http://llvm.org/viewvc/llvm-project?rev=88934&view=rev
Log:
Handle case of missing '@end' in implementation context
gracefully, on par with gcc, by: Issuing a warning,
doing final sematinc check of its definitions and generating
its meta-data.

Added:
    cfe/trunk/test/CodeGenObjC/missing-atend-metadata.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParseObjc.cpp
    cfe/trunk/lib/Sema/ParseAST.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/Analysis/NSString.m
    cfe/trunk/test/Analysis/PR3991.m
    cfe/trunk/test/Analysis/misc-ps.m
    cfe/trunk/test/Analysis/pr4209.m
    cfe/trunk/test/Analysis/region-1.m
    cfe/trunk/test/SemaObjC/compare-qualified-id.m
    cfe/trunk/test/SemaObjC/method-arg-decay.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=88934&r1=88933&r2=88934&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Nov 16 12:57:01 2009
@@ -251,6 +251,7 @@
 def note_declared_at : Note<"declared at">;
 def err_setter_type_void : Error<"type of setter must be void">;
 def err_duplicate_method_decl : Error<"duplicate declaration of method %0">;
+def warn_missing_atend : Warning<"'@end' is missing in implementation context">;
 def err_objc_var_decl_inclass : 
     Error<"cannot declare variable inside @interface or @protocol">;
 def error_missing_method_context : Error<

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=88934&r1=88933&r2=88934&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Nov 16 12:57:01 2009
@@ -179,6 +179,8 @@
   /// the EOF was encountered.
   bool ParseTopLevelDecl(DeclGroupPtrTy &Result);
 
+  DeclGroupPtrTy RetreivePendingObjCImpDecl();
+
 private:
   //===--------------------------------------------------------------------===//
   // Low-Level token peeking and consumption methods.
@@ -783,6 +785,7 @@
                                            AttributeList *prefixAttrs = 0);
 
   DeclPtrTy ObjCImpDecl;
+  llvm::SmallVector<DeclPtrTy, 4> PendingObjCImpDecl;
 
   DeclPtrTy ParseObjCAtImplementationDeclaration(SourceLocation atLoc);
   DeclPtrTy ParseObjCAtEndDeclaration(SourceLocation atLoc);

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Nov 16 12:57:01 2009
@@ -123,6 +123,7 @@
     Diag(Tok, diag::err_expected_ident); // missing class or category name.
     return DeclPtrTy();
   }
+
   // We have a class or category name - consume it.
   IdentifierInfo *nameId = Tok.getIdentifierInfo();
   SourceLocation nameLoc = ConsumeToken();
@@ -1093,6 +1094,7 @@
                                     atLoc, nameId, nameLoc, categoryId,
                                     categoryLoc);
     ObjCImpDecl = ImplCatType;
+    PendingObjCImpDecl.push_back(ObjCImpDecl);
     return DeclPtrTy();
   }
   // We have a class implementation
@@ -1115,7 +1117,8 @@
   if (Tok.is(tok::l_brace)) // we have ivars
     ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc);
   ObjCImpDecl = ImplClsType;
-
+  PendingObjCImpDecl.push_back(ObjCImpDecl);
+  
   return DeclPtrTy();
 }
 
@@ -1127,12 +1130,21 @@
   if (ObjCImpDecl) {
     Actions.ActOnAtEnd(atLoc, ObjCImpDecl);
     ObjCImpDecl = DeclPtrTy();
+    PendingObjCImpDecl.pop_back();
   }
   else
     Diag(atLoc, diag::warn_expected_implementation); // missing @implementation
   return Result;
 }
 
+Parser::DeclGroupPtrTy Parser::RetreivePendingObjCImpDecl() {
+  if (PendingObjCImpDecl.empty())
+    return Actions.ConvertDeclToDeclGroup(DeclPtrTy());
+  DeclPtrTy ImpDecl = PendingObjCImpDecl.pop_back_val();
+  Actions.ActOnAtEnd(SourceLocation(), ImpDecl);
+  return Actions.ConvertDeclToDeclGroup(ImpDecl);
+}
+
 ///   compatibility-alias-decl:
 ///     @compatibility_alias alias-name  class-name ';'
 ///

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

==============================================================================
--- cfe/trunk/lib/Sema/ParseAST.cpp (original)
+++ cfe/trunk/lib/Sema/ParseAST.cpp Mon Nov 16 12:57:01 2009
@@ -71,6 +71,9 @@
     if (ADecl)
       Consumer->HandleTopLevelDecl(ADecl.getAsVal<DeclGroupRef>());
   };
+  // Check for any pending objective-c implementation decl.
+  while (ADecl = P.RetreivePendingObjCImpDecl())
+    Consumer->HandleTopLevelDecl(ADecl.getAsVal<DeclGroupRef>());
 
   // process any TopLevelDecls generated by #pragma weak
   for (llvm::SmallVector<Decl*,2>::iterator

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Nov 16 12:57:01 2009
@@ -1559,12 +1559,17 @@
   // should be true.
   if (!ClassDecl)
     return;
-
+  
   bool isInterfaceDeclKind =
         isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl)
          || isa<ObjCProtocolDecl>(ClassDecl);
   bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl);
 
+  if (!isInterfaceDeclKind && AtEndLoc.isInvalid()) {
+    AtEndLoc = ClassDecl->getLocation();
+    Diag(AtEndLoc, diag::warn_missing_atend);
+  }
+  
   DeclContext *DC = dyn_cast<DeclContext>(ClassDecl);
 
   // FIXME: Remove these and use the ObjCContainerDecl/DeclContext.

Modified: cfe/trunk/test/Analysis/NSString.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/NSString.m?rev=88934&r1=88933&r2=88934&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/NSString.m (original)
+++ cfe/trunk/test/Analysis/NSString.m Mon Nov 16 12:57:01 2009
@@ -371,5 +371,4 @@
     NSString *string = [[NSString stringWithFormat:@"%ld", (long) 100] retain]; // expected-warning {{leak}}
   }
 }
-
-
+ at end

Modified: cfe/trunk/test/Analysis/PR3991.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/PR3991.m?rev=88934&r1=88933&r2=88934&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/PR3991.m (original)
+++ cfe/trunk/test/Analysis/PR3991.m Mon Nov 16 12:57:01 2009
@@ -42,7 +42,15 @@
 - (unsigned int)currentPathComponentIndex;
 - (void)setCurrentPathComponentIndex:(unsigned int)aCurrentPathComponentIndex;
 - (NSURL *)folderFeedURL;
- at end  @implementation IHGoogleDocsAdapter    - (id)initWithUsername:(NSString *)inUsername password:(NSString *)inPassword owner:(NSObject <IHGoogleDocsAdapterDelegate> *)owner {
+ at end  
+
+ at implementation IHGoogleDocsAdapter    - (id)initWithUsername:(NSString *)inUsername password:(NSString *)inPassword owner:(NSObject <IHGoogleDocsAdapterDelegate> *)owner {	// expected-warning {{incomplete implementation}} \
+// expected-warning {{method definition for 'entries' not found}} \
+// expected-warning {{method definition for 'feedDocList' not found}} \
+// expected-warning {{method definition for 'directoryPathComponents' not found}} \
+// expected-warning {{method definition for 'currentPathComponentIndex' not found}} \
+// expected-warning {{method definition for 'setCurrentPathComponentIndex:' not found}} \
+// expected-warning {{method definition for 'folderFeedURL' not found}} 
   return 0;
 }
 
@@ -66,3 +74,4 @@
     }
   }
 }
+ at end

Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=88934&r1=88933&r2=88934&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Mon Nov 16 12:57:01 2009
@@ -749,3 +749,4 @@
   int i, a[10];
   int *p = &a[i]; // expected-warning{{Array subscript is undefined}}
 }
+ at end

Modified: cfe/trunk/test/Analysis/pr4209.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/pr4209.m?rev=88934&r1=88933&r2=88934&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/pr4209.m (original)
+++ cfe/trunk/test/Analysis/pr4209.m Mon Nov 16 12:57:01 2009
@@ -49,17 +49,20 @@
   GSEbayCategory *rootCategory;
 }
 - (NSMutableDictionary*)categoryDictionaryForCategoryID:(int)inID inRootTreeCategories:(NSMutableArray*)inRootTreeCategories;
--(NSString*) categoryID;
+-(NSString*) categoryID; 
 @end @interface GSEbayCategory : NSObject <NSCoding> {
 }
 - (int) categoryID;
 - (GSEbayCategory *) parent;
 - (GSEbayCategory*) subcategoryWithID:(int) inID;
- at end   @implementation GBCategoryChooserPanelController  + (int) chooseCategoryIDFromCategories:(NSArray*) inCategories        searchRequest:(GBSearchRequest*)inRequest         parentWindow:(NSWindow*) inParent {
+ at end   @implementation GBCategoryChooserPanelController  + (int) chooseCategoryIDFromCategories:(NSArray*) inCategories        searchRequest:(GBSearchRequest*)inRequest         parentWindow:(NSWindow*) inParent { // expected-warning {{incomplete implementation}} \
+// expected-warning {{method definition for 'categoryDictionaryForCategoryID:inRootTreeCategories:' not found}} \
+// expected-warning {{method definition for 'categoryID' not found}}
   return 0;
 }
 - (void) addCategory:(EBayCategoryType*)inCategory toRootTreeCategory:(NSMutableArray*)inRootTreeCategories {
-  GSEbayCategory *category = [rootCategory subcategoryWithID:[[inCategory categoryID] intValue]];
+  GSEbayCategory *category = [rootCategory subcategoryWithID:[[inCategory categoryID] intValue]]; 
+
   if (rootCategory != category)  {
     GSEbayCategory *parent = category;
     while ((((void*)0) != (parent = [parent parent])) && ([parent categoryID] != 0))   {
@@ -69,3 +72,4 @@
     }
   }
 }
+ at end

Modified: cfe/trunk/test/Analysis/region-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/region-1.m?rev=88934&r1=88933&r2=88934&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/region-1.m (original)
+++ cfe/trunk/test/Analysis/region-1.m Mon Nov 16 12:57:01 2009
@@ -89,3 +89,4 @@
     symbol = [HancodeFett symbolFromClass:(JabaSCClass *) selectedClassifier];
   }
 }
+ at end

Added: cfe/trunk/test/CodeGenObjC/missing-atend-metadata.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/missing-atend-metadata.m?rev=88934&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/missing-atend-metadata.m (added)
+++ cfe/trunk/test/CodeGenObjC/missing-atend-metadata.m Mon Nov 16 12:57:01 2009
@@ -0,0 +1,24 @@
+// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck %s
+
+ at interface I0 
+ at end
+
+ at implementation I0 // expected-warning {{'@end' is missing in implementation context}}
+- meth { return 0; }
+
+ at interface I1 : I0 
+ at end
+
+ at implementation I1 // expected-warning {{'@end' is missing in implementation context}}
+-(void) im0 { self = [super init]; }
+
+ at interface I2 : I0
+- I2meth;
+ at end
+
+ at implementation I2 // expected-warning {{'@end' is missing in implementation context}}
+- I2meth { return 0; }
+
+ at implementation  I2(CAT) // expected-warning {{'@end' is missing in implementation context}}
+
+// CHECK: @"\01L_OBJC_CLASS_I1" = internal global

Modified: cfe/trunk/test/SemaObjC/compare-qualified-id.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/compare-qualified-id.m?rev=88934&r1=88933&r2=88934&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/compare-qualified-id.m (original)
+++ cfe/trunk/test/SemaObjC/compare-qualified-id.m Mon Nov 16 12:57:01 2009
@@ -23,11 +23,12 @@
 - (NSString *)evaluateAsStringInContext:(XCPropertyExpansionContext *)context withNestingState:(const void *)state;
 @end
 
- at implementation XCPropertyExpansionContext
+ at implementation XCPropertyExpansionContext	// expected-warning {{method definition for 'copyWithZone:' not found}} \
+						// expected-warning {{incomplete implementation}}
 - (NSString *)expandedValueForProperty:(NSString *)property {
   id <XCPropertyValues> cachedValueNode = [_propNamesToPropValuesCache objectForKey:property]; // expected-warning {{method '-objectForKey:' not found (return type defaults to 'id')}}
   if (cachedValueNode == ((void *)0)) { }
   NSString * expandedValue = [cachedValueNode evaluateAsStringInContext:self withNestingState:((void *)0)];
   return expandedValue;
 }
-
+ at end

Modified: cfe/trunk/test/SemaObjC/method-arg-decay.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-arg-decay.m?rev=88934&r1=88933&r2=88934&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/method-arg-decay.m (original)
+++ cfe/trunk/test/SemaObjC/method-arg-decay.m Mon Nov 16 12:57:01 2009
@@ -72,7 +72,9 @@
 }
 - (PBXModule *) moduleForTab:(NSTabViewItem *)item;
 @end  
- at implementation XCPerspectiveModule    
+ at implementation XCPerspectiveModule    // expected-warning {{method definition for 'moduleForTab:' not found}}	\
+					// expected-warning {{method definition for 'performAction:withSelection:' not found}} \
+					// expected-warning {{incomplete implementation}}
 + (void) openForProjectDocument:(PBXProjectDocument *)projectDocument {
 }
 - (PBXModule *) type:(Class)type inPerspective:(id)perspectiveIdentifer  matchingFunction:(BOOL (void *, void *))comparator usingData:(void *)data {
@@ -94,3 +96,4 @@
  prompts++;
  return (BOOL)0;
 }
+ at end





More information about the cfe-commits mailing list