]> granicus.if.org Git - clang/commitdiff
[arcmt] Rewrite to "foo = nil;" not "foo = 0;", as suggested by Jordy.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 15 Jul 2011 22:04:00 +0000 (22:04 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 15 Jul 2011 22:04:00 +0000 (22:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135309 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ARCMigrate/TransRetainReleaseDealloc.cpp
test/ARCMT/releases.m
test/ARCMT/releases.m.result

index 8e6c533991ec402b54d5eb9a746a2d801635d2b6..6f917b324655f6ccc6f3844a1e8ce3256d7dc6cd 100644 (file)
@@ -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 @@ public:
 
     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;
     }
 
index 74e3f47aa7b50a20cd06fd2029b095375d3886a4..d5f21dc4c2a737d936e409fc99e75076e7d4804f 100644 (file)
@@ -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();
index f074fb7cf7b30e7a1b3520a3cb13a6753b3779f5..1d36f3e6b7de8db6d7cb79e9386cbbd7b5e5c149 100644 (file)
@@ -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 @@ id IhaveSideEffect();
 
   @try {
   } @finally {
-    x = 0;
+    x = nil;
   }
 }