]> granicus.if.org Git - clang/commitdiff
-E, -Eonly and -parse-noop now work with PCH!
authorChris Lattner <sabre@nondot.org>
Mon, 27 Apr 2009 22:02:30 +0000 (22:02 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 27 Apr 2009 22:02:30 +0000 (22:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70259 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/PCHReader.cpp
tools/clang-cc/clang-cc.cpp

index 7483f7854c60c0ddade3f08ef6f1e1334feec865..7ca0300eed1ee1d64db278df7ff2ab26a99ebdf1 100644 (file)
@@ -270,6 +270,8 @@ public:
     // Read all of the declarations visible at global scope with this
     // name.
     Sema *SemaObj = Reader.getSema();
+    if (!SemaObj) return II;
+    
     while (DataLen > 0) {
       NamedDecl *D = cast<NamedDecl>(Reader.GetDecl(ReadUnalignedLE32(d)));
       if (SemaObj) {
index 4f4d3a3fff36afc17f73ea9832bcbacfebd7a4f1..afc57f127d3c49e485692786104ede6ada0996f4 100644 (file)
@@ -1667,12 +1667,8 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
     break;
   }      
 
-  case PrintPreprocessedInput: {      // -E mode.
-    llvm::TimeRegion Timer(ClangFrontendTimer);
-    DoPrintPreprocessedInput(PP, OutputFile);
-    ClearSourceMgr = true;
+  case PrintPreprocessedInput:
     break;
-  }
       
   case ParseNoop:
     break;
@@ -1750,19 +1746,23 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
                                       /* FreeMemory = */ !DisableFree,
                                       /* size_reserve = */0,
                        /* InitializeBuiltins = */ImplicitIncludePCH.empty()));
-     
+  llvm::OwningPtr<PCHReader> Reader;
+  llvm::OwningPtr<ExternalASTSource> Source;
+    
   if (!ImplicitIncludePCH.empty()) {
+    Reader.reset(new PCHReader(PP, ContextOwner.get()));
+    
     // The user has asked us to include a precompiled header. Load
     // the precompiled header into the AST context.
-    llvm::OwningPtr<PCHReader> Reader(new PCHReader(PP, ContextOwner.get()));
     switch (Reader->ReadPCH(ImplicitIncludePCH)) {
     case PCHReader::Success: {
       // Attach the PCH reader to the AST context as an external AST
       // source, so that declarations will be deserialized from the
       // PCH file as needed.
-      llvm::OwningPtr<ExternalASTSource> Source(Reader.take());
-      if (ContextOwner)
+      if (ContextOwner) {
+        Source.reset(Reader.take());
         ContextOwner->setExternalSource(Source);
+      }
 
       // Clear out the predefines buffer, because all of the
       // predefines are already in the PCH file.
@@ -1814,6 +1814,10 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
     llvm::TimeRegion Timer(ClangFrontendTimer);
     ParseFile(PP, new MinimalAction(PP));
     ClearSourceMgr = true;
+  } else if (PA == PrintPreprocessedInput){  // -E mode.
+    llvm::TimeRegion Timer(ClangFrontendTimer);
+    DoPrintPreprocessedInput(PP, OutputFile);
+    ClearSourceMgr = true;
   }
   
   if (FixItRewrite)