simon_tatham updated this revision to Diff 360099.
simon_tatham retitled this revision from "[clang] Introduce 
SourceLocation::[U]IntType typedefs." to "[clang] Introduce 
SourceLocation::[U]IntTy typedefs.".
simon_tatham added a comment.

Renamed types to [U]IntTy. This will affect some of the dependent patches too, 
but I agree that saving two characters is worthwhile – these names are long 
enough already :-)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105492/new/

https://reviews.llvm.org/D105492

Files:
  clang/include/clang/AST/DeclarationName.h
  clang/include/clang/Basic/SourceLocation.h
  clang/include/clang/Basic/SourceManager.h
  clang/include/clang/Lex/Token.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp
  clang/lib/AST/NestedNameSpecifier.cpp
  clang/lib/Basic/SourceLocation.cpp
  clang/lib/Basic/SourceManager.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Lex/PPCaching.cpp
  clang/lib/Lex/TokenLexer.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/tools/libclang/CIndex.cpp

Index: clang/tools/libclang/CIndex.cpp
===================================================================
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1983,7 +1983,8 @@
     return static_cast<const FieldDecl *>(data[0]);
   }
   SourceLocation getLoc() const {
-    return SourceLocation::getFromRawEncoding((unsigned)(uintptr_t)data[1]);
+    return SourceLocation::getFromRawEncoding(
+        (SourceLocation::UIntTy)(uintptr_t)data[1]);
   }
 };
 class EnqueueVisitor : public ConstStmtVisitor<EnqueueVisitor, void> {
Index: clang/lib/Serialization/ASTWriter.cpp
===================================================================
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2041,7 +2041,7 @@
       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 @@
         // 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::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) {
Index: clang/lib/Serialization/ASTReader.cpp
===================================================================
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -1482,7 +1482,7 @@
   }
 
   BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor;
-  unsigned BaseOffset = F->SLocEntryBaseOffset;
+  SourceLocation::UIntTy BaseOffset = F->SLocEntryBaseOffset;
 
   ++NumSLocEntriesRead;
   Expected<llvm::BitstreamEntry> MaybeEntry = SLocEntryCursor.advance();
@@ -3409,7 +3409,7 @@
     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 @@
       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 @@
       // 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 @@
   }
 
   // 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 @@
       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 @@
     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,
Index: clang/lib/Lex/TokenLexer.cpp
===================================================================
--- clang/lib/Lex/TokenLexer.cpp
+++ clang/lib/Lex/TokenLexer.cpp
@@ -971,7 +971,7 @@
   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 @@
     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 @@
   // 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 @@
   // 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));
   }
Index: clang/lib/Lex/PPCaching.cpp
===================================================================
--- clang/lib/Lex/PPCaching.cpp
+++ clang/lib/Lex/PPCaching.cpp
@@ -145,7 +145,7 @@
   if (LastCachedTok.getKind() != Tok.getKind())
     return false;
 
-  int RelOffset = 0;
+  SourceLocation::IntTy RelOffset = 0;
   if ((!getSourceManager().isInSameSLocAddrSpace(
           Tok.getLocation(), getLastCachedTokenLocation(), &RelOffset)) ||
       RelOffset)
Index: clang/lib/Lex/ModuleMap.cpp
===================================================================
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -1378,7 +1378,7 @@
       RSquare
     } Kind;
 
