diff options
author | Ben Langmuir <blangmuir@apple.com> | 2014-10-20 16:27:30 +0000 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2014-10-20 16:27:30 +0000 |
commit | 785180e7ec441149bc31a922a795d79d6373dd03 (patch) | |
tree | 1907e5edfff15a7440679329ef77878a11f2b3ce /clang/lib/Serialization/ASTWriter.cpp | |
parent | c47baed0b5d906db899419f0d328daeba966ee07 (diff) | |
download | bcm5719-llvm-785180e7ec441149bc31a922a795d79d6373dd03.tar.gz bcm5719-llvm-785180e7ec441149bc31a922a795d79d6373dd03.zip |
Don't add ID mappings for offsets with no entities in a module
This is a better fix for 'duplicate key' problems in module continuous
range maps (vs what I added in r215810) by not adding any mappings at
all when there are no local entities. Now it also covers selectors,
which were not always being bumped because the record SELECTOR_OFFSET is
not always emitted. I'll back out most of r215810 in a future commit,
since it should no longer be needed.
llvm-svn: 220207
Diffstat (limited to 'clang/lib/Serialization/ASTWriter.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 5f8f5961be3..474ea279e3e 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -4455,25 +4455,36 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, SmallString<2048> Buffer; { llvm::raw_svector_ostream Out(Buffer); - for (ModuleManager::ModuleConstIterator M = Chain->ModuleMgr.begin(), - MEnd = Chain->ModuleMgr.end(); - M != MEnd; ++M) { + for (ModuleFile *M : Chain->ModuleMgr) { using namespace llvm::support; endian::Writer<little> LE(Out); - StringRef FileName = (*M)->FileName; + StringRef FileName = M->FileName; LE.write<uint16_t>(FileName.size()); Out.write(FileName.data(), FileName.size()); + // Note: if a base ID was uint max, it would not be possible to load + // another module after it or have more than one entity inside it. + uint32_t None = std::numeric_limits<uint32_t>::max(); + + auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { + assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); + if (ShouldWrite) + LE.write<uint32_t>(BaseID); + else + LE.write<uint32_t>(None); + }; + // These values should be unique within a chain, since they will be read // as keys into ContinuousRangeMaps. - LE.write<uint32_t>((*M)->SLocEntryBaseOffset); - LE.write<uint32_t>((*M)->BaseIdentifierID); - LE.write<uint32_t>((*M)->BaseMacroID); - LE.write<uint32_t>((*M)->BasePreprocessedEntityID); - LE.write<uint32_t>((*M)->BaseSubmoduleID); - LE.write<uint32_t>((*M)->BaseSelectorID); - LE.write<uint32_t>((*M)->BaseDeclID); - LE.write<uint32_t>((*M)->BaseTypeIndex); + writeBaseIDOrNone(M->SLocEntryBaseOffset, M->LocalNumSLocEntries); + writeBaseIDOrNone(M->BaseIdentifierID, M->LocalNumIdentifiers); + writeBaseIDOrNone(M->BaseMacroID, M->LocalNumMacros); + writeBaseIDOrNone(M->BasePreprocessedEntityID, + M->NumPreprocessedEntities); + writeBaseIDOrNone(M->BaseSubmoduleID, M->LocalNumSubmodules); + writeBaseIDOrNone(M->BaseSelectorID, M->LocalNumSelectors); + writeBaseIDOrNone(M->BaseDeclID, M->LocalNumDecls); + writeBaseIDOrNone(M->BaseTypeIndex, M->LocalNumTypes); } } Record.clear(); |