aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-07-15 22:04:00 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-07-15 22:04:00 +0000
commit1aa60ff0ad1fb5bcb3042670dfdd7d5a8359d922 (patch)
tree3633486ceec548a3275caac474fe5ac812d4b729
parent3e4d10917a7ef84ebf86062e8c912de9c00597c9 (diff)
[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
-rw-r--r--lib/ARCMigrate/TransRetainReleaseDealloc.cpp10
-rw-r--r--test/ARCMT/releases.m2
-rw-r--r--test/ARCMT/releases.m.result4
3 files changed, 13 insertions, 3 deletions
diff --git a/lib/ARCMigrate/TransRetainReleaseDealloc.cpp b/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
index 8e6c533991..6f917b3246 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 @@ 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;
}
diff --git a/test/ARCMT/releases.m b/test/ARCMT/releases.m
index 74e3f47aa7..d5f21dc4c2 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 f074fb7cf7..1d36f3e6b7 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 @@ id IhaveSideEffect();
@try {
} @finally {
- x = 0;
+ x = nil;
}
}