From 7b02b583b23fac6f31e0645dc1c11340291ea4a3 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 20 Aug 2010 00:02:33 +0000 Subject: [PATCH] When we decide not to reuse a precompiled preamble, clear out the previous precompiled preamble completely. Fixes . llvm-svn: 111590 --- clang/lib/Frontend/ASTUnit.cpp | 20 ++++++++++++++++++-- clang/test/Index/Inputs/preamble-reparse-1.c | 2 ++ clang/test/Index/Inputs/preamble-reparse-2.c | 1 + clang/test/Index/preamble-reparse.c | 2 ++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 clang/test/Index/Inputs/preamble-reparse-1.c create mode 100644 clang/test/Index/Inputs/preamble-reparse-2.c create mode 100644 clang/test/Index/preamble-reparse.c diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 4395246f4932..9c5fea4717a9 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -698,9 +698,11 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) { CleanTemporaryFiles(); PreprocessedEntitiesByFile.clear(); - if (!OverrideMainBuffer) + if (!OverrideMainBuffer) { StoredDiagnostics.clear(); - + TopLevelDeclsInPreamble.clear(); + } + // Create a file manager object to provide access to and cache the filesystem. Clang.setFileManager(&getFileManager()); @@ -733,6 +735,9 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) { getSourceManager()); StoredDiagnostics[I].setLocation(Loc); } + } else { + PreprocessorOpts.PrecompiledPreambleBytes.first = 0; + PreprocessorOpts.PrecompiledPreambleBytes.second = false; } llvm::OwningPtr Act; @@ -1415,6 +1420,14 @@ bool ASTUnit::Reparse(RemappedFile *RemappedFiles, unsigned NumRemappedFiles) { } // Remap files. + PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts(); + for (PreprocessorOptions::remapped_file_buffer_iterator + R = PPOpts.remapped_file_buffer_begin(), + REnd = PPOpts.remapped_file_buffer_end(); + R != REnd; + ++R) { + delete R->second; + } Invocation->getPreprocessorOpts().clearRemappedFiles(); for (unsigned I = 0; I != NumRemappedFiles; ++I) Invocation->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, @@ -1772,6 +1785,9 @@ void ASTUnit::CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column, FullSourceLoc Loc(StoredDiagnostics[I].getLocation(), SourceMgr); StoredDiagnostics[I].setLocation(Loc); } + } else { + PreprocessorOpts.PrecompiledPreambleBytes.first = 0; + PreprocessorOpts.PrecompiledPreambleBytes.second = false; } llvm::OwningPtr Act; diff --git a/clang/test/Index/Inputs/preamble-reparse-1.c b/clang/test/Index/Inputs/preamble-reparse-1.c new file mode 100644 index 000000000000..139597f9cb07 --- /dev/null +++ b/clang/test/Index/Inputs/preamble-reparse-1.c @@ -0,0 +1,2 @@ + + diff --git a/clang/test/Index/Inputs/preamble-reparse-2.c b/clang/test/Index/Inputs/preamble-reparse-2.c new file mode 100644 index 000000000000..6d1a0d47b7f7 --- /dev/null +++ b/clang/test/Index/Inputs/preamble-reparse-2.c @@ -0,0 +1 @@ +int x; diff --git a/clang/test/Index/preamble-reparse.c b/clang/test/Index/preamble-reparse.c new file mode 100644 index 000000000000..5bd03b3f4de4 --- /dev/null +++ b/clang/test/Index/preamble-reparse.c @@ -0,0 +1,2 @@ +// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 5 local "-remap-file=%S/Inputs/preamble-reparse-1.c;%S/Inputs/preamble-reparse-2.c" %S/Inputs/preamble-reparse-1.c | FileCheck %s +// CHECK: preamble-reparse-1.c:1:5: VarDecl=x:1:5 Extent=[1:1 - 1:6]