]> granicus.if.org Git - clang/commitdiff
[objcmt] Make sure we don't edit the return type to add 'instancetype' if the return...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 21 May 2014 00:24:20 +0000 (00:24 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 21 May 2014 00:24:20 +0000 (00:24 +0000)
rdar://16961577

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

lib/ARCMigrate/ObjCMT.cpp
test/ARCMT/objcmt-instancetype-unnecessary-diff.m [new file with mode: 0644]

index 81cb9da262b9541a17bc98d1a2635a067f20d648..a52c32f08faff63ef8ce1d009fa5f10273cdf5dc 100644 (file)
@@ -830,8 +830,12 @@ bool ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx,
   return Res;
 }
 
-static void ReplaceWithInstancetype(const ObjCMigrateASTConsumer &ASTC,
+static void ReplaceWithInstancetype(ASTContext &Ctx,
+                                    const ObjCMigrateASTConsumer &ASTC,
                                     ObjCMethodDecl *OM) {
+  if (OM->getReturnType() == Ctx.getObjCInstanceType())
+    return; // already has instancetype.
+
   SourceRange R;
   std::string ClassString;
   if (TypeSourceInfo *TSInfo = OM->getReturnTypeSourceInfo()) {
@@ -893,7 +897,7 @@ void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
       return;
     case OIT_Init:
       if (OM->getReturnType()->isObjCIdType())
-        ReplaceWithInstancetype(*this, OM);
+        ReplaceWithInstancetype(Ctx, *this, OM);
       return;
     case OIT_ReturnsSelf:
       migrateFactoryMethod(Ctx, CDecl, OM, OIT_ReturnsSelf);
@@ -914,7 +918,7 @@ void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
     migrateFactoryMethod(Ctx, CDecl, OM);
     return;
   }
-  ReplaceWithInstancetype(*this, OM);
+  ReplaceWithInstancetype(Ctx, *this, OM);
 }
 
 static bool TypeIsInnerPointer(QualType T) {
@@ -1224,7 +1228,7 @@ void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx,
   if (OIT_Family == OIT_ReturnsSelf)
     ReplaceWithClasstype(*this, OM);
   else
-    ReplaceWithInstancetype(*this, OM);
+    ReplaceWithInstancetype(Ctx, *this, OM);
 }
 
 static bool IsVoidStarType(QualType Ty) {
diff --git a/test/ARCMT/objcmt-instancetype-unnecessary-diff.m b/test/ARCMT/objcmt-instancetype-unnecessary-diff.m
new file mode 100644 (file)
index 0000000..e250bb0
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -objcmt-migrate-instancetype %s -triple x86_64-apple-darwin11 -fobjc-arc -migrate -o %t.remap
+// RUN: FileCheck %s -input-file=%t.remap
+
+// Make sure we don't create an edit unnecessarily.
+// CHECK-NOT: instancetype
+
+@class NSString;
+@interface NSDictionary
++(instancetype) dictionaryWithURLEncodedString:(NSString *)urlEncodedString;
+@end