]> granicus.if.org Git - clang/commitdiff
ObjectiveC migrator: Fixes a crash and makes couple
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 13 Aug 2013 18:01:42 +0000 (18:01 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 13 Aug 2013 18:01:42 +0000 (18:01 +0000)
of harmless changes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188303 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ARCMigrate/ObjCMT.cpp
test/ARCMT/objcmt-instancetype-2.m
test/ARCMT/objcmt-instancetype-2.m.result

index b521b560263397e2fb3c2d181115f61be674bafd..ca86d12466f04e41d9850ade7509be15fb917573 100644 (file)
@@ -46,9 +46,11 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
                             ObjCMethodDecl *OM,
                             ObjCInstanceTypeFamily OIT_Family = OIT_None);
   
-  void migrateFunctionDeclAnnotation(ASTContext &Ctx, FunctionDecl *FuncDecl);
+  void migrateFunctionDeclAnnotation(ASTContext &Ctx,
+                                     const FunctionDecl *FuncDecl);
   
-  void migrateObjCMethodDeclAnnotation(ASTContext &Ctx, ObjCMethodDecl *MethodDecl);
+  void migrateObjCMethodDeclAnnotation(ASTContext &Ctx,
+                                       const ObjCMethodDecl *MethodDecl);
 public:
   std::string MigrateDir;
   bool MigrateLiterals;
@@ -713,6 +715,10 @@ void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx,
   LoweredClassName = StringLoweredClassName;
   
   IdentifierInfo *MethodIdName = OM->getSelector().getIdentifierInfoForSlot(0);
+  // Handle method with no name at its first selector slot; e.g. + (id):(int)x.
+  if (!MethodIdName)
+    return;
+  
   std::string MethodName = MethodIdName->getName();
   if (OIT_Family == OIT_Singleton) {
     StringRef STRefMethodName(MethodName);
@@ -745,19 +751,21 @@ void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx,
 
 void ObjCMigrateASTConsumer::migrateFunctionDeclAnnotation(
                                                 ASTContext &Ctx,
-                                                FunctionDecl *FuncDecl) {
+                                                const FunctionDecl *FuncDecl) {
   if (FuncDecl->hasAttr<CFAuditedTransferAttr>() ||
       FuncDecl->getAttr<CFReturnsRetainedAttr>() ||
-      FuncDecl->getAttr<CFReturnsNotRetainedAttr>())
+      FuncDecl->getAttr<CFReturnsNotRetainedAttr>() ||
+      FuncDecl->hasBody())
     return;
 }
 
 void ObjCMigrateASTConsumer::migrateObjCMethodDeclAnnotation(
                                             ASTContext &Ctx,
-                                            ObjCMethodDecl *MethodDecl) {
+                                            const ObjCMethodDecl *MethodDecl) {
   if (MethodDecl->hasAttr<CFAuditedTransferAttr>() ||
       MethodDecl->getAttr<CFReturnsRetainedAttr>() ||
-      MethodDecl->getAttr<CFReturnsNotRetainedAttr>())
+      MethodDecl->getAttr<CFReturnsNotRetainedAttr>() ||
+      MethodDecl->hasBody())
     return;
 }
 
@@ -799,6 +807,11 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
           if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(*N))
             migrateNSEnumDecl(Ctx, ED, TD);
       }
+      else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*D))
+        migrateFunctionDeclAnnotation(Ctx, FD);
+      else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*D))
+        migrateObjCMethodDeclAnnotation(Ctx, MD);
+      
       // migrate methods which can have instancetype as their result type.
       if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(*D))
         migrateInstanceType(Ctx, CDecl);
index 325f2217a75f1d9198356783c0ac5de7dd856194..2fdbcf9cca33025dc917bb12d89281a5b9fb28c9 100644 (file)
@@ -85,3 +85,17 @@ typedef enum NSURLBookmarkResolutionOptions {
 @interface UIApplication
 + (id)sharedApplication;
 @end
+
+//===----------------------------------------------------------------------===//
+// Method name that has a null IdentifierInfo* for its first selector slot.
+// This test just makes sure that we handle it.
+//===----------------------------------------------------------------------===//
+@interface TestNullIdentifier
+@end
+
+@implementation TestNullIdentifier
++ (id):(int)x, ... {
+  return 0;
+}
+@end
+
index 7077f45489645575923883b59d7c3562a7d8b896..b6bd05adeb66735d19d87d3e9fae47c910380f33 100644 (file)
@@ -85,3 +85,17 @@ typedef enum NSURLBookmarkResolutionOptions {
 @interface UIApplication
 + (instancetype)sharedApplication;
 @end
+
+//===----------------------------------------------------------------------===//
+// Method name that has a null IdentifierInfo* for its first selector slot.
+// This test just makes sure that we handle it.
+//===----------------------------------------------------------------------===//
+@interface TestNullIdentifier
+@end
+
+@implementation TestNullIdentifier
++ (id):(int)x, ... {
+  return 0;
+}
+@end
+