From: Fariborz Jahanian Date: Tue, 13 Aug 2013 18:01:42 +0000 (+0000) Subject: ObjectiveC migrator: Fixes a crash and makes couple X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=086d565d2d3b8e72f95492d3a2cefd09e1718f2a;p=clang ObjectiveC migrator: Fixes a crash and makes couple of harmless changes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188303 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index b521b56026..ca86d12466 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -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() || FuncDecl->getAttr() || - FuncDecl->getAttr()) + FuncDecl->getAttr() || + FuncDecl->hasBody()) return; } void ObjCMigrateASTConsumer::migrateObjCMethodDeclAnnotation( ASTContext &Ctx, - ObjCMethodDecl *MethodDecl) { + const ObjCMethodDecl *MethodDecl) { if (MethodDecl->hasAttr() || MethodDecl->getAttr() || - MethodDecl->getAttr()) + MethodDecl->getAttr() || + MethodDecl->hasBody()) return; } @@ -799,6 +807,11 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { if (const TypedefDecl *TD = dyn_cast(*N)) migrateNSEnumDecl(Ctx, ED, TD); } + else if (const FunctionDecl *FD = dyn_cast(*D)) + migrateFunctionDeclAnnotation(Ctx, FD); + else if (const ObjCMethodDecl *MD = dyn_cast(*D)) + migrateObjCMethodDeclAnnotation(Ctx, MD); + // migrate methods which can have instancetype as their result type. if (ObjCContainerDecl *CDecl = dyn_cast(*D)) migrateInstanceType(Ctx, CDecl); diff --git a/test/ARCMT/objcmt-instancetype-2.m b/test/ARCMT/objcmt-instancetype-2.m index 325f2217a7..2fdbcf9cca 100644 --- a/test/ARCMT/objcmt-instancetype-2.m +++ b/test/ARCMT/objcmt-instancetype-2.m @@ -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 + diff --git a/test/ARCMT/objcmt-instancetype-2.m.result b/test/ARCMT/objcmt-instancetype-2.m.result index 7077f45489..b6bd05adeb 100644 --- a/test/ARCMT/objcmt-instancetype-2.m.result +++ b/test/ARCMT/objcmt-instancetype-2.m.result @@ -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 +