aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/Sema.cpp10
-rw-r--r--lib/Serialization/ASTReader.cpp18
-rw-r--r--lib/Serialization/ASTWriter.cpp33
3 files changed, 33 insertions, 28 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index cb240cc031..b2f90613eb 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -438,7 +438,8 @@ void Sema::ActOnEndOfTranslationUnit() {
}
// Remove file scoped decls that turned out to be used.
- UnusedFileScopedDecls.erase(std::remove_if(UnusedFileScopedDecls.begin(),
+ UnusedFileScopedDecls.erase(std::remove_if(UnusedFileScopedDecls.begin(0,
+ true),
UnusedFileScopedDecls.end(),
std::bind1st(std::ptr_fun(ShouldRemoveFromUnused),
this)),
@@ -521,9 +522,12 @@ void Sema::ActOnEndOfTranslationUnit() {
// noise.
if (!Diags.hasErrorOccurred()) {
// Output warning for unused file scoped decls.
- for (SmallVectorImpl<const DeclaratorDecl*>::iterator
- I = UnusedFileScopedDecls.begin(),
+ for (UnusedFileScopedDeclsType::iterator
+ I = UnusedFileScopedDecls.begin(ExternalSource),
E = UnusedFileScopedDecls.end(); I != E; ++I) {
+ if (ShouldRemoveFromUnused(this, *I))
+ continue;
+
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) {
const FunctionDecl *DiagD;
if (!FD->hasBody(DiagD))
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index 9f8514f187..ba50454070 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -4328,13 +4328,6 @@ void ASTReader::InitializeSema(Sema &S) {
}
PreloadedDecls.clear();
- // If there were any unused file scoped decls, deserialize them and add to
- // Sema's list of unused file scoped decls.
- for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) {
- DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I]));
- SemaObj->UnusedFileScopedDecls.push_back(D);
- }
-
// If there were any delegating constructors, add them to Sema's list
for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) {
CXXConstructorDecl *D
@@ -4574,6 +4567,17 @@ void ASTReader::ReadTentativeDefinitions(
TentativeDefinitions.clear();
}
+void ASTReader::ReadUnusedFileScopedDecls(
+ SmallVectorImpl<const DeclaratorDecl *> &Decls) {
+ for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) {
+ DeclaratorDecl *D
+ = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I]));
+ if (D)
+ Decls.push_back(D);
+ }
+ UnusedFileScopedDecls.clear();
+}
+
void ASTReader::LoadSelector(Selector Sel) {
// It would be complicated to avoid reading the methods anyway. So don't.
ReadMethodPool(Sel);
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index 1acc140acd..d604da9c88 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -2777,6 +2777,15 @@ void ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls,
WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile);
}
+template<typename Vector>
+static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec,
+ ASTWriter::RecordData &Record) {
+ for (typename Vector::iterator I = Vec.begin(0, true), E = Vec.end();
+ I != E; ++I) {
+ Writer.AddDeclRef(*I, Record);
+ }
+}
+
void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
StringRef isysroot,
const std::string &OutputFile) {
@@ -2805,17 +2814,12 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
// TentativeDefinitions order. Generally, this record will be empty for
// headers.
RecordData TentativeDefinitions;
- for (Sema::TentativeDefinitionsType::iterator
- T = SemaRef.TentativeDefinitions.begin(0, true),
- TEnd = SemaRef.TentativeDefinitions.end();
- T != TEnd; ++T) {
- AddDeclRef(*T, TentativeDefinitions);
- }
+ AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions);
// Build a record containing all of the file scoped decls in this file.
RecordData UnusedFileScopedDecls;
- for (unsigned i=0, e = SemaRef.UnusedFileScopedDecls.size(); i !=e; ++i)
- AddDeclRef(SemaRef.UnusedFileScopedDecls[i], UnusedFileScopedDecls);
+ AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls,
+ UnusedFileScopedDecls);
RecordData DelegatingCtorDecls;
for (unsigned i=0, e = SemaRef.DelegatingCtorDecls.size(); i != e; ++i)
@@ -3075,19 +3079,12 @@ void ASTWriter::WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls,
// Build a record containing all of the new tentative definitions in this
// file, in TentativeDefinitions order.
RecordData TentativeDefinitions;
- for (Sema::TentativeDefinitionsType::iterator
- T = SemaRef.TentativeDefinitions.begin(0, true),
- TEnd = SemaRef.TentativeDefinitions.end();
- T != TEnd; ++T) {
- AddDeclRef(*T, TentativeDefinitions);
- }
+ AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions);
// Build a record containing all of the file scoped decls in this file.
RecordData UnusedFileScopedDecls;
- for (unsigned i=0, e = SemaRef.UnusedFileScopedDecls.size(); i !=e; ++i) {
- if (SemaRef.UnusedFileScopedDecls[i]->getPCHLevel() == 0)
- AddDeclRef(SemaRef.UnusedFileScopedDecls[i], UnusedFileScopedDecls);
- }
+ AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls,
+ UnusedFileScopedDecls);
// Build a record containing all of the delegating constructor decls in this
// file.