[libclang] Make sure we don't try to erase past the StoredDiagnostics vector.

Ted came upon the bug but I couldn't make a test out of it.

llvm-svn: 142805
This commit is contained in:
Argyrios Kyrtzidis 2011-10-24 17:25:20 +00:00
parent d48d52e7b2
commit 067cbfa299
2 changed files with 22 additions and 19 deletions

View File

@ -559,17 +559,26 @@ public:
}
// Retrieve the diagnostics associated with this AST
typedef const StoredDiagnostic *stored_diag_iterator;
stored_diag_iterator stored_diag_begin() const {
typedef StoredDiagnostic *stored_diag_iterator;
typedef const StoredDiagnostic *stored_diag_const_iterator;
stored_diag_const_iterator stored_diag_begin() const {
return StoredDiagnostics.begin();
}
stored_diag_iterator stored_diag_end() const {
stored_diag_iterator stored_diag_begin() {
return StoredDiagnostics.begin();
}
stored_diag_const_iterator stored_diag_end() const {
return StoredDiagnostics.end();
}
stored_diag_iterator stored_diag_end() {
return StoredDiagnostics.end();
}
unsigned stored_diag_size() const { return StoredDiagnostics.size(); }
SmallVector<StoredDiagnostic, 4> &getStoredDiagnostics() {
return StoredDiagnostics;
stored_diag_iterator stored_diag_afterDriver_begin() {
if (NumStoredDiagnosticsFromDriver > StoredDiagnostics.size())
NumStoredDiagnosticsFromDriver = 0;
return StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver;
}
typedef std::vector<CachedCodeCompletionResult>::iterator

View File

@ -919,9 +919,7 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {
CleanTemporaryFiles();
if (!OverrideMainBuffer) {
StoredDiagnostics.erase(
StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver,
StoredDiagnostics.end());
StoredDiagnostics.erase(stored_diag_afterDriver_begin(), stored_diag_end());
TopLevelDeclsInPreamble.clear();
}
@ -1002,6 +1000,7 @@ error:
}
StoredDiagnostics.clear();
NumStoredDiagnosticsFromDriver = 0;
return true;
}
@ -1393,9 +1392,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
// Clear out old caches and data.
getDiagnostics().Reset();
ProcessWarningOptions(getDiagnostics(), Clang->getDiagnosticOpts());
StoredDiagnostics.erase(
StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver,
StoredDiagnostics.end());
StoredDiagnostics.erase(stored_diag_afterDriver_begin(), stored_diag_end());
TopLevelDecls.clear();
TopLevelDeclsInPreamble.clear();
@ -1438,11 +1435,8 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
// of preamble diagnostics.
PreambleDiagnostics.clear();
PreambleDiagnostics.insert(PreambleDiagnostics.end(),
StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver,
StoredDiagnostics.end());
StoredDiagnostics.erase(
StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver,
StoredDiagnostics.end());
stored_diag_afterDriver_begin(), stored_diag_end());
StoredDiagnostics.erase(stored_diag_afterDriver_begin(), stored_diag_end());
// Keep track of the preamble we precompiled.
PreambleFile = FrontendOpts.OutputFile;
@ -2196,8 +2190,8 @@ void ASTUnit::CodeComplete(StringRef File, unsigned Line, unsigned Column,
// make that override happen and introduce the preamble.
PreprocessorOpts.DisableStatCache = true;
StoredDiagnostics.insert(StoredDiagnostics.end(),
this->StoredDiagnostics.begin(),
this->StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver);
stored_diag_begin(),
stored_diag_afterDriver_begin());
if (OverrideMainBuffer) {
PreprocessorOpts.addRemappedFile(OriginalSourceFile, OverrideMainBuffer);
PreprocessorOpts.PrecompiledPreambleBytes.first = Preamble.size();