From: Argyrios Kyrtzidis Date: Mon, 22 Jul 2013 18:13:54 +0000 (+0000) Subject: [arcmt] Only disable ARC in the second compilation if there were actually ARC errors... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec852d908f453e1c97a85fe0292774d519d39914;p=platform%2Fupstream%2Fllvm.git [arcmt] Only disable ARC in the second compilation if there were actually ARC errors in the checking phase. rdar://14490204 llvm-svn: 186850 --- diff --git a/clang/include/clang/ARCMigrate/ARCMT.h b/clang/include/clang/ARCMigrate/ARCMT.h index c167d3c..196f6c0 100644 --- a/clang/include/clang/ARCMigrate/ARCMT.h +++ b/clang/include/clang/ARCMigrate/ARCMT.h @@ -97,6 +97,8 @@ class MigrationProcess { FileRemapper Remapper; public: + bool HadARCErrors; + MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient, StringRef outputDir = StringRef()); diff --git a/clang/lib/ARCMigrate/ARCMT.cpp b/clang/lib/ARCMigrate/ARCMT.cpp index 8a2b939..8cd6e4b 100644 --- a/clang/lib/ARCMigrate/ARCMT.cpp +++ b/clang/lib/ARCMigrate/ARCMT.cpp @@ -270,6 +270,8 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI, return true; } + bool hadARCErrors = capturedDiags.hasErrors(); + // Don't filter diagnostics anymore. Diags->setClient(DiagClient, /*ShouldOwnClient=*/false); @@ -321,12 +323,14 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI, DiagClient->EndSourceFile(); errRec.FinishCapture(); - // 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; - // Disable auto-synthesize to avoid "@synthesize of 'weak' property is only - // allowed in ARC" errors. - origCI.getLangOpts()->ObjCDefaultSynthProperties = false; + if (hadARCErrors) { + // 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; + // Disable auto-synthesize to avoid "@synthesize of 'weak' property is only + // allowed in ARC" errors. + origCI.getLangOpts()->ObjCDefaultSynthProperties = false; + } return capturedDiags.hasErrors() || testAct.hasReportedErrors(); } @@ -377,9 +381,14 @@ static bool applyTransforms(CompilerInvocation &origCI, origCI.getLangOpts()->ObjCAutoRefCount = true; return migration.getRemapper().overwriteOriginal(*Diags); } 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; + if (migration.HadARCErrors) { + // 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; + // Disable auto-synthesize to avoid "@synthesize of 'weak' property is only + // allowed in ARC" errors. + origCI.getLangOpts()->ObjCDefaultSynthProperties = false; + } return migration.getRemapper().flushToDisk(outputDir, *Diags); } } @@ -548,7 +557,7 @@ MigrationProcess::RewriteListener::~RewriteListener() { } MigrationProcess::MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient, StringRef outputDir) - : OrigCI(CI), DiagClient(diagClient) { + : OrigCI(CI), DiagClient(diagClient), HadARCErrors(false) { if (!outputDir.empty()) { IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); IntrusiveRefCntPtr Diags( @@ -591,6 +600,8 @@ bool MigrationProcess::applyTransform(TransformFn trans, } Unit->setOwnsRemappedFileBuffers(false); // FileRemapper manages that. + HadARCErrors = HadARCErrors || capturedDiags.hasErrors(); + // Don't filter diagnostics anymore. Diags->setClient(DiagClient, /*ShouldOwnClient=*/false); diff --git a/clang/test/ARCMT/checking-in-arc.m b/clang/test/ARCMT/checking-in-arc.m index 5a1b3d3..0b6c3d1 100644 --- a/clang/test/ARCMT/checking-in-arc.m +++ b/clang/test/ARCMT/checking-in-arc.m @@ -45,3 +45,7 @@ extern const CFStringRef kUTTypeRTF; @implementation Test @end + +#if ! __has_feature(objc_arc) +#error This file must be compiled with ARC (set -fobjc_arc flag on file) +#endif