r174386 - [arcmt] Make sure the objc migrators work fine when used with a PCH.

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Feb 5 08:37:01 PST 2013


Author: akirtzidis
Date: Tue Feb  5 10:37:00 2013
New Revision: 174386

URL: http://llvm.org/viewvc/llvm-project?rev=174386&view=rev
Log:
[arcmt] Make sure the objc migrators work fine when used with a PCH.

rdar://13140508

Added:
    cfe/trunk/test/ARCMT/check-with-pch.m
    cfe/trunk/test/ARCMT/migrate-with-pch.m
    cfe/trunk/test/ARCMT/objcmt-with-pch.m
    cfe/trunk/test/ARCMT/objcmt-with-pch.m.result
Modified:
    cfe/trunk/lib/ARCMigrate/ARCMT.cpp

Modified: cfe/trunk/lib/ARCMigrate/ARCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ARCMT.cpp?rev=174386&r1=174385&r2=174386&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ARCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ARCMT.cpp Tue Feb  5 10:37:00 2013
@@ -18,6 +18,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Sema/SemaDiagnostic.h"
+#include "clang/Serialization/ASTReader.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/MemoryBuffer.h"
 using namespace clang;
@@ -174,8 +175,24 @@ static CompilerInvocation *
 createInvocationForMigration(CompilerInvocation &origCI) {
   OwningPtr<CompilerInvocation> CInvok;
   CInvok.reset(new CompilerInvocation(origCI));
-  CInvok->getPreprocessorOpts().ImplicitPCHInclude = std::string();
-  CInvok->getPreprocessorOpts().ImplicitPTHInclude = std::string();
+  PreprocessorOptions &PPOpts = CInvok->getPreprocessorOpts();
+  if (!PPOpts.ImplicitPCHInclude.empty()) {
+    // We can't use a PCH because it was likely built in non-ARC mode and we
+    // want to parse in ARC. Include the original header.
+    FileManager FileMgr(origCI.getFileSystemOpts());
+    IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
+    IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
+        new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(),
+                              new IgnoringDiagConsumer()));
+    std::string OriginalFile =
+        ASTReader::getOriginalSourceFile(PPOpts.ImplicitPCHInclude,
+                                         FileMgr, *Diags);
+    if (!OriginalFile.empty())
+      PPOpts.Includes.insert(PPOpts.Includes.begin(), OriginalFile);
+    PPOpts.ImplicitPCHInclude.clear();
+  }
+  // FIXME: Get the original header of a PTH as well.
+  CInvok->getPreprocessorOpts().ImplicitPTHInclude.clear();
   std::string define = getARCMTMacroName();
   define += '=';
   CInvok->getPreprocessorOpts().addMacroDef(define);

Added: cfe/trunk/test/ARCMT/check-with-pch.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/check-with-pch.m?rev=174386&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/check-with-pch.m (added)
+++ cfe/trunk/test/ARCMT/check-with-pch.m Tue Feb  5 10:37:00 2013
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -x objective-c -triple x86_64-apple-darwin10 %S/Common.h -emit-pch -o %t.pch
+// RUN: %clang_cc1 -include-pch %t.pch -arcmt-check -verify -triple x86_64-apple-darwin10 -fblocks -Werror %s
+// DISABLE: mingw32
+
+// rdar://9601437
+ at interface I9601437 {
+  __unsafe_unretained id x;
+}
+-(void)Meth;
+ at end
+
+ at implementation I9601437
+-(void)Meth {
+  self->x = [NSObject new]; // expected-error {{assigning retained object}}
+}
+ at end

Added: cfe/trunk/test/ARCMT/migrate-with-pch.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/migrate-with-pch.m?rev=174386&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/migrate-with-pch.m (added)
+++ cfe/trunk/test/ARCMT/migrate-with-pch.m Tue Feb  5 10:37:00 2013
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x objective-c %S/Common.h -emit-pch -o %t.pch
+// RUN: %clang_cc1 -arcmt-migrate -mt-migrate-directory %t %S/Inputs/test1.m.in -x objective-c -include-pch %t.pch 
+// RUN: %clang_cc1 -arcmt-migrate -mt-migrate-directory %t %S/Inputs/test2.m.in -x objective-c -include-pch %t.pch
+// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %S/Inputs/test1.m.in.result %S/Inputs/test2.m.in.result %S/Inputs/test.h.result
+// RUN: rm -rf %t
+// DISABLE: mingw32

Added: cfe/trunk/test/ARCMT/objcmt-with-pch.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-with-pch.m?rev=174386&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-with-pch.m (added)
+++ cfe/trunk/test/ARCMT/objcmt-with-pch.m Tue Feb  5 10:37:00 2013
@@ -0,0 +1,16 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c %S/Common.h -emit-pch -o %t.pch
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -include-pch %t.pch
+// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s.result -include-pch %t.pch
+
+ at interface NSNumber : NSObject
+ at end
+
+ at interface NSNumber (NSNumberCreation)
++ (NSNumber *)numberWithInt:(int)value;
+ at end
+
+void foo() {
+  NSNumber *n = [NSNumber numberWithInt:1];
+}

Added: cfe/trunk/test/ARCMT/objcmt-with-pch.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-with-pch.m.result?rev=174386&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-with-pch.m.result (added)
+++ cfe/trunk/test/ARCMT/objcmt-with-pch.m.result Tue Feb  5 10:37:00 2013
@@ -0,0 +1,16 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c %S/Common.h -emit-pch -o %t.pch
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -include-pch %t.pch
+// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s.result -include-pch %t.pch
+
+ at interface NSNumber : NSObject
+ at end
+
+ at interface NSNumber (NSNumberCreation)
++ (NSNumber *)numberWithInt:(int)value;
+ at end
+
+void foo() {
+  NSNumber *n = @1;
+}





More information about the cfe-commits mailing list