r209264 - [objcmt] Make sure we don't edit the return type to add 'instancetype' if the return type is already that.

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue May 20 17:24:20 PDT 2014


Author: akirtzidis
Date: Tue May 20 19:24:20 2014
New Revision: 209264

URL: http://llvm.org/viewvc/llvm-project?rev=209264&view=rev
Log:
[objcmt] Make sure we don't edit the return type to add 'instancetype' if the return type is already that.

rdar://16961577

Added:
    cfe/trunk/test/ARCMT/objcmt-instancetype-unnecessary-diff.m
Modified:
    cfe/trunk/lib/ARCMigrate/ObjCMT.cpp

Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=209264&r1=209263&r2=209264&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Tue May 20 19:24:20 2014
@@ -830,8 +830,12 @@ bool ObjCMigrateASTConsumer::migrateNSEn
   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::migrateMeth
       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::migrateMeth
     migrateFactoryMethod(Ctx, CDecl, OM);
     return;
   }
-  ReplaceWithInstancetype(*this, OM);
+  ReplaceWithInstancetype(Ctx, *this, OM);
 }
 
 static bool TypeIsInnerPointer(QualType T) {
@@ -1224,7 +1228,7 @@ void ObjCMigrateASTConsumer::migrateFact
   if (OIT_Family == OIT_ReturnsSelf)
     ReplaceWithClasstype(*this, OM);
   else
-    ReplaceWithInstancetype(*this, OM);
+    ReplaceWithInstancetype(Ctx, *this, OM);
 }
 
 static bool IsVoidStarType(QualType Ty) {

Added: cfe/trunk/test/ARCMT/objcmt-instancetype-unnecessary-diff.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-instancetype-unnecessary-diff.m?rev=209264&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-instancetype-unnecessary-diff.m (added)
+++ cfe/trunk/test/ARCMT/objcmt-instancetype-unnecessary-diff.m Tue May 20 19:24:20 2014
@@ -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
+
+ at class NSString;
+ at interface NSDictionary
++(instancetype) dictionaryWithURLEncodedString:(NSString *)urlEncodedString;
+ at end





More information about the cfe-commits mailing list