diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp | 2 | ||||
-rw-r--r-- | clang/lib/AST/NestedNameSpecifier.cpp | 19 | ||||
-rw-r--r-- | clang/lib/Basic/SourceLocation.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 62 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Lex/Lexer.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Lex/ModuleMap.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Lex/PPCaching.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Lex/TokenLexer.cpp | 11 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 29 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 8 |
11 files changed, 80 insertions, 66 deletions
diff --git a/clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp b/clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp index 5d0cfb8..e9c21b8 100644 --- a/clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp +++ b/clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp @@ -52,7 +52,7 @@ static bool isEmptyARCMTMacroStatement(NullStmt *S, if (AfterMacroLoc == SemiLoc) return true; - int RelOffs = 0; + SourceLocation::IntTy RelOffs = 0; if (!SM.isInSameSLocAddrSpace(AfterMacroLoc, SemiLoc, &RelOffs)) return false; if (RelOffs < 0) diff --git a/clang/lib/AST/NestedNameSpecifier.cpp b/clang/lib/AST/NestedNameSpecifier.cpp index 3f8fb7a..21afdd1 100644 --- a/clang/lib/AST/NestedNameSpecifier.cpp +++ b/clang/lib/AST/NestedNameSpecifier.cpp @@ -356,7 +356,7 @@ NestedNameSpecifierLoc::getLocalDataLength(NestedNameSpecifier *Qualifier) { assert(Qualifier && "Expected a non-NULL qualifier"); // Location of the trailing '::'. - unsigned Length = sizeof(unsigned); + unsigned Length = sizeof(SourceLocation::UIntTy); switch (Qualifier->getKind()) { case NestedNameSpecifier::Global: @@ -368,7 +368,7 @@ NestedNameSpecifierLoc::getLocalDataLength(NestedNameSpecifier *Qualifier) { case NestedNameSpecifier::NamespaceAlias: case NestedNameSpecifier::Super: // The location of the identifier or namespace name. - Length += sizeof(unsigned); + Length += sizeof(SourceLocation::UIntTy); break; case NestedNameSpecifier::TypeSpecWithTemplate: @@ -393,8 +393,8 @@ NestedNameSpecifierLoc::getDataLength(NestedNameSpecifier *Qualifier) { /// Load a (possibly unaligned) source location from a given address /// and offset. static SourceLocation LoadSourceLocation(void *Data, unsigned Offset) { - unsigned Raw; - memcpy(&Raw, static_cast<char *>(Data) + Offset, sizeof(unsigned)); + SourceLocation::UIntTy Raw; + memcpy(&Raw, static_cast<char *>(Data) + Offset, sizeof(Raw)); return SourceLocation::getFromRawEncoding(Raw); } @@ -431,8 +431,9 @@ SourceRange NestedNameSpecifierLoc::getLocalSourceRange() const { case NestedNameSpecifier::Namespace: case NestedNameSpecifier::NamespaceAlias: case NestedNameSpecifier::Super: - return SourceRange(LoadSourceLocation(Data, Offset), - LoadSourceLocation(Data, Offset + sizeof(unsigned))); + return SourceRange( + LoadSourceLocation(Data, Offset), + LoadSourceLocation(Data, Offset + sizeof(SourceLocation::UIntTy))); case NestedNameSpecifier::TypeSpecWithTemplate: case NestedNameSpecifier::TypeSpec: { @@ -487,10 +488,10 @@ static void Append(char *Start, char *End, char *&Buffer, unsigned &BufferSize, /// Save a source location to the given buffer. static void SaveSourceLocation(SourceLocation Loc, char *&Buffer, unsigned &BufferSize, unsigned &BufferCapacity) { - unsigned Raw = Loc.getRawEncoding(); + SourceLocation::UIntTy Raw = Loc.getRawEncoding(); Append(reinterpret_cast<char *>(&Raw), - reinterpret_cast<char *>(&Raw) + sizeof(unsigned), - Buffer, BufferSize, BufferCapacity); + reinterpret_cast<char *>(&Raw) + sizeof(Raw), Buffer, BufferSize, + BufferCapacity); } /// Save a pointer to the given buffer. diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp index 6f64120..6986fcd 100644 --- a/clang/lib/Basic/SourceLocation.cpp +++ b/clang/lib/Basic/SourceLocation.cpp @@ -51,7 +51,7 @@ static_assert(std::is_trivially_destructible<SourceRange>::value, "used in unions"); unsigned SourceLocation::getHashValue() const { - return llvm::DenseMapInfo<unsigned>::getHashValue(ID); + return llvm::DenseMapInfo<UIntTy>::getHashValue(ID); } void llvm::FoldingSetTrait<SourceLocation>::Profile( diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 2c8036a..8cba379 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -450,9 +450,9 @@ const SrcMgr::SLocEntry &SourceManager::loadSLocEntry(unsigned Index, return LoadedSLocEntryTable[Index]; } -std::pair<int, unsigned> +std::pair<int, SourceLocation::UIntTy> SourceManager::AllocateLoadedSLocEntries(unsigned NumSLocEntries, - unsigned TotalSize) { + SourceLocation::UIntTy TotalSize) { assert(ExternalSLocEntries && "Don't have an external sloc source"); // Make sure we're not about to run out of source locations. if (CurrentLoadedOffset - TotalSize < NextLocalOffset) @@ -532,7 +532,8 @@ FileID SourceManager::getNextFileID(FileID FID) const { FileID SourceManager::createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, - int LoadedID, unsigned LoadedOffset) { + int LoadedID, + SourceLocation::UIntTy LoadedOffset) { return createFileID(SourceFile->getLastRef(), IncludePos, FileCharacter, LoadedID, LoadedOffset); } @@ -540,7 +541,8 @@ FileID SourceManager::createFileID(const FileEntry *SourceFile, FileID SourceManager::createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, - int LoadedID, unsigned LoadedOffset) { + int LoadedID, + SourceLocation::UIntTy LoadedOffset) { SrcMgr::ContentCache &IR = getOrCreateContentCache(SourceFile, isSystem(FileCharacter)); @@ -559,7 +561,8 @@ FileID SourceManager::createFileID(FileEntryRef SourceFile, /// MemoryBuffer, so only pass a MemoryBuffer to this once. FileID SourceManager::createFileID(std::unique_ptr<llvm::MemoryBuffer> Buffer, SrcMgr::CharacteristicKind FileCharacter, - int LoadedID, unsigned LoadedOffset, + int LoadedID, + SourceLocation::UIntTy LoadedOffset, SourceLocation IncludeLoc) { StringRef Name = Buffer->getBufferIdentifier(); return createFileIDImpl(createMemBufferContentCache(std::move(Buffer)), Name, @@ -572,7 +575,8 @@ FileID SourceManager::createFileID(std::unique_ptr<llvm::MemoryBuffer> Buffer, /// outlive the SourceManager. FileID SourceManager::createFileID(const llvm::MemoryBufferRef &Buffer, SrcMgr::CharacteristicKind FileCharacter, - int LoadedID, unsigned LoadedOffset, + int LoadedID, + SourceLocation::UIntTy LoadedOffset, SourceLocation IncludeLoc) { return createFileID(llvm::MemoryBuffer::getMemBuffer(Buffer), FileCharacter, LoadedID, LoadedOffset, IncludeLoc); @@ -594,7 +598,8 @@ SourceManager::getOrCreateFileID(const FileEntry *SourceFile, FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, - int LoadedID, unsigned LoadedOffset) { + int LoadedID, + SourceLocation::UIntTy LoadedOffset) { if (LoadedID < 0) { assert(LoadedID != -1 && "Loading sentinel FileID"); unsigned Index = unsigned(-LoadedID) - 2; @@ -633,14 +638,11 @@ SourceManager::createMacroArgExpansionLoc(SourceLocation SpellingLoc, return createExpansionLocImpl(Info, TokLength); } -SourceLocation -SourceManager::createExpansionLoc(SourceLocation SpellingLoc, - SourceLocation ExpansionLocStart, - SourceLocation ExpansionLocEnd, - unsigned TokLength, - bool ExpansionIsTokenRange, - int LoadedID, - unsigned LoadedOffset) { +SourceLocation SourceManager::createExpansionLoc( + SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, + SourceLocation ExpansionLocEnd, unsigned TokLength, + bool ExpansionIsTokenRange, int LoadedID, + SourceLocation::UIntTy LoadedOffset) { ExpansionInfo Info = ExpansionInfo::create( SpellingLoc, ExpansionLocStart, ExpansionLocEnd, ExpansionIsTokenRange); return createExpansionLocImpl(Info, TokLength, LoadedID, LoadedOffset); @@ -658,9 +660,8 @@ SourceLocation SourceManager::createTokenSplitLoc(SourceLocation Spelling, SourceLocation SourceManager::createExpansionLocImpl(const ExpansionInfo &Info, - unsigned TokLength, - int LoadedID, - unsigned LoadedOffset) { + unsigned TokLength, int LoadedID, + SourceLocation::UIntTy LoadedOffset) { if (LoadedID < 0) { assert(LoadedID != -1 && "Loading sentinel FileID"); unsigned Index = unsigned(-LoadedID) - 2; @@ -762,7 +763,7 @@ llvm::Optional<StringRef> SourceManager::getBufferDataOrNone(FileID FID) const { /// This is the cache-miss path of getFileID. Not as hot as that function, but /// still very important. It is responsible for finding the entry in the /// SLocEntry tables that contains the specified location. -FileID SourceManager::getFileIDSlow(unsigned SLocOffset) const { +FileID SourceManager::getFileIDSlow(SourceLocation::UIntTy SLocOffset) const { if (!SLocOffset) return FileID::get(0); @@ -777,7 +778,7 @@ FileID SourceManager::getFileIDSlow(unsigned SLocOffset) const { /// /// This function knows that the SourceLocation is in a local buffer, not a /// loaded one. -FileID SourceManager::getFileIDLocal(unsigned SLocOffset) const { +FileID SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const { assert(SLocOffset < NextLocalOffset && "Bad function choice"); // After the first and second level caches, I see two common sorts of @@ -828,7 +829,8 @@ FileID SourceManager::getFileIDLocal(unsigned SLocOffset) const { NumProbes = 0; while (true) { unsigned MiddleIndex = (GreaterIndex-LessIndex)/2+LessIndex; - unsigned MidOffset = getLocalSLocEntry(MiddleIndex).getOffset(); + SourceLocation::UIntTy MidOffset = + getLocalSLocEntry(MiddleIndex).getOffset(); ++NumProbes; @@ -859,7 +861,7 @@ FileID SourceManager::getFileIDLocal(unsigned SLocOffset) const { /// /// This function knows that the SourceLocation is in a loaded buffer, not a /// local one. -FileID SourceManager::getFileIDLoaded(unsigned SLocOffset) const { +FileID SourceManager::getFileIDLoaded(SourceLocation::UIntTy SLocOffset) const { // Sanity checking, otherwise a bug may lead to hanging in release build. if (SLocOffset < CurrentLoadedOffset) { assert(0 && "Invalid SLocOffset or bad function choice"); @@ -1619,7 +1621,7 @@ unsigned SourceManager::getFileIDSize(FileID FID) const { return 0; int ID = FID.ID; - unsigned NextOffset; + SourceLocation::UIntTy NextOffset; if ((ID > 0 && unsigned(ID+1) == local_sloc_entry_size())) NextOffset = getNextLocalOffset(); else if (ID+1 == -1) @@ -1827,8 +1829,8 @@ void SourceManager::associateFileChunkWithMacroArgExp( SourceLocation ExpansionLoc, unsigned ExpansionLength) const { if (!SpellLoc.isFileID()) { - unsigned SpellBeginOffs = SpellLoc.getOffset(); - unsigned SpellEndOffs = SpellBeginOffs + ExpansionLength; + SourceLocation::UIntTy SpellBeginOffs = SpellLoc.getOffset(); + SourceLocation::UIntTy SpellEndOffs = SpellBeginOffs + ExpansionLength; // The spelling range for this macro argument expansion can span multiple // consecutive FileID entries. Go through each entry contained in the @@ -1840,9 +1842,9 @@ void SourceManager::associateFileChunkWithMacroArgExp( std::tie(SpellFID, SpellRelativeOffs) = getDecomposedLoc(SpellLoc); while (true) { const SLocEntry &Entry = getSLocEntry(SpellFID); - unsigned SpellFIDBeginOffs = Entry.getOffset(); + SourceLocation::UIntTy SpellFIDBeginOffs = Entry.getOffset(); unsigned SpellFIDSize = getFileIDSize(SpellFID); - unsigned SpellFIDEndOffs = SpellFIDBeginOffs + SpellFIDSize; + SourceLocation::UIntTy SpellFIDEndOffs = SpellFIDBeginOffs + SpellFIDSize; const ExpansionInfo &Info = Entry.getExpansion(); if (Info.isMacroArgExpansion()) { unsigned CurrSpellLength; @@ -1934,7 +1936,7 @@ SourceManager::getMacroArgExpandedLocation(SourceLocation Loc) const { --I; - unsigned MacroArgBeginOffs = I->first; + SourceLocation::UIntTy MacroArgBeginOffs = I->first; SourceLocation MacroArgExpandedLoc = I->second; if (MacroArgExpandedLoc.isValid()) return MacroArgExpandedLoc.getLocWithOffset(Offset - MacroArgBeginOffs); @@ -2154,7 +2156,7 @@ LLVM_DUMP_METHOD void SourceManager::dump() const { llvm::raw_ostream &out = llvm::errs(); auto DumpSLocEntry = [&](int ID, const SrcMgr::SLocEntry &Entry, - llvm::Optional<unsigned> NextStart) { + llvm::Optional<SourceLocation::UIntTy> NextStart) { out << "SLocEntry <FileID " << ID << "> " << (Entry.isFile() ? "file" : "expansion") << " <SourceLocation " << Entry.getOffset() << ":"; if (NextStart) @@ -2194,7 +2196,7 @@ LLVM_DUMP_METHOD void SourceManager::dump() const { : LocalSLocEntryTable[ID + 1].getOffset()); } // Dump loaded SLocEntries. - llvm::Optional<unsigned> NextStart; + llvm::Optional<SourceLocation::UIntTy> NextStart; for (unsigned Index = 0; Index != LoadedSLocEntryTable.size(); ++Index) { int ID = -(int)Index - 2; if (SLocEntryLoaded[Index]) { diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index a9f7b09..7310b5c 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -12000,13 +12000,14 @@ Address CGOpenMPRuntime::getAddressOfLocalVariable(CodeGenFunction &CGF, // Cleanup action for allocate support. class OMPAllocateCleanupTy final : public EHScopeStack::Cleanup { llvm::FunctionCallee RTLFn; - unsigned LocEncoding; + SourceLocation::UIntTy LocEncoding; Address Addr; const Expr *Allocator; public: - OMPAllocateCleanupTy(llvm::FunctionCallee RTLFn, unsigned LocEncoding, - Address Addr, const Expr *Allocator) + OMPAllocateCleanupTy(llvm::FunctionCallee RTLFn, + SourceLocation::UIntTy LocEncoding, Address Addr, + const Expr *Allocator) : RTLFn(RTLFn), LocEncoding(LocEncoding), Addr(Addr), Allocator(Allocator) {} void Emit(CodeGenFunction &CGF, Flags /*flags*/) override { diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index ac0489e..3034af23 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -588,7 +588,7 @@ PreambleBounds Lexer::ComputePreamble(StringRef Buffer, // Create a lexer starting at the beginning of the file. Note that we use a // "fake" file source location at offset 1 so that the lexer will track our // position within the file. - const unsigned StartOffset = 1; + const SourceLocation::UIntTy StartOffset = 1; SourceLocation FileLoc = SourceLocation::getFromRawEncoding(StartOffset); Lexer TheLexer(FileLoc, LangOpts, Buffer.begin(), Buffer.begin(), Buffer.end()); diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 2c0038d..f9af7c2 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -1378,7 +1378,7 @@ namespace clang { RSquare } Kind; - unsigned Location; + SourceLocation::UIntTy Location; unsigned StringLength; union { // If Kind != IntegerLiteral. diff --git a/clang/lib/Lex/PPCaching.cpp b/clang/lib/Lex/PPCaching.cpp index 31548d24..e05e52b 100644 --- a/clang/lib/Lex/PPCaching.cpp +++ b/clang/lib/Lex/PPCaching.cpp @@ -145,7 +145,7 @@ bool Preprocessor::IsPreviousCachedToken(const Token &Tok) const { if (LastCachedTok.getKind() != Tok.getKind()) return false; - int RelOffset = 0; + SourceLocation::IntTy RelOffset = 0; if ((!getSourceManager().isInSameSLocAddrSpace( Tok.getLocation(), getLastCachedTokenLocation(), &RelOffset)) || RelOffset) diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp index da5681a..41e7f3f 100644 --- a/clang/lib/Lex/TokenLexer.cpp +++ b/clang/lib/Lex/TokenLexer.cpp @@ -971,7 +971,7 @@ TokenLexer::getExpansionLocForMacroDefLoc(SourceLocation loc) const { assert(SM.isInSLocAddrSpace(loc, MacroDefStart, MacroDefLength) && "Expected loc to come from the macro definition"); - unsigned relativeOffset = 0; + SourceLocation::UIntTy relativeOffset = 0; SM.isInSLocAddrSpace(loc, MacroDefStart, MacroDefLength, &relativeOffset); return MacroExpansionStart.getLocWithOffset(relativeOffset); } @@ -1010,7 +1010,7 @@ static void updateConsecutiveMacroArgTokens(SourceManager &SM, if (CurLoc.isFileID() != NextLoc.isFileID()) break; // Token from different kind of FileID. - int RelOffs; + SourceLocation::IntTy RelOffs; if (!SM.isInSameSLocAddrSpace(CurLoc, NextLoc, &RelOffs)) break; // Token from different local/loaded location. // Check that token is not before the previous token or more than 50 @@ -1027,10 +1027,11 @@ static void updateConsecutiveMacroArgTokens(SourceManager &SM, // For the consecutive tokens, find the length of the SLocEntry to contain // all of them. Token &LastConsecutiveTok = *(NextTok-1); - int LastRelOffs = 0; + SourceLocation::IntTy LastRelOffs = 0; SM.isInSameSLocAddrSpace(FirstLoc, LastConsecutiveTok.getLocation(), &LastRelOffs); - unsigned FullLength = LastRelOffs + LastConsecutiveTok.getLength(); + SourceLocation::UIntTy FullLength = + LastRelOffs + LastConsecutiveTok.getLength(); // Create a macro expansion SLocEntry that will "contain" all of the tokens. SourceLocation Expansion = @@ -1040,7 +1041,7 @@ static void updateConsecutiveMacroArgTokens(SourceManager &SM, // expanded location. for (; begin_tokens < NextTok; ++begin_tokens) { Token &Tok = *begin_tokens; - int RelOffs = 0; + SourceLocation::IntTy RelOffs = 0; SM.isInSameSLocAddrSpace(FirstLoc, Tok.getLocation(), &RelOffs); Tok.setLocation(Expansion.getLocWithOffset(RelOffs)); } diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index faf6f3d..83bade9 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1482,7 +1482,7 @@ bool ASTReader::ReadSLocEntry(int ID) { } BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; - unsigned BaseOffset = F->SLocEntryBaseOffset; + SourceLocation::UIntTy BaseOffset = F->SLocEntryBaseOffset; ++NumSLocEntriesRead; Expected<llvm::BitstreamEntry> MaybeEntry = SLocEntryCursor.advance(); @@ -3409,7 +3409,7 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { case SOURCE_LOCATION_OFFSETS: { F.SLocEntryOffsets = (const uint32_t *)Blob.data(); F.LocalNumSLocEntries = Record[0]; - unsigned SLocSpaceSize = Record[1]; + SourceLocation::UIntTy SLocSpaceSize = Record[1]; F.SLocEntryOffsetsBase = Record[2] + F.SourceManagerBlockStartOffset; std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, @@ -3427,7 +3427,7 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. - assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); + assert((F.SLocEntryBaseOffset & SourceLocation::MacroIDBit) == 0); GlobalSLocOffsetMap.insert( std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset - SLocSpaceSize,&F)); @@ -3436,8 +3436,8 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { // Invalid stays invalid. F.SLocRemap.insertOrReplace(std::make_pair(0U, 0)); // This module. Base was 2 when being compiled. - F.SLocRemap.insertOrReplace(std::make_pair(2U, - static_cast<int>(F.SLocEntryBaseOffset - 2))); + F.SLocRemap.insertOrReplace(std::make_pair( + 2U, static_cast<SourceLocation::IntTy>(F.SLocEntryBaseOffset - 2))); TotalNumSLocEntries += F.LocalNumSLocEntries; break; @@ -3838,8 +3838,11 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { } // Continuous range maps we may be updating in our module. + using SLocRemapBuilder = + ContinuousRangeMap<SourceLocation::UIntTy, SourceLocation::IntTy, + 2>::Builder; using RemapBuilder = ContinuousRangeMap<uint32_t, int, 2>::Builder; - RemapBuilder SLocRemap(F.SLocRemap); + SLocRemapBuilder SLocRemap(F.SLocRemap); RemapBuilder IdentifierRemap(F.IdentifierRemap); RemapBuilder MacroRemap(F.MacroRemap); RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap); @@ -3870,7 +3873,7 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { return; } - uint32_t SLocOffset = + SourceLocation::UIntTy SLocOffset = endian::readNext<uint32_t, little, unaligned>(Data); uint32_t IdentifierIDOffset = endian::readNext<uint32_t, little, unaligned>(Data); @@ -3887,15 +3890,21 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { uint32_t TypeIndexOffset = endian::readNext<uint32_t, little, unaligned>(Data); - uint32_t None = std::numeric_limits<uint32_t>::max(); - auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset, RemapBuilder &Remap) { + constexpr uint32_t None = std::numeric_limits<uint32_t>::max(); if (Offset != None) Remap.insert(std::make_pair(Offset, static_cast<int>(BaseOffset - Offset))); }; - mapOffset(SLocOffset, OM->SLocEntryBaseOffset, SLocRemap); + + constexpr SourceLocation::UIntTy SLocNone = + std::numeric_limits<SourceLocation::UIntTy>::max(); + if (SLocOffset != SLocNone) + SLocRemap.insert(std::make_pair( + SLocOffset, static_cast<SourceLocation::IntTy>( + OM->SLocEntryBaseOffset - SLocOffset))); + mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap); mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap); mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID, diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index ca169c0..66c207a 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2041,7 +2041,7 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, Record.push_back(Expansion.isExpansionTokenRange()); // Compute the token length for this macro expansion. - unsigned NextOffset = SourceMgr.getNextLocalOffset(); + SourceLocation::UIntTy NextOffset = SourceMgr.getNextLocalOffset(); if (I + 1 != N) NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); Record.push_back(NextOffset - SLoc->getOffset() - 1); @@ -4640,7 +4640,7 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, // 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) { + auto writeBaseIDOrNone = [&](auto BaseID, bool ShouldWrite) { assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); if (ShouldWrite) LE.write<uint32_t>(BaseID); @@ -5027,8 +5027,8 @@ void ASTWriter::AddAlignPackInfo(const Sema::AlignPackInfo &Info, } void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { - uint32_t Raw = Loc.getRawEncoding(); - Record.push_back((Raw << 1) | (Raw >> 31)); + SourceLocation::UIntTy Raw = Loc.getRawEncoding(); + Record.push_back((Raw << 1) | (Raw >> (8 * sizeof(Raw) - 1))); } void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { |