From: Argyrios Kyrtzidis Date: Thu, 14 Jul 2011 00:17:54 +0000 (+0000) Subject: [arcmt] Make sure migrating to ARC works even if '-fobjc-arc' is included in command... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a944b123e49790e4cb0a8f4d6ee3a65e185127aa;p=clang [arcmt] Make sure migrating to ARC works even if '-fobjc-arc' is included in command-line flags. rdar://9567824 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135115 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ARCMigrate/ARCMT.cpp b/lib/ARCMigrate/ARCMT.cpp index 73c8dbd6a4..f1d947da67 100644 --- a/lib/ARCMigrate/ARCMT.cpp +++ b/lib/ARCMigrate/ARCMT.cpp @@ -262,6 +262,10 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI, DiagClient->EndSourceFile(); + // If we are migrating code that gets the '-fobjc-arc' flag, make sure + // to remove it so that we don't get errors from normal compilation. + origCI.getLangOpts().ObjCAutoRefCount = false; + return capturedDiags.hasErrors(); } @@ -302,8 +306,12 @@ static bool applyTransforms(CompilerInvocation &origCI, if (outputDir.empty()) { origCI.getLangOpts().ObjCAutoRefCount = true; return migration.getRemapper().overwriteOriginal(*Diags); - } else + } else { + // If we are migrating code that gets the '-fobjc-arc' flag, make sure + // to remove it so that we don't get errors from normal compilation. + origCI.getLangOpts().ObjCAutoRefCount = false; return migration.getRemapper().flushToDisk(outputDir, *Diags); + } } bool arcmt::applyTransformations(CompilerInvocation &origCI, diff --git a/test/ARCMT/with-arc-mode-check.m b/test/ARCMT/with-arc-mode-check.m new file mode 100644 index 0000000000..c3146ef3b6 --- /dev/null +++ b/test/ARCMT/with-arc-mode-check.m @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -arcmt-check -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { + [p release]; +} diff --git a/test/ARCMT/with-arc-mode-migrate.m b/test/ARCMT/with-arc-mode-migrate.m new file mode 100644 index 0000000000..3851bc7731 --- /dev/null +++ b/test/ARCMT/with-arc-mode-migrate.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: %clang_cc1 -arcmt-migrate -arcmt-migrate-directory %t -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc %s +// RUN: c-arcmt-test -arcmt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result +// RUN: rm -rf %t + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { + [p release]; +} diff --git a/test/ARCMT/with-arc-mode-migrate.m.result b/test/ARCMT/with-arc-mode-migrate.m.result new file mode 100644 index 0000000000..c2222ae7b6 --- /dev/null +++ b/test/ARCMT/with-arc-mode-migrate.m.result @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: %clang_cc1 -arcmt-migrate -arcmt-migrate-directory %t -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc %s +// RUN: c-arcmt-test -arcmt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result +// RUN: rm -rf %t + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { +} diff --git a/test/ARCMT/with-arc-mode-modify.m b/test/ARCMT/with-arc-mode-modify.m new file mode 100644 index 0000000000..17a398072e --- /dev/null +++ b/test/ARCMT/with-arc-mode-modify.m @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: cp %s %t +// RUN: %clang_cc1 -arcmt-modify -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %t +// RUN: diff %t %s.result +// RUN: rm %t + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { + [p release]; +} diff --git a/test/ARCMT/with-arc-mode-modify.m.result b/test/ARCMT/with-arc-mode-modify.m.result new file mode 100644 index 0000000000..97c5128cd9 --- /dev/null +++ b/test/ARCMT/with-arc-mode-modify.m.result @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %s.result +// RUN: cp %s %t +// RUN: %clang_cc1 -arcmt-modify -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c %t +// RUN: diff %t %s.result +// RUN: rm %t + +@protocol NSObject +- (oneway void)release; +@end + +void test1(id p) { +}