[arcmt] Only disable ARC in the second compilation if there were actually ARC errors...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 22 Jul 2013 18:13:54 +0000 (18:13 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 22 Jul 2013 18:13:54 +0000 (18:13 +0000)
rdar://14490204

llvm-svn: 186850

clang/include/clang/ARCMigrate/ARCMT.h
clang/lib/ARCMigrate/ARCMT.cpp
clang/test/ARCMT/checking-in-arc.m

index c167d3c..196f6c0 100644 (file)
@@ -97,6 +97,8 @@ class MigrationProcess {
   FileRemapper Remapper;
 
 public:
+  bool HadARCErrors;
+
   MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient,
                    StringRef outputDir = StringRef());
 
index 8a2b939..8cd6e4b 100644 (file)
@@ -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<DiagnosticIDs> DiagID(new DiagnosticIDs());
     IntrusiveRefCntPtr<DiagnosticsEngine> 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);
 
index 5a1b3d3..0b6c3d1 100644 (file)
@@ -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