aboutsummaryrefslogtreecommitdiff
path: root/tools/libclang/CIndexCodeCompletion.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-02-16 19:08:06 +0000
committerDouglas Gregor <dgregor@apple.com>2011-02-16 19:08:06 +0000
commit48601b32321496b07a18fb6631f8563275d8c5fb (patch)
tree65c4d3a557ca8ebec5a43551a0561ceda2a31cf3 /tools/libclang/CIndexCodeCompletion.cpp
parentbb6f54833cda9197511678d078f7d95d8da6f27e (diff)
Teach the CXCodeCompleteResults results structure, which stores
code-completion results accessed via libclang, to extend the lifetime of the allocator used for cached global code-completion results at least until these completion results are destroyed. Fixes <rdar://problem/8997369>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125678 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/libclang/CIndexCodeCompletion.cpp')
-rw-r--r--tools/libclang/CIndexCodeCompletion.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp
index 705c62c6fe..292719bebd 100644
--- a/tools/libclang/CIndexCodeCompletion.cpp
+++ b/tools/libclang/CIndexCodeCompletion.cpp
@@ -229,6 +229,10 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults {
/// the code-completion results.
llvm::SmallVector<const llvm::MemoryBuffer *, 1> TemporaryBuffers;
+ /// \brief Allocator used to store globally cached code-completion results.
+ llvm::IntrusiveRefCntPtr<clang::GlobalCodeCompletionAllocator>
+ CachedCompletionAllocator;
+
/// \brief Allocator used to store code completion results.
clang::CodeCompletionAllocator CodeCompletionAllocator;
};
@@ -379,7 +383,7 @@ void clang_codeCompleteAt_Impl(void *UserData) {
AllocatedCXCodeCompleteResults *Results = new AllocatedCXCodeCompleteResults;
Results->Results = 0;
Results->NumResults = 0;
-
+
// Create a code-completion consumer to capture the results.
CaptureCompletionResults Capture(*Results);
@@ -392,6 +396,12 @@ void clang_codeCompleteAt_Impl(void *UserData) {
*Results->Diag, Results->LangOpts, Results->SourceMgr,
Results->FileMgr, Results->Diagnostics,
Results->TemporaryBuffers);
+
+ // Keep a reference to the allocator used for cached global completions, so
+ // that we can be sure that the memory used by our code completion strings
+ // doesn't get freed due to subsequent reparses (while the code completion
+ // results are still active).
+ Results->CachedCompletionAllocator = AST->getCachedCompletionAllocator();