/// \brief Diagnostics produced while performing code completion.
SmallVector<StoredDiagnostic, 8> Diagnostics;
+ /// \brief Allocated API-exposed wrappters for Diagnostics.
+ SmallVector<CXStoredDiagnostic *, 8> DiagnosticsWrappers;
+
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
/// \brief Diag object
}
AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() {
+ llvm::DeleteContainerPointers(DiagnosticsWrappers);
delete [] Results;
for (unsigned I = 0, N = TemporaryFiles.size(); I != N; ++I)
*Results->Diag, Results->LangOpts, *Results->SourceMgr,
*Results->FileMgr, Results->Diagnostics,
Results->TemporaryBuffers);
-
+
+ Results->DiagnosticsWrappers.resize(Results->Diagnostics.size());
+
// 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
if (!Results || Index >= Results->Diagnostics.size())
return 0;
- return new CXStoredDiagnostic(Results->Diagnostics[Index], Results->LangOpts);
+ CXStoredDiagnostic *Diag = Results->DiagnosticsWrappers[Index];
+ if (!Diag)
+ Results->DiagnosticsWrappers[Index] = Diag =
+ new CXStoredDiagnostic(Results->Diagnostics[Index], Results->LangOpts);
+ return Diag;
}
unsigned long long