[cfe-commits] r142805 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Oct 24 10:25:20 PDT 2011
Author: akirtzidis
Date: Mon Oct 24 12:25:20 2011
New Revision: 142805
URL: http://llvm.org/viewvc/llvm-project?rev=142805&view=rev
Log:
[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.
Modified:
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=142805&r1=142804&r2=142805&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Mon Oct 24 12:25:20 2011
@@ -559,17 +559,26 @@
}
// 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
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=142805&r1=142804&r2=142805&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Oct 24 12:25:20 2011
@@ -919,9 +919,7 @@
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 @@
}
StoredDiagnostics.clear();
+ NumStoredDiagnosticsFromDriver = 0;
return true;
}
@@ -1393,9 +1392,7 @@
// 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 @@
// 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 @@
// 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();
More information about the cfe-commits
mailing list