[arcmt] Rewrite to "foo = nil;" not "foo = 0;", as suggested by Jordy.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135309 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/ARCMigrate/TransRetainReleaseDealloc.cpp b/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
index 8e6c533..6f917b3 100644
--- a/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
+++ b/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
@@ -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;
     }
 
diff --git a/test/ARCMT/releases.m b/test/ARCMT/releases.m
index 74e3f47..d5f21dc 100644
--- a/test/ARCMT/releases.m
+++ b/test/ARCMT/releases.m
@@ -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();
diff --git a/test/ARCMT/releases.m.result b/test/ARCMT/releases.m.result
index f074fb7..1d36f3e 100644
--- a/test/ARCMT/releases.m.result
+++ b/test/ARCMT/releases.m.result
@@ -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;
   }
 }