aboutsummaryrefslogtreecommitdiff
path: root/lib/Serialization/ASTReaderDecl.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-08-03 15:48:04 +0000
committerDouglas Gregor <dgregor@apple.com>2011-08-03 15:48:04 +0000
commit496c709a6f08f5c502b6f592ddd9ed40f953a5e5 (patch)
treef20c7be9a943f4c3cd2b4bdab6970891e77c46e4 /lib/Serialization/ASTReaderDecl.cpp
parentfc4b191b07df309d95aefae39f4cf7c456c91afa (diff)
Introduce the local -> global declaration ID mapping into the AST
reader, to allow AST files to be loaded with their declarations remapped to different ID numbers. Fix a number of places where we were either failing to map local declaration IDs into global declaration IDs or where interpreting the local declaration IDs within the wrong module. I've tested this via the usual "random gaps" method. It works well except for the preamble tests, because our handling of the precompiled preamble requires declaration and preprocessed entity to be stable when parsing code and then loading that back into memory. This property will hold in general, but my randomized testing naturally breaks this property to get more coverage. In the future, I expect that the precompiled preamble logic won't need this property. I am very unhappy with the current handling of the translation unit, which is a rather egregious hack. We're going to have to do something very different here for loading multiple AST files, because we don't want to have to cope with merging two translation units. Likely, we'll just handle translation units entirely via "update" records, and predefine a single, fixed declaration ID for the translation unit. That will come later. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136779 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTReaderDecl.cpp')
-rw-r--r--lib/Serialization/ASTReaderDecl.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp
index 546ca4dbe4..f9a99fc671 100644
--- a/lib/Serialization/ASTReaderDecl.cpp
+++ b/lib/Serialization/ASTReaderDecl.cpp
@@ -1398,7 +1398,7 @@ static bool isConsumerInterestedIn(Decl *D) {
/// \brief Get the correct cursor and offset for loading a declaration.
ASTReader::RecordLocation
-ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) {
+ASTReader::DeclCursorForID(DeclID ID) {
// See if there's an override.
DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
if (It != ReplacedDecls.end())
@@ -1407,7 +1407,7 @@ ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) {
GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Module *M = I->second;
- return RecordLocation(M, M->DeclOffsets[Index - M->BaseDeclID]);
+ return RecordLocation(M, M->DeclOffsets[ID - M->BaseDeclID - 1]);
}
ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
@@ -1438,8 +1438,9 @@ void ASTReader::loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID) {
}
/// \brief Read the declaration at the given offset from the AST file.
-Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
- RecordLocation Loc = DeclCursorForIndex(Index, ID);
+Decl *ASTReader::ReadDeclRecord(DeclID ID) {
+ unsigned Index = ID - 1;
+ RecordLocation Loc = DeclCursorForID(ID);
llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
// Keep track of where we are in the stream, then jump back there
// after reading this declaration.
@@ -1463,7 +1464,8 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
assert(false && "Record cannot be de-serialized with ReadDeclRecord");
break;
case DECL_TRANSLATION_UNIT:
- assert(Index == 0 && "Translation unit must be at index 0");
+ assert(Index == Loc.F->BaseDeclID &&
+ "Translation unit must be at first index in file");
D = Context->getTranslationUnitDecl();
break;
case DECL_TYPEDEF:
@@ -1707,12 +1709,12 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
DeclContextVisibleUpdates &U = I->second;
DeclContextInfos &Infos = DeclContextOffsets[DC];
DeclContextInfo Info;
- Info.F = Loc.F;
Info.LexicalDecls = 0;
Info.NumLexicalDecls = 0;
for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
UI != UE; ++UI) {
- Info.NameLookupTableData = *UI;
+ Info.NameLookupTableData = UI->first;
+ Info.F = UI->second;
Infos.push_back(Info);
}
PendingVisibleUpdates.erase(I);
@@ -1759,23 +1761,25 @@ void ASTDeclReader::UpdateDecl(Decl *D, Module &Module,
switch ((DeclUpdateKind)Record[Idx++]) {
case UPD_CXX_SET_DEFINITIONDATA: {
CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
- CXXRecordDecl *DefinitionDecl = ReadDeclAs<CXXRecordDecl>(Record, Idx);
+ CXXRecordDecl *DefinitionDecl
+ = Reader.ReadDeclAs<CXXRecordDecl>(Module, Record, Idx);
assert(!RD->DefinitionData && "DefinitionData is already set!");
InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx);
break;
}
case UPD_CXX_ADDED_IMPLICIT_MEMBER:
- cast<CXXRecordDecl>(D)->addedMember(ReadDecl(Record, Idx));
+ cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(Module, Record, Idx));
break;
case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
// It will be added to the template's specializations set when loaded.
- (void)ReadDecl(Record, Idx);
+ (void)Reader.ReadDecl(Module, Record, Idx);
break;
case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
- NamespaceDecl *Anon = ReadDeclAs<NamespaceDecl>(Record, Idx);
+ NamespaceDecl *Anon
+ = Reader.ReadDeclAs<NamespaceDecl>(Module, Record, Idx);
// Guard against these being loaded out of original order. Don't use
// getNextNamespace(), since it tries to access the context and can't in
// the middle of deserialization.