[cfe-commits] r149079 - in /cfe/trunk: include/clang/ARCMigrate/ARCMT.h lib/ARCMigrate/ARCMT.cpp lib/ARCMigrate/Transforms.cpp lib/Frontend/CompilerInvocation.cpp test/ARCMT/GC-no-finalize-removal.m test/ARCMT/GC-no-finalize-removal.m.result tools/arcmt-test/arcmt-test.cpp
Fariborz Jahanian
fjahanian at apple.com
Thu Jan 26 12:57:59 PST 2012
Author: fjahanian
Date: Thu Jan 26 14:57:58 2012
New Revision: 149079
URL: http://llvm.org/viewvc/llvm-project?rev=149079&view=rev
Log:
objc-arc: introduce -no-finalize-removal which in gc mode,
leaves "finalize' behind and in arc mode, does not
include it. This allows the migrated source to be compiled
in both gc and arc mode. // rdar://10532441
Added:
cfe/trunk/test/ARCMT/GC-no-finalize-removal.m
cfe/trunk/test/ARCMT/GC-no-finalize-removal.m.result
Modified:
cfe/trunk/include/clang/ARCMigrate/ARCMT.h
cfe/trunk/lib/ARCMigrate/ARCMT.cpp
cfe/trunk/lib/ARCMigrate/Transforms.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/tools/arcmt-test/arcmt-test.cpp
Modified: cfe/trunk/include/clang/ARCMigrate/ARCMT.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ARCMigrate/ARCMT.h?rev=149079&r1=149078&r2=149079&view=diff
==============================================================================
--- cfe/trunk/include/clang/ARCMigrate/ARCMT.h (original)
+++ cfe/trunk/include/clang/ARCMigrate/ARCMT.h Thu Jan 26 14:57:58 2012
@@ -78,7 +78,8 @@
typedef void (*TransformFn)(MigrationPass &pass);
-std::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode);
+std::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode,
+ bool NoFinalizeRemoval);
class MigrationProcess {
CompilerInvocation OrigCI;
Modified: cfe/trunk/lib/ARCMigrate/ARCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ARCMT.cpp?rev=149079&r1=149078&r2=149079&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ARCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ARCMT.cpp Thu Jan 26 14:57:58 2012
@@ -232,7 +232,8 @@
bool NoNSAllocReallocError = origCI.getMigratorOpts().NoNSAllocReallocError;
bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval;
- std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode);
+ std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode,
+ NoFinalizeRemoval);
assert(!transforms.empty());
llvm::OwningPtr<CompilerInvocation> CInvok;
@@ -337,8 +338,10 @@
CInvok.getFrontendOpts().Inputs.push_back(Input);
MigrationProcess migration(CInvok, DiagClient, outputDir);
+ bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval;
- std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode);
+ std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode,
+ NoFinalizeRemoval);
assert(!transforms.empty());
for (unsigned i=0, e = transforms.size(); i != e; ++i) {
Modified: cfe/trunk/lib/ARCMigrate/Transforms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Transforms.cpp?rev=149079&r1=149078&r2=149079&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/Transforms.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/Transforms.cpp Thu Jan 26 14:57:58 2012
@@ -502,6 +502,45 @@
ASTTransform(*this).TraverseDecl(TU);
}
+static void GCRewriteFinalize(MigrationPass &pass) {
+ ASTContext &Ctx = pass.Ctx;
+ TransformActions &TA = pass.TA;
+ DeclContext *DC = Ctx.getTranslationUnitDecl();
+ Selector FinalizeSel =
+ Ctx.Selectors.getNullarySelector(&pass.Ctx.Idents.get("finalize"));
+
+ typedef DeclContext::specific_decl_iterator<ObjCImplementationDecl>
+ impl_iterator;
+ for (impl_iterator I = impl_iterator(DC->decls_begin()),
+ E = impl_iterator(DC->decls_end()); I != E; ++I) {
+ for (ObjCImplementationDecl::instmeth_iterator
+ MI = (*I)->instmeth_begin(),
+ ME = (*I)->instmeth_end(); MI != ME; ++MI) {
+ ObjCMethodDecl *MD = *MI;
+ if (!MD->hasBody())
+ continue;
+
+ if (MD->isInstanceMethod() && MD->getSelector() == FinalizeSel) {
+ ObjCMethodDecl *FinalizeM = MD;
+ Transaction Trans(TA);
+ TA.insert(FinalizeM->getSourceRange().getBegin(),
+ "#if !__has_feature(objc_arc)\n");
+ CharSourceRange::getTokenRange(FinalizeM->getSourceRange());
+ const SourceManager &SM = pass.Ctx.getSourceManager();
+ const LangOptions &LangOpts = pass.Ctx.getLangOptions();
+ bool Invalid;
+ std::string str = "\n#endif\n";
+ str += Lexer::getSourceText(
+ CharSourceRange::getTokenRange(FinalizeM->getSourceRange()),
+ SM, LangOpts, &Invalid);
+ TA.insertAfterToken(FinalizeM->getSourceRange().getEnd(), str);
+
+ break;
+ }
+ }
+ }
+}
+
//===----------------------------------------------------------------------===//
// getAllTransformations.
//===----------------------------------------------------------------------===//
@@ -531,9 +570,12 @@
}
std::vector<TransformFn> arcmt::getAllTransformations(
- LangOptions::GCMode OrigGCMode) {
+ LangOptions::GCMode OrigGCMode,
+ bool NoFinalizeRemoval) {
std::vector<TransformFn> transforms;
+ if (OrigGCMode == LangOptions::GCOnly && NoFinalizeRemoval)
+ transforms.push_back(GCRewriteFinalize);
transforms.push_back(independentTransforms);
// This depends on previous transformations removing various expressions.
transforms.push_back(removeEmptyStatementsAndDeallocFinalize);
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=149079&r1=149078&r2=149079&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Jan 26 14:57:58 2012
@@ -1065,6 +1065,7 @@
static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args) {
Opts.NoNSAllocReallocError = Args.hasArg(OPT_migrator_no_nsalloc_error);
+ Opts.NoFinalizeRemoval = Args.hasArg(OPT_migrator_no_finalize_removal);
return true;
}
Added: cfe/trunk/test/ARCMT/GC-no-finalize-removal.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/GC-no-finalize-removal.m?rev=149079&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/GC-no-finalize-removal.m (added)
+++ cfe/trunk/test/ARCMT/GC-no-finalize-removal.m Thu Jan 26 14:57:58 2012
@@ -0,0 +1,92 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -x objective-c %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-gc-only -no-finalize-removal -x objective-c %s > %t
+// RUN: diff %t %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-gc-only -no-finalize-removal -x objective-c++ %s > %t
+// RUN: diff %t %s.result
+// DISABLE: mingw32
+
+#include "Common.h"
+#include "GC.h"
+
+void test1(CFTypeRef *cft) {
+ id x = NSMakeCollectable(cft);
+}
+
+ at interface I1 {
+ __strong I1 *myivar;
+}
+ at end
+
+ at implementation I1
+-(void)dealloc {
+ // dealloc
+ test1(0);
+}
+
+-(void)finalize {
+ // finalize
+ test1(0);
+}
+ at end
+
+ at interface I2
+ at property (retain) id prop;
+ at end
+
+ at implementation I2
+ at synthesize prop;
+
+-(void)finalize {
+ self.prop = 0;
+ // finalize
+ test1(0);
+}
+ at end
+
+__attribute__((objc_arc_weak_reference_unavailable))
+ at interface QQ {
+ __weak id s;
+ __weak QQ *q;
+}
+ at end
+
+ at interface I3
+ at property (assign) I3 *__weak pw1, *__weak pw2;
+ at property (assign) I3 *__strong ps;
+ at property (assign) I3 * pds;
+ at end
+
+ at interface I4Impl {
+ I4Impl *pds2;
+ I4Impl *pds3;
+ __weak I4Impl *pw3;
+ __weak I4Impl *pw4;
+}
+ at property (assign) I4Impl *__weak pw1, *__weak pw2;
+ at property (assign) I4Impl *__strong ps;
+ at property (assign) I4Impl * pds;
+ at property (assign) I4Impl * pds2;
+ at property (readwrite) I4Impl * pds3;
+ at property (readonly) I4Impl * pds4;
+ at property (readonly) __weak I4Impl *pw3;
+ at property (assign) __weak I4Impl *pw4;
+ at end
+
+ at implementation I4Impl
+ at synthesize pw1, pw2, pw3, pw4, ps, pds, pds2, pds3, pds4;
+
+-(void)test1:(CFTypeRef *)cft {
+ id x = NSMakeCollectable(cft);
+}
+ at end
+
+// rdar://10532449
+ at interface rdar10532449
+ at property (assign) id assign_prop;
+ at property (assign, readonly) id __strong strong_readonly_prop;
+ at property (assign) id __weak weak_prop;
+ at end
+
+ at implementation rdar10532449
+ at synthesize assign_prop, strong_readonly_prop, weak_prop;
+ at end
Added: cfe/trunk/test/ARCMT/GC-no-finalize-removal.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/GC-no-finalize-removal.m.result?rev=149079&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/GC-no-finalize-removal.m.result (added)
+++ cfe/trunk/test/ARCMT/GC-no-finalize-removal.m.result Thu Jan 26 14:57:58 2012
@@ -0,0 +1,100 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -x objective-c %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-gc-only -no-finalize-removal -x objective-c %s > %t
+// RUN: diff %t %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-macosx10.7 -fsyntax-only -fobjc-gc-only -no-finalize-removal -x objective-c++ %s > %t
+// RUN: diff %t %s.result
+// DISABLE: mingw32
+
+#include "Common.h"
+#include "GC.h"
+
+void test1(CFTypeRef *cft) {
+ id x = CFBridgingRelease(cft);
+}
+
+ at interface I1 {
+ I1 *myivar;
+}
+ at end
+
+ at implementation I1
+-(void)dealloc {
+ // dealloc
+ test1(0);
+}
+
+#if !__has_feature(objc_arc)
+-(void)finalize {
+ // finalize
+ test1(0);
+}
+#endif
+ at end
+
+ at interface I2
+ at property (strong) id prop;
+ at end
+
+ at implementation I2
+ at synthesize prop;
+
+#if !__has_feature(objc_arc)
+-(void)finalize {
+ self.prop = 0;
+ // finalize
+ test1(0);
+}
+#endif
+-(void)dealloc {
+ // finalize
+ test1(0);
+}
+ at end
+
+__attribute__((objc_arc_weak_reference_unavailable))
+ at interface QQ {
+ __weak id s;
+ __unsafe_unretained QQ *q;
+}
+ at end
+
+ at interface I3
+ at property (weak) I3 * pw1, * pw2;
+ at property (strong) I3 * ps;
+ at property (assign) I3 * pds;
+ at end
+
+ at interface I4Impl {
+ I4Impl *__strong pds2;
+ I4Impl *pds3;
+ __weak I4Impl *pw3;
+ __weak I4Impl *pw4;
+}
+ at property (weak) I4Impl * pw1, * pw2;
+ at property (strong) I4Impl * ps;
+ at property (strong) I4Impl * pds;
+ at property (strong) I4Impl * pds2;
+ at property (readwrite) I4Impl * pds3;
+ at property (readonly) I4Impl * pds4;
+ at property (weak, readonly) I4Impl *pw3;
+ at property (weak) I4Impl *pw4;
+ at end
+
+ at implementation I4Impl
+ at synthesize pw1, pw2, pw3, pw4, ps, pds, pds2, pds3, pds4;
+
+-(void)test1:(CFTypeRef *)cft {
+ id x = CFBridgingRelease(cft);
+}
+ at end
+
+// rdar://10532449
+ at interface rdar10532449
+ at property (strong) id assign_prop;
+ at property (strong, readonly) id strong_readonly_prop;
+ at property (weak) id weak_prop;
+ at end
+
+ at implementation rdar10532449
+ at synthesize assign_prop, strong_readonly_prop, weak_prop;
+ at end
Modified: cfe/trunk/tools/arcmt-test/arcmt-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/arcmt-test/arcmt-test.cpp?rev=149079&r1=149078&r2=149079&view=diff
==============================================================================
--- cfe/trunk/tools/arcmt-test/arcmt-test.cpp (original)
+++ cfe/trunk/tools/arcmt-test/arcmt-test.cpp Thu Jan 26 14:57:58 2012
@@ -173,7 +173,8 @@
MigrationProcess migration(origCI, DiagClient);
std::vector<TransformFn>
- transforms = arcmt::getAllTransformations(origCI.getLangOpts()->getGC());
+ transforms = arcmt::getAllTransformations(origCI.getLangOpts()->getGC(),
+ origCI.getMigratorOpts().NoFinalizeRemoval);
assert(!transforms.empty());
llvm::OwningPtr<PrintTransforms> transformPrinter;
More information about the cfe-commits
mailing list