From: Chris Lattner Date: Mon, 27 Apr 2009 22:02:30 +0000 (+0000) Subject: -E, -Eonly and -parse-noop now work with PCH! X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cc7dea8f32a46dac852178df1557fc97e799e3d1;p=clang -E, -Eonly and -parse-noop now work with PCH! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70259 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 7483f7854c..7ca0300eed 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -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(Reader.GetDecl(ReadUnalignedLE32(d))); if (SemaObj) { diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 4f4d3a3fff..afc57f127d 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -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 Reader; + llvm::OwningPtr 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 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 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)