From 2d009f0655c2c5da9653bd358bd22f2fe8e66885 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Fri, 28 Mar 2014 20:32:17 +0000 Subject: [PATCH] Revert "OnDiskHashTable: Use Endian.h to read little endian ostreams" This reverts commit r205045. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205048 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/OnDiskHashTable.h | 61 ++++++++--- lib/Lex/PTHLexer.cpp | 86 ++++++--------- lib/Serialization/ASTReader.cpp | 132 ++++++++++-------------- lib/Serialization/GlobalModuleIndex.cpp | 14 +-- 4 files changed, 139 insertions(+), 154 deletions(-) diff --git a/include/clang/Basic/OnDiskHashTable.h b/include/clang/Basic/OnDiskHashTable.h index 1c398d5772..ee301237f9 100644 --- a/include/clang/Basic/OnDiskHashTable.h +++ b/include/clang/Basic/OnDiskHashTable.h @@ -70,6 +70,45 @@ inline void Pad(raw_ostream& Out, unsigned A) { Emit8(Out, 0); } +inline uint16_t ReadUnalignedLE16(const unsigned char *&Data) { + uint16_t V = ((uint16_t)Data[0]) | + ((uint16_t)Data[1] << 8); + Data += 2; + return V; +} + +inline uint32_t ReadUnalignedLE32(const unsigned char *&Data) { + uint32_t V = ((uint32_t)Data[0]) | + ((uint32_t)Data[1] << 8) | + ((uint32_t)Data[2] << 16) | + ((uint32_t)Data[3] << 24); + Data += 4; + return V; +} + +inline uint64_t ReadUnalignedLE64(const unsigned char *&Data) { + uint64_t V = ((uint64_t)Data[0]) | + ((uint64_t)Data[1] << 8) | + ((uint64_t)Data[2] << 16) | + ((uint64_t)Data[3] << 24) | + ((uint64_t)Data[4] << 32) | + ((uint64_t)Data[5] << 40) | + ((uint64_t)Data[6] << 48) | + ((uint64_t)Data[7] << 56); + Data += 8; + return V; +} + +inline uint32_t ReadLE32(const unsigned char *&Data) { + // Hosts that directly support little-endian 32-bit loads can just + // use them. Big-endian hosts need a bswap. + uint32_t V = *((const uint32_t*)Data); + if (llvm::sys::IsBigEndianHost) + V = llvm::ByteSwap_32(V); + Data += 4; + return V; +} + } // end namespace io template @@ -247,7 +286,7 @@ public: if (!InfoPtr) InfoPtr = &InfoObj; - using namespace llvm::support; + using namespace io; const internal_key_type& iKey = InfoObj.GetInternalKey(eKey); unsigned key_hash = InfoObj.ComputeHash(iKey); @@ -255,17 +294,17 @@ public: unsigned idx = key_hash & (NumBuckets - 1); const unsigned char* Bucket = Buckets + sizeof(uint32_t)*idx; - unsigned offset = endian::readNext(Bucket); + unsigned offset = ReadLE32(Bucket); if (offset == 0) return iterator(); // Empty bucket. const unsigned char* Items = Base + offset; // 'Items' starts with a 16-bit unsigned integer representing the // number of items in this bucket. - unsigned len = endian::readNext(Items); + unsigned len = ReadUnalignedLE16(Items); for (unsigned i = 0; i < len; ++i) { // Read the hash. - uint32_t item_hash = endian::readNext(Items); + uint32_t item_hash = ReadUnalignedLE32(Items); // Determine the length of the key and the data. const std::pair& L = Info::ReadKeyDataLength(Items); @@ -320,12 +359,10 @@ public: } key_iterator& operator++() { // Preincrement - using namespace llvm::support; if (!NumItemsInBucketLeft) { // 'Items' starts with a 16-bit unsigned integer representing the // number of items in this bucket. - NumItemsInBucketLeft = - endian::readNext(Ptr); + NumItemsInBucketLeft = io::ReadUnalignedLE16(Ptr); } Ptr += 4; // Skip the hash. // Determine the length of the key and the data. @@ -386,12 +423,10 @@ public: } data_iterator& operator++() { // Preincrement - using namespace llvm::support; if (!NumItemsInBucketLeft) { // 'Items' starts with a 16-bit unsigned integer representing the // number of items in this bucket. - NumItemsInBucketLeft = - endian::readNext(Ptr); + NumItemsInBucketLeft = io::ReadUnalignedLE16(Ptr); } Ptr += 4; // Skip the hash. // Determine the length of the key and the data. @@ -433,13 +468,13 @@ public: static OnDiskChainedHashTable* Create(const unsigned char* buckets, const unsigned char* const base, const Info &InfoObj = Info()) { - using namespace llvm::support; + using namespace io; assert(buckets > base); assert((reinterpret_cast(buckets) & 0x3) == 0 && "buckets should be 4-byte aligned."); - unsigned numBuckets = endian::readNext(buckets); - unsigned numEntries = endian::readNext(buckets); + unsigned numBuckets = ReadLE32(buckets); + unsigned numEntries = ReadLE32(buckets); return new OnDiskChainedHashTable(numBuckets, numEntries, buckets, base, InfoObj); } diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp index 0e2ceb3cd9..8c0865a539 100644 --- a/lib/Lex/PTHLexer.cpp +++ b/lib/Lex/PTHLexer.cpp @@ -47,17 +47,14 @@ bool PTHLexer::Lex(Token& Tok) { //===--------------------------------------==// // Read the raw token data. //===--------------------------------------==// - using namespace llvm::support; // Shadow CurPtr into an automatic variable. const unsigned char *CurPtrShadow = CurPtr; // Read in the data for the token. - unsigned Word0 = endian::readNext(CurPtrShadow); - uint32_t IdentifierID = - endian::readNext(CurPtrShadow); - uint32_t FileOffset = - endian::readNext(CurPtrShadow); + unsigned Word0 = ReadLE32(CurPtrShadow); + uint32_t IdentifierID = ReadLE32(CurPtrShadow); + uint32_t FileOffset = ReadLE32(CurPtrShadow); tok::TokenKind TKind = (tok::TokenKind) (Word0 & 0xFF); Token::TokenFlags TFlags = (Token::TokenFlags) ((Word0 >> 8) & 0xFF); @@ -187,7 +184,6 @@ void PTHLexer::DiscardToEndOfLine() { /// SkipBlock - Used by Preprocessor to skip the current conditional block. bool PTHLexer::SkipBlock() { - using namespace llvm::support; assert(CurPPCondPtr && "No cached PP conditional information."); assert(LastHashTokPtr && "No known '#' token."); @@ -196,10 +192,10 @@ bool PTHLexer::SkipBlock() { do { // Read the token offset from the side-table. - uint32_t Offset = endian::readNext(CurPPCondPtr); + uint32_t Offset = ReadLE32(CurPPCondPtr); // Read the target table index from the side-table. - TableIdx = endian::readNext(CurPPCondPtr); + TableIdx = ReadLE32(CurPPCondPtr); // Compute the actual memory address of the '#' token data for this entry. HashEntryI = TokBuf + Offset; @@ -216,13 +212,12 @@ bool PTHLexer::SkipBlock() { PPCond + TableIdx*(sizeof(uint32_t)*2); assert(NextPPCondPtr >= CurPPCondPtr); // Read where we should jump to. - const unsigned char *HashEntryJ = - TokBuf + endian::readNext(NextPPCondPtr); + const unsigned char* HashEntryJ = TokBuf + ReadLE32(NextPPCondPtr); if (HashEntryJ <= LastHashTokPtr) { // Jump directly to the next entry in the side table. HashEntryI = HashEntryJ; - TableIdx = endian::readNext(NextPPCondPtr); + TableIdx = ReadLE32(NextPPCondPtr); CurPPCondPtr = NextPPCondPtr; } } @@ -237,9 +232,8 @@ bool PTHLexer::SkipBlock() { CurPPCondPtr = NextPPCondPtr; // Read where we should jump to. - HashEntryI = - TokBuf + endian::readNext(NextPPCondPtr); - uint32_t NextIdx = endian::readNext(NextPPCondPtr); + HashEntryI = TokBuf + ReadLE32(NextPPCondPtr); + uint32_t NextIdx = ReadLE32(NextPPCondPtr); // By construction NextIdx will be zero if this is a #endif. This is useful // to know to obviate lexing another token. @@ -288,10 +282,8 @@ SourceLocation PTHLexer::getSourceLocation() { // handling a #included file. Just read the necessary data from the token // data buffer to construct the SourceLocation object. // NOTE: This is a virtual function; hence it is defined out-of-line. - using namespace llvm::support; - const unsigned char *OffsetPtr = CurPtr + (DISK_TOKEN_SIZE - 4); - uint32_t Offset = endian::readNext(OffsetPtr); + uint32_t Offset = ReadLE32(OffsetPtr); return FileStartLoc.getLocWithOffset(Offset); } @@ -325,9 +317,7 @@ public: static std::pair ReadKeyDataLength(const unsigned char*& d) { - using namespace llvm::support; - unsigned keyLen = - (unsigned)endian::readNext(d); + unsigned keyLen = (unsigned) ReadUnalignedLE16(d); unsigned dataLen = (unsigned) *(d++); return std::make_pair(keyLen, dataLen); } @@ -354,9 +344,8 @@ public: static PTHFileData ReadData(const internal_key_type& k, const unsigned char* d, unsigned) { assert(k.first == 0x1 && "Only file lookups can match!"); - using namespace llvm::support; - uint32_t x = endian::readNext(d); - uint32_t y = endian::readNext(d); + uint32_t x = ::ReadUnalignedLE32(d); + uint32_t y = ::ReadUnalignedLE32(d); return PTHFileData(x, y); } }; @@ -387,10 +376,7 @@ public: static std::pair ReadKeyDataLength(const unsigned char*& d) { - using namespace llvm::support; - return std::make_pair( - (unsigned)endian::readNext(d), - sizeof(uint32_t)); + return std::make_pair((unsigned) ReadUnalignedLE16(d), sizeof(uint32_t)); } static std::pair @@ -401,8 +387,7 @@ public: static uint32_t ReadData(const internal_key_type& k, const unsigned char* d, unsigned) { - using namespace llvm::support; - return endian::readNext(d); + return ::ReadUnalignedLE32(d); } }; @@ -448,8 +433,6 @@ PTHManager *PTHManager::Create(const std::string &file, return 0; } - using namespace llvm::support; - // Get the buffer ranges and check if there are at least three 32-bit // words at the end of the file. const unsigned char *BufBeg = (const unsigned char*)File->getBufferStart(); @@ -464,7 +447,7 @@ PTHManager *PTHManager::Create(const std::string &file, // Read the PTH version. const unsigned char *p = BufBeg + (sizeof("cfe-pth")); - unsigned Version = endian::readNext(p); + unsigned Version = ReadLE32(p); if (Version < PTHManager::Version) { InvalidPTH(Diags, @@ -485,8 +468,7 @@ PTHManager *PTHManager::Create(const std::string &file, // Construct the file lookup table. This will be used for mapping from // FileEntry*'s to cached tokens. const unsigned char* FileTableOffset = PrologueOffset + sizeof(uint32_t)*2; - const unsigned char *FileTable = - BufBeg + endian::readNext(FileTableOffset); + const unsigned char* FileTable = BufBeg + ReadLE32(FileTableOffset); if (!(FileTable > BufBeg && FileTable < BufEnd)) { Diags.Report(diag::err_invalid_pth_file) << file; @@ -503,8 +485,7 @@ PTHManager *PTHManager::Create(const std::string &file, // Get the location of the table mapping from persistent ids to the // data needed to reconstruct identifiers. const unsigned char* IDTableOffset = PrologueOffset + sizeof(uint32_t)*0; - const unsigned char *IData = - BufBeg + endian::readNext(IDTableOffset); + const unsigned char* IData = BufBeg + ReadLE32(IDTableOffset); if (!(IData >= BufBeg && IData < BufEnd)) { Diags.Report(diag::err_invalid_pth_file) << file; @@ -514,8 +495,7 @@ PTHManager *PTHManager::Create(const std::string &file, // Get the location of the hashtable mapping between strings and // persistent IDs. const unsigned char* StringIdTableOffset = PrologueOffset + sizeof(uint32_t)*1; - const unsigned char *StringIdTable = - BufBeg + endian::readNext(StringIdTableOffset); + const unsigned char* StringIdTable = BufBeg + ReadLE32(StringIdTableOffset); if (!(StringIdTable >= BufBeg && StringIdTable < BufEnd)) { Diags.Report(diag::err_invalid_pth_file) << file; return 0; @@ -526,15 +506,14 @@ PTHManager *PTHManager::Create(const std::string &file, // Get the location of the spelling cache. const unsigned char* spellingBaseOffset = PrologueOffset + sizeof(uint32_t)*3; - const unsigned char *spellingBase = - BufBeg + endian::readNext(spellingBaseOffset); + const unsigned char* spellingBase = BufBeg + ReadLE32(spellingBaseOffset); if (!(spellingBase >= BufBeg && spellingBase < BufEnd)) { Diags.Report(diag::err_invalid_pth_file) << file; return 0; } // Get the number of IdentifierInfos and pre-allocate the identifier cache. - uint32_t NumIds = endian::readNext(IData); + uint32_t NumIds = ReadLE32(IData); // Pre-allocate the persistent ID -> IdentifierInfo* cache. We use calloc() // so that we in the best case only zero out memory once when the OS returns @@ -551,8 +530,7 @@ PTHManager *PTHManager::Create(const std::string &file, // Compute the address of the original source file. const unsigned char* originalSourceBase = PrologueOffset + sizeof(uint32_t)*4; - unsigned len = - endian::readNext(originalSourceBase); + unsigned len = ReadUnalignedLE16(originalSourceBase); if (!len) originalSourceBase = 0; // Create the new PTHManager. @@ -562,12 +540,10 @@ PTHManager *PTHManager::Create(const std::string &file, } IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) { - using namespace llvm::support; // Look in the PTH file for the string data for the IdentifierInfo object. const unsigned char* TableEntry = IdDataTable + sizeof(uint32_t)*PersistentID; - const unsigned char *IDData = - (const unsigned char *)Buf->getBufferStart() + - endian::readNext(TableEntry); + const unsigned char* IDData = + (const unsigned char*)Buf->getBufferStart() + ReadLE32(TableEntry); assert(IDData < (const unsigned char*)Buf->getBufferEnd()); // Allocate the object. @@ -603,8 +579,6 @@ PTHLexer *PTHManager::CreateLexer(FileID FID) { if (!FE) return 0; - using namespace llvm::support; - // Lookup the FileEntry object in our file lookup data structure. It will // return a variant that indicates whether or not there is an offset within // the PTH file that contains cached tokens. @@ -622,7 +596,7 @@ PTHLexer *PTHManager::CreateLexer(FileID FID) { // Get the location of pp-conditional table. const unsigned char* ppcond = BufStart + FileData.getPPCondOffset(); - uint32_t Len = endian::readNext(ppcond); + uint32_t Len = ReadLE32(ppcond); if (Len == 0) ppcond = 0; assert(PP && "No preprocessor set yet!"); @@ -676,13 +650,11 @@ public: d += 4 * 2; // Skip the first 2 words. } - using namespace llvm::support; - - uint64_t File = endian::readNext(d); - uint64_t Device = endian::readNext(d); + uint64_t File = ReadUnalignedLE64(d); + uint64_t Device = ReadUnalignedLE64(d); llvm::sys::fs::UniqueID UniqueID(File, Device); - time_t ModTime = endian::readNext(d); - uint64_t Size = endian::readNext(d); + time_t ModTime = ReadUnalignedLE64(d); + uint64_t Size = ReadUnalignedLE64(d); return data_type(Size, ModTime, UniqueID, IsDirectory); } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index ff0b1dd629..2d3408c584 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -470,19 +470,19 @@ unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { std::pair ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { - using namespace llvm::support; - unsigned KeyLen = endian::readNext(d); - unsigned DataLen = endian::readNext(d); + using namespace clang::io; + unsigned KeyLen = ReadUnalignedLE16(d); + unsigned DataLen = ReadUnalignedLE16(d); return std::make_pair(KeyLen, DataLen); } ASTSelectorLookupTrait::internal_key_type ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { - using namespace llvm::support; + using namespace clang::io; SelectorTable &SelTable = Reader.getContext().Selectors; - unsigned N = endian::readNext(d); - IdentifierInfo *FirstII = Reader.getLocalIdentifier( - F, endian::readNext(d)); + unsigned N = ReadUnalignedLE16(d); + IdentifierInfo *FirstII + = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); if (N == 0) return SelTable.getNullarySelector(FirstII); else if (N == 1) @@ -491,8 +491,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { SmallVector Args; Args.push_back(FirstII); for (unsigned I = 1; I != N; ++I) - Args.push_back(Reader.getLocalIdentifier( - F, endian::readNext(d))); + Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d))); return SelTable.getSelector(N, Args.data()); } @@ -500,16 +499,13 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { ASTSelectorLookupTrait::data_type ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, unsigned DataLen) { - using namespace llvm::support; + using namespace clang::io; data_type Result; - Result.ID = Reader.getGlobalSelectorID( - F, endian::readNext(d)); - unsigned NumInstanceMethodsAndBits = - endian::readNext(d); - unsigned NumFactoryMethodsAndBits = - endian::readNext(d); + Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d)); + unsigned NumInstanceMethodsAndBits = ReadUnalignedLE16(d); + unsigned NumFactoryMethodsAndBits = ReadUnalignedLE16(d); Result.InstanceBits = NumInstanceMethodsAndBits & 0x3; Result.FactoryBits = NumFactoryMethodsAndBits & 0x3; unsigned NumInstanceMethods = NumInstanceMethodsAndBits >> 2; @@ -517,15 +513,15 @@ ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, // Load instance methods for (unsigned I = 0; I != NumInstanceMethods; ++I) { - if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs( - F, endian::readNext(d))) + if (ObjCMethodDecl *Method + = Reader.GetLocalDeclAs(F, ReadUnalignedLE32(d))) Result.Instance.push_back(Method); } // Load factory methods for (unsigned I = 0; I != NumFactoryMethods; ++I) { - if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs( - F, endian::readNext(d))) + if (ObjCMethodDecl *Method + = Reader.GetLocalDeclAs(F, ReadUnalignedLE32(d))) Result.Factory.push_back(Method); } @@ -538,9 +534,9 @@ unsigned ASTIdentifierLookupTraitBase::ComputeHash(const internal_key_type& a) { std::pair ASTIdentifierLookupTraitBase::ReadKeyDataLength(const unsigned char*& d) { - using namespace llvm::support; - unsigned DataLen = endian::readNext(d); - unsigned KeyLen = endian::readNext(d); + using namespace clang::io; + unsigned DataLen = ReadUnalignedLE16(d); + unsigned KeyLen = ReadUnalignedLE16(d); return std::make_pair(KeyLen, DataLen); } @@ -563,8 +559,8 @@ static bool isInterestingIdentifier(IdentifierInfo &II) { IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, const unsigned char* d, unsigned DataLen) { - using namespace llvm::support; - unsigned RawID = endian::readNext(d); + using namespace clang::io; + unsigned RawID = ReadUnalignedLE32(d); bool IsInteresting = RawID & 0x01; // Wipe out the "is interesting" bit. @@ -590,8 +586,8 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, return II; } - unsigned ObjCOrBuiltinID = endian::readNext(d); - unsigned Bits = endian::readNext(d); + unsigned ObjCOrBuiltinID = ReadUnalignedLE16(d); + unsigned Bits = ReadUnalignedLE16(d); bool CPlusPlusOperatorKeyword = Bits & 0x01; Bits >>= 1; bool HasRevertedTokenIDToIdentifier = Bits & 0x01; @@ -640,13 +636,11 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, // If this identifier is a macro, deserialize the macro // definition. if (hadMacroDefinition) { - uint32_t MacroDirectivesOffset = - endian::readNext(d); + uint32_t MacroDirectivesOffset = ReadUnalignedLE32(d); DataLen -= 4; SmallVector LocalMacroIDs; if (hasSubmoduleMacros) { - while (uint32_t LocalMacroID = - endian::readNext(d)) { + while (uint32_t LocalMacroID = ReadUnalignedLE32(d)) { DataLen -= 4; LocalMacroIDs.push_back(LocalMacroID); } @@ -694,8 +688,7 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, if (DataLen > 0) { SmallVector DeclIDs; for (; DataLen > 0; DataLen -= 4) - DeclIDs.push_back(Reader.getGlobalDeclID( - F, endian::readNext(d))); + DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); Reader.SetGloballyVisibleDecls(II, DeclIDs); } @@ -763,37 +756,34 @@ ASTDeclContextNameLookupTrait::GetInternalKey( std::pair ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) { - using namespace llvm::support; - unsigned KeyLen = endian::readNext(d); - unsigned DataLen = endian::readNext(d); + using namespace clang::io; + unsigned KeyLen = ReadUnalignedLE16(d); + unsigned DataLen = ReadUnalignedLE16(d); return std::make_pair(KeyLen, DataLen); } ASTDeclContextNameLookupTrait::internal_key_type ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) { - using namespace llvm::support; + using namespace clang::io; DeclNameKey Key; Key.Kind = (DeclarationName::NameKind)*d++; switch (Key.Kind) { case DeclarationName::Identifier: - Key.Data = (uint64_t)Reader.getLocalIdentifier( - F, endian::readNext(d)); + Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); break; case DeclarationName::ObjCZeroArgSelector: case DeclarationName::ObjCOneArgSelector: case DeclarationName::ObjCMultiArgSelector: Key.Data = - (uint64_t)Reader.getLocalSelector( - F, endian::readNext( - d)).getAsOpaquePtr(); + (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) + .getAsOpaquePtr(); break; case DeclarationName::CXXOperatorName: Key.Data = *d++; // OverloadedOperatorKind break; case DeclarationName::CXXLiteralOperatorName: - Key.Data = (uint64_t)Reader.getLocalIdentifier( - F, endian::readNext(d)); + Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); break; case DeclarationName::CXXConstructorName: case DeclarationName::CXXDestructorName: @@ -810,8 +800,8 @@ ASTDeclContextNameLookupTrait::data_type ASTDeclContextNameLookupTrait::ReadData(internal_key_type, const unsigned char* d, unsigned DataLen) { - using namespace llvm::support; - unsigned NumDecls = endian::readNext(d); + using namespace clang::io; + unsigned NumDecls = ReadUnalignedLE16(d); LE32DeclID *Start = reinterpret_cast( const_cast(d)); return std::make_pair(Start, Start + NumDecls); @@ -1364,18 +1354,16 @@ bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) { std::pair HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { - using namespace llvm::support; - unsigned KeyLen = (unsigned) endian::readNext(d); + unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); unsigned DataLen = (unsigned) *d++; return std::make_pair(KeyLen, DataLen); } HeaderFileInfoTrait::internal_key_type HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) { - using namespace llvm::support; internal_key_type ikey; - ikey.Size = off_t(endian::readNext(d)); - ikey.ModTime = time_t(endian::readNext(d)); + ikey.Size = off_t(clang::io::ReadUnalignedLE64(d)); + ikey.ModTime = time_t(clang::io::ReadUnalignedLE64(d)); ikey.Filename = (const char *)d; return ikey; } @@ -1384,7 +1372,7 @@ HeaderFileInfoTrait::data_type HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, unsigned DataLen) { const unsigned char *End = d + DataLen; - using namespace llvm::support; + using namespace clang::io; HeaderFileInfo HFI; unsigned Flags = *d++; HFI.HeaderRole = static_cast @@ -1394,11 +1382,10 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, HFI.DirInfo = (Flags >> 2) & 0x03; HFI.Resolved = (Flags >> 1) & 0x01; HFI.IndexHeaderMapHeader = Flags & 0x01; - HFI.NumIncludes = endian::readNext(d); - HFI.ControllingMacroID = Reader.getGlobalIdentifierID( - M, endian::readNext(d)); - if (unsigned FrameworkOffset = - endian::readNext(d)) { + HFI.NumIncludes = ReadUnalignedLE16(d); + HFI.ControllingMacroID = Reader.getGlobalIdentifierID(M, + ReadUnalignedLE32(d)); + if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { // The framework offset is 1 greater than the actual offset, // since 0 is used as an indicator for "no framework name". StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); @@ -1406,7 +1393,7 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, } if (d != End) { - uint32_t LocalSMID = endian::readNext(d); + uint32_t LocalSMID = ReadUnalignedLE32(d); if (LocalSMID) { // This header is part of a module. Associate it with the module to enable // implicit module import. @@ -2750,8 +2737,7 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) { ContinuousRangeMap::Builder TypeRemap(F.TypeRemap); while(Data < DataEnd) { - using namespace llvm::support; - uint16_t Len = endian::readNext(Data); + uint16_t Len = io::ReadUnalignedLE16(Data); StringRef Name = StringRef((const char*)Data, Len); Data += Len; ModuleFile *OM = ModuleMgr.lookup(Name); @@ -2760,23 +2746,15 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) { return true; } - uint32_t SLocOffset = - endian::readNext(Data); - uint32_t IdentifierIDOffset = - endian::readNext(Data); - uint32_t MacroIDOffset = - endian::readNext(Data); - uint32_t PreprocessedEntityIDOffset = - endian::readNext(Data); - uint32_t SubmoduleIDOffset = - endian::readNext(Data); - uint32_t SelectorIDOffset = - endian::readNext(Data); - uint32_t DeclIDOffset = - endian::readNext(Data); - uint32_t TypeIndexOffset = - endian::readNext(Data); - + uint32_t SLocOffset = io::ReadUnalignedLE32(Data); + uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); + uint32_t MacroIDOffset = io::ReadUnalignedLE32(Data); + uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); + uint32_t SubmoduleIDOffset = io::ReadUnalignedLE32(Data); + uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); + uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); + uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); + // Source location offset is mapped to OM->SLocEntryBaseOffset. SLocRemap.insert(std::make_pair(SLocOffset, static_cast(OM->SLocEntryBaseOffset - SLocOffset))); diff --git a/lib/Serialization/GlobalModuleIndex.cpp b/lib/Serialization/GlobalModuleIndex.cpp index ada02efc3f..b9e6130bad 100644 --- a/lib/Serialization/GlobalModuleIndex.cpp +++ b/lib/Serialization/GlobalModuleIndex.cpp @@ -82,9 +82,9 @@ public: static std::pair ReadKeyDataLength(const unsigned char*& d) { - using namespace llvm::support; - unsigned KeyLen = endian::readNext(d); - unsigned DataLen = endian::readNext(d); + using namespace clang::io; + unsigned KeyLen = ReadUnalignedLE16(d); + unsigned DataLen = ReadUnalignedLE16(d); return std::make_pair(KeyLen, DataLen); } @@ -101,11 +101,11 @@ public: static data_type ReadData(const internal_key_type& k, const unsigned char* d, unsigned DataLen) { - using namespace llvm::support; + using namespace clang::io; data_type Result; while (DataLen > 0) { - unsigned ID = endian::readNext(d); + unsigned ID = ReadUnalignedLE32(d); Result.push_back(ID); DataLen -= 4; } @@ -459,8 +459,8 @@ namespace { unsigned DataLen) { // The first bit indicates whether this identifier is interesting. // That's all we care about. - using namespace llvm::support; - unsigned RawID = endian::readNext(d); + using namespace clang::io; + unsigned RawID = ReadUnalignedLE32(d); bool IsInteresting = RawID & 0x01; return std::make_pair(k, IsInteresting); } -- 2.40.0