r203534 - If a visibility update record is found for a DeclContext after that Decl has
Richard Smith
richard-llvm at metafoo.co.uk
Mon Mar 10 20:10:46 PDT 2014
Author: rsmith
Date: Mon Mar 10 22:10:46 2014
New Revision: 203534
URL: http://llvm.org/viewvc/llvm-project?rev=203534&view=rev
Log:
If a visibility update record is found for a DeclContext after that Decl has
already been loaded, apply that update record to the Decl immediately, rather
than adding it to a pending list and never applying it.
Added:
cfe/trunk/test/Modules/Inputs/update-after-load/
cfe/trunk/test/Modules/Inputs/update-after-load/a.h
cfe/trunk/test/Modules/Inputs/update-after-load/b.h
cfe/trunk/test/Modules/Inputs/update-after-load/module.map
cfe/trunk/test/Modules/Inputs/update-after-load/modules.timestamp
cfe/trunk/test/Modules/update-after-load.cpp
Modified:
cfe/trunk/include/clang/Serialization/Module.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/Module.cpp
Modified: cfe/trunk/include/clang/Serialization/Module.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/Module.h?rev=203534&r1=203533&r2=203534&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/Module.h (original)
+++ cfe/trunk/include/clang/Serialization/Module.h Mon Mar 10 22:10:46 2014
@@ -44,13 +44,21 @@ enum ModuleKind {
MK_MainFile ///< File is a PCH file treated as the actual main file.
};
+/// A custom deleter for DeclContextInfo::NameLookupTableData, to allow
+/// an incomplete type to be used there.
+struct NameLookupTableDataDeleter {
+ void operator()(
+ OnDiskChainedHashTable<reader::ASTDeclContextNameLookupTrait> *Ptr) const;
+};
+
/// \brief Information about the contents of a DeclContext.
struct DeclContextInfo {
DeclContextInfo()
- : NameLookupTableData(), LexicalDecls(), NumLexicalDecls() {}
+ : NameLookupTableData(), LexicalDecls(), NumLexicalDecls() {}
- OnDiskChainedHashTable<reader::ASTDeclContextNameLookupTrait>
- *NameLookupTableData; // an ASTDeclContextNameLookupTable.
+ /// An ASTDeclContextNameLookupTable.
+ std::unique_ptr<OnDiskChainedHashTable<reader::ASTDeclContextNameLookupTrait>,
+ NameLookupTableDataDeleter> NameLookupTableData;
const KindDeclIDPair *LexicalDecls;
unsigned NumLexicalDecls;
};
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=203534&r1=203533&r2=203534&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon Mar 10 22:10:46 2014
@@ -457,6 +457,11 @@ ASTReader::setDeserializationListener(AS
}
+void NameLookupTableDataDeleter::
+operator()(ASTDeclContextNameLookupTable *Ptr) const {
+ delete Ptr;
+}
+
unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) {
return serialization::ComputeHash(Sel);
@@ -836,11 +841,10 @@ bool ASTReader::ReadDeclContextStorage(M
Error("Expected visible lookup table block");
return true;
}
- Info.NameLookupTableData
- = ASTDeclContextNameLookupTable::Create(
- (const unsigned char *)Blob.data() + Record[0],
- (const unsigned char *)Blob.data(),
- ASTDeclContextNameLookupTrait(*this, M));
+ Info.NameLookupTableData.reset(ASTDeclContextNameLookupTable::Create(
+ (const unsigned char *)Blob.data() + Record[0],
+ (const unsigned char *)Blob.data(),
+ ASTDeclContextNameLookupTrait(*this, M)));
}
return false;
@@ -2493,8 +2497,12 @@ bool ASTReader::ReadASTBlock(ModuleFile
ASTDeclContextNameLookupTrait(*this, F));
if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU?
DeclContext *TU = Context.getTranslationUnitDecl();
- F.DeclContextInfos[TU].NameLookupTableData = Table;
+ F.DeclContextInfos[TU].NameLookupTableData.reset(Table);
TU->setHasExternalVisibleStorage(true);
+ } else if (Decl *D = DeclsLoaded[ID - NUM_PREDEF_DECL_IDS]) {
+ auto *DC = cast<DeclContext>(D);
+ DC->getPrimaryContext()->setHasExternalVisibleStorage(true);
+ F.DeclContextInfos[DC].NameLookupTableData.reset(Table);
} else
PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F));
break;
@@ -6078,7 +6086,7 @@ namespace {
return false;
// Look for this name within this module.
- ASTDeclContextNameLookupTable *LookupTable =
+ const auto &LookupTable =
Info->second.NameLookupTableData;
ASTDeclContextNameLookupTable::iterator Pos
= LookupTable->find(This->Name);
@@ -6208,7 +6216,7 @@ namespace {
if (!FoundInfo)
return false;
- ASTDeclContextNameLookupTable *LookupTable =
+ const auto &LookupTable =
Info->second.NameLookupTableData;
bool FoundAnything = false;
for (ASTDeclContextNameLookupTable::data_iterator
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=203534&r1=203533&r2=203534&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon Mar 10 22:10:46 2014
@@ -2609,13 +2609,9 @@ Decl *ASTReader::ReadDeclRecord(DeclID I
// There are updates. This means the context has external visible
// storage, even if the original stored version didn't.
LookupDC->setHasExternalVisibleStorage(true);
- DeclContextVisibleUpdates &U = I->second;
- for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
- UI != UE; ++UI) {
- DeclContextInfo &Info = UI->second->DeclContextInfos[DC];
- delete Info.NameLookupTableData;
- Info.NameLookupTableData = UI->first;
- }
+ for (const auto &Update : I->second)
+ Update.second->DeclContextInfos[DC].NameLookupTableData.reset(
+ Update.first);
PendingVisibleUpdates.erase(I);
}
}
Modified: cfe/trunk/lib/Serialization/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/Module.cpp?rev=203534&r1=203533&r2=203534&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/Module.cpp (original)
+++ cfe/trunk/lib/Serialization/Module.cpp Mon Mar 10 22:10:46 2014
@@ -45,13 +45,6 @@ ModuleFile::ModuleFile(ModuleKind Kind,
{}
ModuleFile::~ModuleFile() {
- for (DeclContextInfosMap::iterator I = DeclContextInfos.begin(),
- E = DeclContextInfos.end();
- I != E; ++I) {
- if (I->second.NameLookupTableData)
- delete I->second.NameLookupTableData;
- }
-
delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
Added: cfe/trunk/test/Modules/Inputs/update-after-load/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/update-after-load/a.h?rev=203534&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/update-after-load/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/update-after-load/a.h Mon Mar 10 22:10:46 2014
@@ -0,0 +1 @@
+namespace llvm {}
Added: cfe/trunk/test/Modules/Inputs/update-after-load/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/update-after-load/b.h?rev=203534&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/update-after-load/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/update-after-load/b.h Mon Mar 10 22:10:46 2014
@@ -0,0 +1,2 @@
+#include "a.h"
+namespace llvm { void f(); }
Added: cfe/trunk/test/Modules/Inputs/update-after-load/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/update-after-load/module.map?rev=203534&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/update-after-load/module.map (added)
+++ cfe/trunk/test/Modules/Inputs/update-after-load/module.map Mon Mar 10 22:10:46 2014
@@ -0,0 +1 @@
+module a { header "a.h" } module b { header "b.h" }
Added: cfe/trunk/test/Modules/Inputs/update-after-load/modules.timestamp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/update-after-load/modules.timestamp?rev=203534&view=auto
==============================================================================
(empty)
Added: cfe/trunk/test/Modules/update-after-load.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/update-after-load.cpp?rev=203534&view=auto
==============================================================================
--- cfe/trunk/test/Modules/update-after-load.cpp (added)
+++ cfe/trunk/test/Modules/update-after-load.cpp Mon Mar 10 22:10:46 2014
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -I %S/Inputs/update-after-load -verify -fmodules-cache-path=%t %s
+
+// expected-no-diagnostics
+#include "a.h"
+namespace llvm {}
+#include "b.h"
+void llvm::f() {}
More information about the cfe-commits
mailing list