aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Frontend/PCHReader.cpp2
-rw-r--r--tools/clang-cc/clang-cc.cpp22
2 files changed, 15 insertions, 9 deletions
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<NamedDecl>(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<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)