]> granicus.if.org Git - clang/commitdiff
[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186850 91177308-0d34-0410-b5e6-96231b3b80d8

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

index c167d3c3192b3aeb2002aff6c2473202f9be36ed..196f6c0b731f0e2d4b0b5ec3e9f65fe57918e682 100644 (file)
@@ -97,6 +97,8 @@ class MigrationProcess {
   FileRemapper Remapper;
 
 public:
+  bool HadARCErrors;
+
   MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient,
                    StringRef outputDir = StringRef());
 
index 8a2b939ac302ff0c551b7c47d708eaf92f53d1d1..8cd6e4bb619e8aff43c098dc2f26f01d0b5e7ca7 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 5a1b3d3f06a0df4fd696be844704898a2e2e5ad3..0b6c3d16decc79b72aca3433dd7160fed3a58ce6 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