[cfe-commits] r135309 - in /cfe/trunk: lib/ARCMigrate/TransRetainReleaseDealloc.cpp test/ARCMT/releases.m test/ARCMT/releases.m.result

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Jul 15 15:04:00 PDT 2011


Author: akirtzidis
Date: Fri Jul 15 17:04:00 2011
New Revision: 135309

URL: http://llvm.org/viewvc/llvm-project?rev=135309&view=rev
Log:
[arcmt] Rewrite to "foo = nil;" not "foo = 0;", as suggested by Jordy.

Modified:
    cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
    cfe/trunk/test/ARCMT/releases.m
    cfe/trunk/test/ARCMT/releases.m.result

Modified: cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp?rev=135309&r1=135308&r2=135309&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp Fri Jul 15 17:04:00 2011
@@ -19,7 +19,9 @@
 
 #include "Transforms.h"
 #include "Internals.h"
+#include "clang/Sema/Sema.h"
 #include "clang/Sema/SemaDiagnostic.h"
+#include "clang/Lex/Preprocessor.h"
 #include "clang/AST/ParentMap.h"
 
 using namespace clang;
@@ -115,10 +117,14 @@
 
     if (E->getMethodFamily() == OMF_release &&
         isRemovable(E) && isInAtFinally(E)) {
-      // Change the -release to "receiver = 0" in a finally to avoid a leak
+      // Change the -release to "receiver = nil" in a finally to avoid a leak
       // when an exception is thrown.
       Pass.TA.replace(E->getSourceRange(), rec->getSourceRange());
-      Pass.TA.insertAfterToken(rec->getLocEnd(), " = 0");
+      if (Pass.SemaRef.getPreprocessor()
+                        .getIdentifierInfo("nil")->hasMacroDefinition())
+        Pass.TA.insertAfterToken(rec->getLocEnd(), " = nil");
+      else
+        Pass.TA.insertAfterToken(rec->getLocEnd(), " = 0");
       return true;
     }
 

Modified: cfe/trunk/test/ARCMT/releases.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/releases.m?rev=135309&r1=135308&r2=135309&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/releases.m (original)
+++ cfe/trunk/test/ARCMT/releases.m Fri Jul 15 17:04:00 2011
@@ -2,6 +2,8 @@
 // RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-exceptions -fblocks -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t
 // RUN: diff %t %s.result
 
+#define nil 0
+
 typedef int BOOL;
 
 id IhaveSideEffect();

Modified: cfe/trunk/test/ARCMT/releases.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/releases.m.result?rev=135309&r1=135308&r2=135309&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/releases.m.result (original)
+++ cfe/trunk/test/ARCMT/releases.m.result Fri Jul 15 17:04:00 2011
@@ -2,6 +2,8 @@
 // RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-exceptions -fblocks -fobjc-nonfragile-abi -fsyntax-only -x objective-c %s > %t
 // RUN: diff %t %s.result
 
+#define nil 0
+
 typedef int BOOL;
 
 id IhaveSideEffect();
@@ -37,7 +39,7 @@
 
   @try {
   } @finally {
-    x = 0;
+    x = nil;
   }
 }
   





More information about the cfe-commits mailing list