-    unsigned Location;
+    SourceLocation::UIntTy Location;
     unsigned StringLength;
     union {
       // If Kind != IntegerLiteral.
Index: clang/lib/Lex/Lexer.cpp
===================================================================
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -588,7 +588,7 @@
   // 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());
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -12000,13 +12000,14 @@
     // 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 {
Index: clang/lib/Basic/SourceManager.cpp
===================================================================
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -450,9 +450,9 @@
   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::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(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 @@
 /// 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 @@
 /// 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 @@
 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 @@
   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::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 @@
 /// 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 @@
 ///
 /// 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 @@
   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 @@
 ///
 /// 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 @@
     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 @@
                                          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 @@
     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 @@
 
   --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::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 @@
                                    : 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]) {
Index: clang/lib/Basic/SourceLocation.cpp
===================================================================
--- clang/lib/Basic/SourceLocation.cpp
+++ clang/lib/Basic/SourceLocation.cpp
@@ -51,7 +51,7 @@
               "used in unions");
 
 unsigned SourceLocation::getHashValue() const {
-  return llvm::DenseMapInfo<unsigned>::getHashValue(ID);
+  return llvm::DenseMapInfo<UIntTy>::getHashValue(ID);
 }
 
 void llvm::FoldingSetTrait<SourceLocation>::Profile(
Index: clang/lib/AST/NestedNameSpecifier.cpp
===================================================================
--- clang/lib/AST/NestedNameSpecifier.cpp
+++ clang/lib/AST/NestedNameSpecifier.cpp
@@ -356,7 +356,7 @@
   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 @@
   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 @@
 /// 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 @@
   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 @@
 /// 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.
Index: clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp
===================================================================
--- clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp
+++ clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp
@@ -52,7 +52,7 @@
   if (AfterMacroLoc == SemiLoc)
     return true;
 
-  int RelOffs = 0;
+  SourceLocation::IntTy RelOffs = 0;
   if (!SM.isInSameSLocAddrSpace(AfterMacroLoc, SemiLoc, &RelOffs))
     return false;
   if (RelOffs < 0)
Index: clang/include/clang/Serialization/ModuleFile.h
===================================================================
--- clang/include/clang/Serialization/ModuleFile.h
+++ clang/include/clang/Serialization/ModuleFile.h
@@ -260,7 +260,7 @@
   int SLocEntryBaseID = 0;
 
   /// The base offset in the source manager's view of this module.
-  unsigned SLocEntryBaseOffset = 0;
+  SourceLocation::UIntTy SLocEntryBaseOffset = 0;
 
   /// Base file offset for the offsets in SLocEntryOffsets. Real file offset
   /// for the entry is SLocEntryOffsetsBase + SLocEntryOffsets[i].
@@ -274,7 +274,8 @@
   SmallVector<uint64_t, 4> PreloadSLocEntries;
 
   /// Remapping table for source locations in this module.
-  ContinuousRangeMap<uint32_t, int, 2> SLocRemap;
+  ContinuousRangeMap<SourceLocation::UIntTy, SourceLocation::IntTy, 2>
+      SLocRemap;
 
   // === Identifiers ===
 
Index: clang/include/clang/Serialization/ASTWriter.h
===================================================================
--- clang/include/clang/Serialization/ASTWriter.h
+++ clang/include/clang/Serialization/ASTWriter.h
@@ -347,7 +347,7 @@
     union {
       const Decl *Dcl;
       void *Type;
-      unsigned Loc;
+      SourceLocation::UIntTy Loc;
       unsigned Val;
       Module *Mod;
       const Attr *Attribute;
Index: clang/include/clang/Serialization/ASTReader.h
===================================================================
--- clang/include/clang/Serialization/ASTReader.h
+++ clang/include/clang/Serialization/ASTReader.h
@@ -2139,12 +2139,15 @@
 
   /// Read a source location from raw form and return it in its
   /// originating module file's source location space.
-  SourceLocation ReadUntranslatedSourceLocation(uint32_t Raw) const {
-    return SourceLocation::getFromRawEncoding((Raw >> 1) | (Raw << 31));
+  SourceLocation
+  ReadUntranslatedSourceLocation(SourceLocation::UIntTy Raw) const {
+    return SourceLocation::getFromRawEncoding((Raw >> 1) |
+                                              (Raw << (8 * sizeof(Raw) - 1)));
   }
 
   /// Read a source location from raw form.
-  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const {
+  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
+                                    SourceLocation::UIntTy Raw) const {
     SourceLocation Loc = ReadUntranslatedSourceLocation(Raw);
     return TranslateSourceLocation(ModuleFile, Loc);
   }
@@ -2158,7 +2161,8 @@
     assert(ModuleFile.SLocRemap.find(Loc.getOffset()) !=
                ModuleFile.SLocRemap.end() &&
            "Cannot find offset to remap.");
-    int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
+    SourceLocation::IntTy Remap =
+        ModuleFile.SLocRemap.find(Loc.getOffset())->second;
     return Loc.getLocWithOffset(Remap);
   }
 
Index: clang/include/clang/Serialization/ASTBitCodes.h
===================================================================
--- clang/include/clang/Serialization/ASTBitCodes.h
+++ clang/include/clang/Serialization/ASTBitCodes.h
@@ -176,10 +176,10 @@
 /// Source range/offset of a preprocessed entity.
 struct PPEntityOffset {
   /// Raw source location of beginning of range.
-  unsigned Begin;
+  SourceLocation::UIntTy Begin;
 
   /// Raw source location of end of range.
-  unsigned End;
+  SourceLocation::UIntTy End;
 
   /// Offset in the AST file relative to ModuleFile::MacroOffsetsBase.
   uint32_t BitOffset;
@@ -200,9 +200,9 @@
 /// Source range of a skipped preprocessor region
 struct PPSkippedRange {
   /// Raw source location of beginning of range.
-  unsigned Begin;
+  SourceLocation::UIntTy Begin;
   /// Raw source location of end of range.
-  unsigned End;
+  SourceLocation::UIntTy End;
 
   PPSkippedRange(SourceRange R)
       : Begin(R.getBegin().getRawEncoding()), End(R.getEnd().getRawEncoding()) {
@@ -240,7 +240,7 @@
 /// Source location and bit offset of a declaration.
 struct DeclOffset {
   /// Raw source location.
-  unsigned Loc = 0;
+  SourceLocation::UIntTy Loc = 0;
 
   /// Offset relative to the start of the DECLTYPES_BLOCK block. Keep
   /// structure alignment 32-bit and avoid padding gap because undefined
Index: clang/include/clang/Lex/Token.h
===================================================================
--- clang/include/clang/Lex/Token.h
+++ clang/include/clang/Lex/Token.h
@@ -33,7 +33,7 @@
 /// information about the SourceRange of the tokens and the type object.
 class Token {
   /// The location of the token. This is actually a SourceLocation.
-  unsigned Loc;
+  SourceLocation::UIntTy Loc;
 
   // Conceptually these next two fields could be in a union.  However, this
   // causes gcc 4.2 to pessimize LexTokenInternal, a very performance critical
@@ -43,7 +43,7 @@
   /// UintData - This holds either the length of the token text, when
   /// a normal token, or the end of the SourceRange when an annotation
   /// token.
-  unsigned UintData;
+  SourceLocation::UIntTy UintData;
 
   /// PtrData - This is a union of four different pointer types, which depends
   /// on what type of token this is:
Index: clang/include/clang/Basic/SourceManager.h
===================================================================
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -465,8 +465,9 @@
 /// SourceManager keeps an array of these objects, and they are uniquely
 /// identified by the FileID datatype.
 class SLocEntry {
-  unsigned Offset : 31;
-  unsigned IsExpansion : 1;
+  static constexpr int OffsetBits = 8 * sizeof(SourceLocation::UIntTy) - 1;
+  SourceLocation::UIntTy Offset : OffsetBits;
+  SourceLocation::UIntTy IsExpansion : 1;
   union {
     FileInfo File;
     ExpansionInfo Expansion;
@@ -475,7 +476,7 @@
 public:
   SLocEntry() : Offset(), IsExpansion(), File() {}
 
-  unsigned getOffset() const { return Offset; }
+  SourceLocation::UIntTy getOffset() const { return Offset; }
 
   bool isExpansion() const { return IsExpansion; }
   bool isFile() const { return !isExpansion(); }
@@ -490,8 +491,8 @@
     return Expansion;
   }
 
-  static SLocEntry get(unsigned Offset, const FileInfo &FI) {
-    assert(!(Offset & (1u << 31)) && "Offset is too large");
+  static SLocEntry get(SourceLocation::UIntTy Offset, const FileInfo &FI) {
+    assert(!(Offset & (1ULL << OffsetBits)) && "Offset is too large");
     SLocEntry E;
     E.Offset = Offset;
     E.IsExpansion = false;
@@ -499,8 +500,9 @@
     return E;
   }
 
-  static SLocEntry get(unsigned Offset, const ExpansionInfo &Expansion) {
-    assert(!(Offset & (1u << 31)) && "Offset is too large");
+  static SLocEntry get(SourceLocation::UIntTy Offset,
+                       const ExpansionInfo &Expansion) {
+    assert(!(Offset & (1ULL << OffsetBits)) && "Offset is too large");
     SLocEntry E;
     E.Offset = Offset;
     E.IsExpansion = true;
@@ -690,17 +692,18 @@
   /// The starting offset of the next local SLocEntry.
   ///
   /// This is LocalSLocEntryTable.back().Offset + the size of that entry.
-  unsigned NextLocalOffset;
+  SourceLocation::UIntTy NextLocalOffset;
 
   /// The starting offset of the latest batch of loaded SLocEntries.
   ///
   /// This is LoadedSLocEntryTable.back().Offset, except that that entry might
   /// not have been loaded, so that value would be unknown.
-  unsigned CurrentLoadedOffset;
+  SourceLocation::UIntTy CurrentLoadedOffset;
 
-  /// The highest possible offset is 2^31-1, so CurrentLoadedOffset
-  /// starts at 2^31.
-  static const unsigned MaxLoadedOffset = 1U << 31U;
+  /// The highest possible offset is 2^32-1 (2^63-1 for 64-bit source
+  /// locations), so CurrentLoadedOffset starts at 2^31 (2^63 resp.).
+  static const SourceLocation::UIntTy MaxLoadedOffset =
+      1ULL << (8 * sizeof(SourceLocation::UIntTy) - 1);
 
   /// A bitmap that indicates whether the entries of LoadedSLocEntryTable
   /// have already been loaded from the external source.
@@ -865,11 +868,13 @@
   /// This translates NULL into standard input.
   FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos,
                       SrcMgr::CharacteristicKind FileCharacter,
-                      int LoadedID = 0, unsigned LoadedOffset = 0);
+                      int LoadedID = 0,
+                      SourceLocation::UIntTy LoadedOffset = 0);
 
   FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos,
                       SrcMgr::CharacteristicKind FileCharacter,
-                      int LoadedID = 0, unsigned LoadedOffset = 0);
+                      int LoadedID = 0,
+                      SourceLocation::UIntTy LoadedOffset = 0);
 
   /// Create a new FileID that represents the specified memory buffer.
   ///
@@ -877,7 +882,7 @@
   /// MemoryBuffer, so only pass a MemoryBuffer to this once.
   FileID createFileID(std::unique_ptr<llvm::MemoryBuffer> Buffer,
                       SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User,
-                      int LoadedID = 0, unsigned LoadedOffset = 0,
+                      int LoadedID = 0, SourceLocation::UIntTy LoadedOffset = 0,
                       SourceLocation IncludeLoc = SourceLocation());
 
   /// Create a new FileID that represents the specified memory buffer.
@@ -886,7 +891,7 @@
   /// outlive the SourceManager.
   FileID createFileID(const llvm::MemoryBufferRef &Buffer,
                       SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User,
-                      int LoadedID = 0, unsigned LoadedOffset = 0,
+                      int LoadedID = 0, SourceLocation::UIntTy LoadedOffset = 0,
                       SourceLocation IncludeLoc = SourceLocation());
 
   /// Get the FileID for \p SourceFile if it exists. Otherwise, create a
@@ -905,13 +910,11 @@
   /// Return a new SourceLocation that encodes the fact
   /// that a token from SpellingLoc should actually be referenced from
   /// ExpansionLoc.
-  SourceLocation createExpansionLoc(SourceLocation Loc,
-                                    SourceLocation ExpansionLocStart,
-                                    SourceLocation ExpansionLocEnd,
-                                    unsigned TokLength,
-                                    bool ExpansionIsTokenRange = true,
-                                    int LoadedID = 0,
-                                    unsigned LoadedOffset = 0);
+  SourceLocation
+  createExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLocStart,
+                     SourceLocation ExpansionLocEnd, unsigned TokLength,
+                     bool ExpansionIsTokenRange = true, int LoadedID = 0,
+                     SourceLocation::UIntTy LoadedOffset = 0);
 
   /// Return a new SourceLocation that encodes that the token starting
   /// at \p TokenStart ends prematurely at \p TokenEnd.
@@ -1098,7 +1101,7 @@
   /// the entry in SLocEntryTable which contains the specified location.
   ///
   FileID getFileID(SourceLocation SpellingLoc) const {
-    unsigned SLocOffset = SpellingLoc.getOffset();
+    SourceLocation::UIntTy SLocOffset = SpellingLoc.getOffset();
 
     // If our one-entry cache covers this offset, just return it.
     if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
@@ -1221,7 +1224,7 @@
     if (!Entry)
       return SourceLocation();
 
-    unsigned GlobalOffset = Entry->getOffset() + Offset;
+    SourceLocation::UIntTy GlobalOffset = Entry->getOffset() + Offset;
     return Entry->isFile() ? SourceLocation::getFileLoc(GlobalOffset)
                            : SourceLocation::getMacroLoc(GlobalOffset);
   }
@@ -1326,17 +1329,17 @@
   ///
   /// If it's true and \p RelativeOffset is non-null, it will be set to the
   /// relative offset of \p Loc inside the chunk.
-  bool isInSLocAddrSpace(SourceLocation Loc,
-                         SourceLocation Start, unsigned Length,
-                         unsigned *RelativeOffset = nullptr) const {
+  bool
+  isInSLocAddrSpace(SourceLocation Loc, SourceLocation Start, unsigned Length,
+                    SourceLocation::UIntTy *RelativeOffset = nullptr) const {
     assert(((Start.getOffset() < NextLocalOffset &&
                Start.getOffset()+Length <= NextLocalOffset) ||
             (Start.getOffset() >= CurrentLoadedOffset &&
                 Start.getOffset()+Length < MaxLoadedOffset)) &&
            "Chunk is not valid SLoc address space");
-    unsigned LocOffs = Loc.getOffset();
-    unsigned BeginOffs = Start.getOffset();
-    unsigned EndOffs = BeginOffs + Length;
+    SourceLocation::UIntTy LocOffs = Loc.getOffset();
+    SourceLocation::UIntTy BeginOffs = Start.getOffset();
+    SourceLocation::UIntTy EndOffs = BeginOffs + Length;
     if (LocOffs >= BeginOffs && LocOffs < EndOffs) {
       if (RelativeOffset)
         *RelativeOffset = LocOffs - BeginOffs;
@@ -1352,8 +1355,8 @@
   /// If it's true and \p RelativeOffset is non-null, it will be set to the
   /// offset of \p RHS relative to \p LHS.
   bool isInSameSLocAddrSpace(SourceLocation LHS, SourceLocation RHS,
-                             int *RelativeOffset) const {
-    unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset();
+                             SourceLocation::IntTy *RelativeOffset) const {
+    SourceLocation::UIntTy LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset();
     bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;
     bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;
 
@@ -1517,7 +1520,7 @@
   /// of FileID) to \p relativeOffset.
   bool isInFileID(SourceLocation Loc, FileID FID,
                   unsigned *RelativeOffset = nullptr) const {
-    unsigned Offs = Loc.getOffset();
+    SourceLocation::UIntTy Offs = Loc.getOffset();
     if (isOffsetInFileID(FID, Offs)) {
       if (RelativeOffset)
         *RelativeOffset = Offs - getSLocEntry(FID).getOffset();
@@ -1636,8 +1639,9 @@
   /// offset in the "source location address space".
   ///
   /// Note that we always consider source locations loaded from
-  bool isBeforeInSLocAddrSpace(SourceLocation LHS, unsigned RHS) const {
-    unsigned LHSOffset = LHS.getOffset();
+  bool isBeforeInSLocAddrSpace(SourceLocation LHS,
+                               SourceLocation::UIntTy RHS) const {
+    SourceLocation::UIntTy LHSOffset = LHS.getOffset();
     bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
     bool RHSLoaded = RHS >= CurrentLoadedOffset;
     if (LHSLoaded == RHSLoaded)
@@ -1699,7 +1703,7 @@
     return getSLocEntryByID(FID.ID, Invalid);
   }
 
-  unsigned getNextLocalOffset() const { return NextLocalOffset; }
+  SourceLocation::UIntTy getNextLocalOffset() const { return NextLocalOffset; }
 
   void setExternalSLocEntrySource(ExternalSLocEntrySource *Source) {
     assert(LoadedSLocEntryTable.empty() &&
@@ -1713,8 +1717,9 @@
   /// NumSLocEntries will be allocated, which occupy a total of TotalSize space
   /// in the global source view. The lowest ID and the base offset of the
   /// entries will be returned.
-  std::pair<int, unsigned>
-  AllocateLoadedSLocEntries(unsigned NumSLocEntries, unsigned TotalSize);
+  std::pair<int, SourceLocation::UIntTy>
+  AllocateLoadedSLocEntries(unsigned NumSLocEntries,
+                            SourceLocation::UIntTy TotalSize);
 
   /// Returns true if \p Loc came from a PCH/Module.
   bool isLoadedSourceLocation(SourceLocation Loc) const {
@@ -1795,14 +1800,15 @@
 
   /// Implements the common elements of storing an expansion info struct into
   /// the SLocEntry table and producing a source location that refers to it.
-  SourceLocation createExpansionLocImpl(const SrcMgr::ExpansionInfo &Expansion,
-                                        unsigned TokLength,
-                                        int LoadedID = 0,
-                                        unsigned LoadedOffset = 0);
+  SourceLocation
+  createExpansionLocImpl(const SrcMgr::ExpansionInfo &Expansion,
+                         unsigned TokLength, int LoadedID = 0,
+                         SourceLocation::UIntTy LoadedOffset = 0);
 
   /// Return true if the specified FileID contains the
   /// specified SourceLocation offset.  This is a very hot method.
-  inline bool isOffsetInFileID(FileID FID, unsigned SLocOffset) const {
+  inline bool isOffsetInFileID(FileID FID,
+                               SourceLocation::UIntTy SLocOffset) const {
     const SrcMgr::SLocEntry &Entry = getSLocEntry(FID);
     // If the entry is after the offset, it can't contain it.
     if (SLocOffset < Entry.getOffset()) return false;
@@ -1836,7 +1842,7 @@
   FileID createFileIDImpl(SrcMgr::ContentCache &File, StringRef Filename,
                           SourceLocation IncludePos,
                           SrcMgr::CharacteristicKind DirCharacter, int LoadedID,
-                          unsigned LoadedOffset);
+                          SourceLocation::UIntTy LoadedOffset);
 
   SrcMgr::ContentCache &getOrCreateContentCache(FileEntryRef SourceFile,
                                                 bool isSystemFile = false);
@@ -1845,9 +1851,9 @@
   SrcMgr::ContentCache &
   createMemBufferContentCache(std::unique_ptr<llvm::MemoryBuffer> Buf);
 
-  FileID getFileIDSlow(unsigned SLocOffset) const;
-  FileID getFileIDLocal(unsigned SLocOffset) const;
-  FileID getFileIDLoaded(unsigned SLocOffset) const;
+  FileID getFileIDSlow(SourceLocation::UIntTy SLocOffset) const;
+  FileID getFileIDLocal(SourceLocation::UIntTy SLocOffset) const;
+  FileID getFileIDLoaded(SourceLocation::UIntTy SLocOffset) const;
 
   SourceLocation getExpansionLocSlowCase(SourceLocation Loc) const;
   SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const;
Index: clang/include/clang/Basic/SourceLocation.h
===================================================================
--- clang/include/clang/Basic/SourceLocation.h
+++ clang/include/clang/Basic/SourceLocation.h
@@ -91,11 +91,14 @@
   friend class SourceManager;
   friend struct llvm::FoldingSetTrait<SourceLocation>;
 
-  unsigned ID = 0;
+public:
+  using UIntTy = uint32_t;
+  using IntTy = int32_t;
 
-  enum : unsigned {
-    MacroIDBit = 1U << 31
-  };
+private:
+  UIntTy ID = 0;
+
+  enum : UIntTy { MacroIDBit = 1ULL << (8 * sizeof(UIntTy) - 1) };
 
 public:
   bool isFileID() const  { return (ID & MacroIDBit) == 0; }
@@ -111,18 +114,16 @@
 
 private:
   /// Return the offset into the manager's global input view.
-  unsigned getOffset() const {
-    return ID & ~MacroIDBit;
-  }
+  UIntTy getOffset() const { return ID & ~MacroIDBit; }
 
-  static SourceLocation getFileLoc(unsigned ID) {
+  static SourceLocation getFileLoc(UIntTy ID) {
     assert((ID & MacroIDBit) == 0 && "Ran out of source locations!");
     SourceLocation L;
     L.ID = ID;
     return L;
   }
 
-  static SourceLocation getMacroLoc(unsigned ID) {
+  static SourceLocation getMacroLoc(UIntTy ID) {
     assert((ID & MacroIDBit) == 0 && "Ran out of source locations!");
     SourceLocation L;
     L.ID = MacroIDBit | ID;
@@ -132,7 +133,7 @@
 public:
   /// Return a source location with the specified offset from this
   /// SourceLocation.
-  SourceLocation getLocWithOffset(int Offset) const {
+  SourceLocation getLocWithOffset(IntTy Offset) const {
     assert(((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow");
     SourceLocation L;
     L.ID = ID+Offset;
@@ -144,13 +145,13 @@
   ///
   /// This should only be passed to SourceLocation::getFromRawEncoding, it
   /// should not be inspected directly.
-  unsigned getRawEncoding() const { return ID; }
+  UIntTy getRawEncoding() const { return ID; }
 
   /// Turn a raw encoding of a SourceLocation object into
   /// a real SourceLocation.
   ///
   /// \see getRawEncoding.
-  static SourceLocation getFromRawEncoding(unsigned Encoding) {
+  static SourceLocation getFromRawEncoding(UIntTy Encoding) {
     SourceLocation X;
     X.ID = Encoding;
     return X;
@@ -170,7 +171,7 @@
   /// Turn a pointer encoding of a SourceLocation object back
   /// into a real SourceLocation.
   static SourceLocation getFromPtrEncoding(const void *Encoding) {
-    return getFromRawEncoding((unsigned)(uintptr_t)Encoding);
+    return getFromRawEncoding((SourceLocation::UIntTy)(uintptr_t)Encoding);
   }
 
   static bool isPairOfFileLocations(SourceLocation Start, SourceLocation End) {
@@ -488,11 +489,13 @@
   /// DenseMapInfo<unsigned> which uses SourceLocation::ID is used as a key.
   template <> struct DenseMapInfo<clang::SourceLocation> {
     static clang::SourceLocation getEmptyKey() {
-      return clang::SourceLocation::getFromRawEncoding(~0U);
+      constexpr clang::SourceLocation::UIntTy Zero = 0;
+      return clang::SourceLocation::getFromRawEncoding(~Zero);
     }
 
     static clang::SourceLocation getTombstoneKey() {
-      return clang::SourceLocation::getFromRawEncoding(~0U - 1);
+      constexpr clang::SourceLocation::UIntTy Zero = 0;
+      return clang::SourceLocation::getFromRawEncoding(~Zero - 1);
     }
 
     static unsigned getHashValue(clang::SourceLocation Loc) {
Index: clang/include/clang/AST/DeclarationName.h
===================================================================
--- clang/include/clang/AST/DeclarationName.h
+++ clang/include/clang/AST/DeclarationName.h
@@ -660,13 +660,13 @@
 
   // The location (if any) of the operator keyword is stored elsewhere.
   struct CXXOpName {
-    unsigned BeginOpNameLoc;
-    unsigned EndOpNameLoc;
+    SourceLocation::UIntTy BeginOpNameLoc;
+    SourceLocation::UIntTy EndOpNameLoc;
   };
 
   // The location (if any) of the operator keyword is stored elsewhere.
   struct CXXLitOpName {
-    unsigned OpNameLoc;
+    SourceLocation::UIntTy OpNameLoc;
   };
 
   // struct {} CXXUsingDirective;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D105492: [clang] Intr... Simon Tatham via Phabricator via cfe-commits

Reply via email to