diff options
| -rw-r--r-- | clang/lib/ARCMigrate/ObjCMT.cpp | 25 | ||||
| -rw-r--r-- | clang/test/ARCMT/objcmt-instancetype-2.m | 14 | ||||
| -rw-r--r-- | clang/test/ARCMT/objcmt-instancetype-2.m.result | 14 |
3 files changed, 47 insertions, 6 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index b521b560263..ca86d12466f 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/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<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); diff --git a/clang/test/ARCMT/objcmt-instancetype-2.m b/clang/test/ARCMT/objcmt-instancetype-2.m index 325f2217a75..2fdbcf9cca3 100644 --- a/clang/test/ARCMT/objcmt-instancetype-2.m +++ b/clang/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/clang/test/ARCMT/objcmt-instancetype-2.m.result b/clang/test/ARCMT/objcmt-instancetype-2.m.result index 7077f454896..b6bd05adeb6 100644 --- a/clang/test/ARCMT/objcmt-instancetype-2.m.result +++ b/clang/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 + |

