forked from OSchip/llvm-project
[libclang] When caching code-completion results, pass the CachedCompletionAllocator
to the CodeCompletionTUInfo that is going to be used to get the results. Previously we would use ASTUnit's CodeCompletionTUInfo which has its own allocator that will go away when we reparse. That could result in a use-after-free bug when getting the parent context name from a CodeCompletionString. Addresses rdar://12568377. llvm-svn: 168133
This commit is contained in:
parent
0e551c191c
commit
2bafa0076d
|
@ -356,8 +356,9 @@ void ASTUnit::CacheCodeCompletionResults() {
|
|||
typedef CodeCompletionResult Result;
|
||||
SmallVector<Result, 8> Results;
|
||||
CachedCompletionAllocator = new GlobalCodeCompletionAllocator;
|
||||
CodeCompletionTUInfo CCTUInfo(CachedCompletionAllocator);
|
||||
TheSema->GatherGlobalCodeCompletions(*CachedCompletionAllocator,
|
||||
getCodeCompletionTUInfo(), Results);
|
||||
CCTUInfo, Results);
|
||||
|
||||
// Translate global code completions into cached completions.
|
||||
llvm::DenseMap<CanQualType, unsigned> CompletionTypes;
|
||||
|
@ -369,7 +370,7 @@ void ASTUnit::CacheCodeCompletionResults() {
|
|||
CachedCodeCompletionResult CachedResult;
|
||||
CachedResult.Completion = Results[I].CreateCodeCompletionString(*TheSema,
|
||||
*CachedCompletionAllocator,
|
||||
getCodeCompletionTUInfo(),
|
||||
CCTUInfo,
|
||||
IncludeBriefCommentsInCodeCompletion);
|
||||
CachedResult.ShowInContexts = getDeclShowContexts(Results[I].Declaration,
|
||||
Ctx->getLangOpts(),
|
||||
|
@ -435,7 +436,7 @@ void ASTUnit::CacheCodeCompletionResults() {
|
|||
CachedResult.Completion
|
||||
= Results[I].CreateCodeCompletionString(*TheSema,
|
||||
*CachedCompletionAllocator,
|
||||
getCodeCompletionTUInfo(),
|
||||
CCTUInfo,
|
||||
IncludeBriefCommentsInCodeCompletion);
|
||||
CachedResult.ShowInContexts = RemainingContexts;
|
||||
CachedResult.Priority = CCP_NestedNameSpecifier;
|
||||
|
@ -458,7 +459,7 @@ void ASTUnit::CacheCodeCompletionResults() {
|
|||
CachedResult.Completion
|
||||
= Results[I].CreateCodeCompletionString(*TheSema,
|
||||
*CachedCompletionAllocator,
|
||||
getCodeCompletionTUInfo(),
|
||||
CCTUInfo,
|
||||
IncludeBriefCommentsInCodeCompletion);
|
||||
CachedResult.ShowInContexts
|
||||
= (1LL << CodeCompletionContext::CCC_TopLevel)
|
||||
|
|
Loading…
Reference in New Issue