[cfe-commits] r110216 - in /cfe/trunk: lib/Frontend/ASTUnit.cpp tools/libclang/CIndexCodeCompletion.cpp
Douglas Gregor
dgregor at apple.com
Wed Aug 4 10:07:00 PDT 2010
Author: dgregor
Date: Wed Aug 4 12:07:00 2010
New Revision: 110216
URL: http://llvm.org/viewvc/llvm-project?rev=110216&view=rev
Log:
When performing in-process code completion, don't free the remapped
file buffers until the code completion results are destroyed;
diagnostics may end up referring into the source.
Modified:
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=110216&r1=110215&r2=110216&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Wed Aug 4 12:07:00 2010
@@ -1213,6 +1213,7 @@
// Remap files.
PreprocessorOpts.clearRemappedFiles();
+ PreprocessorOpts.RetainRemappedFileBuffers = true;
for (unsigned I = 0; I != NumRemappedFiles; ++I)
PreprocessorOpts.addRemappedFile(RemappedFiles[I].first,
RemappedFiles[I].second);
Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=110216&r1=110215&r2=110216&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Wed Aug 4 12:07:00 2010
@@ -224,10 +224,6 @@
AllocatedCXCodeCompleteResults();
~AllocatedCXCodeCompleteResults();
- /// \brief The memory buffer from which we parsed the results. We
- /// retain this buffer because the completion strings point into it.
- llvm::MemoryBuffer *Buffer;
-
/// \brief Diagnostics produced while performing code completion.
llvm::SmallVector<StoredDiagnostic, 8> Diagnostics;
@@ -246,20 +242,23 @@
/// \brief Temporary files that should be removed once we have finished
/// with the code-completion results.
std::vector<llvm::sys::Path> TemporaryFiles;
+
+ /// \brief Temporary buffers that will be deleted once we have finished with the code-completion results.
+ llvm::SmallVector<const llvm::MemoryBuffer *, 1> TemporaryBuffers;
};
AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults()
- : CXCodeCompleteResults(), Buffer(0), Diag(new Diagnostic),
- SourceMgr(*Diag) { }
+ : CXCodeCompleteResults(), Diag(new Diagnostic), SourceMgr(*Diag) { }
AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() {
for (unsigned I = 0, N = NumResults; I != N; ++I)
delete (CXStoredCodeCompletionString *)Results[I].CompletionString;
delete [] Results;
- delete Buffer;
for (unsigned I = 0, N = TemporaryFiles.size(); I != N; ++I)
TemporaryFiles[I].eraseFromDisk();
+ for (unsigned I = 0, N = TemporaryBuffers.size(); I != N; ++I)
+ delete TemporaryBuffers[I];
}
CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
@@ -409,7 +408,6 @@
AllocatedCXCodeCompleteResults *Results = new AllocatedCXCodeCompleteResults;
Results->Results = 0;
Results->NumResults = 0;
- Results->Buffer = 0;
// FIXME: Set Results->LangOpts!
if (MemoryBuffer *F = MemoryBuffer::getFile(ResultsFile.c_str())) {
llvm::SmallVector<CXCompletionResult, 4> CompletionResults;
@@ -445,7 +443,7 @@
Results->NumResults = CompletionResults.size();
memcpy(Results->Results, CompletionResults.data(),
CompletionResults.size() * sizeof(CXCompletionResult));
- Results->Buffer = F;
+ Results->TemporaryBuffers.push_back(F);
}
LoadSerializedDiagnostics(DiagnosticsFile, num_unsaved_files, unsaved_files,
@@ -602,11 +600,15 @@
AllocatedCXCodeCompleteResults *Results = new AllocatedCXCodeCompleteResults;
Results->Results = 0;
Results->NumResults = 0;
- Results->Buffer = 0;
// Create a code-completion consumer to capture the results.
CaptureCompletionResults Capture(*Results);
+ // Make sure that we free the temporary buffers when the
+ // code-completion constructor is freed.
+ for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I)
+ Results->TemporaryBuffers.push_back(RemappedFiles[I].second);
+
// Perform completion.
AST->CodeComplete(complete_filename, complete_line, complete_column,
RemappedFiles.data(), RemappedFiles.size(), Capture,
More information about the cfe-commits
mailing list