@@ -465,8 +465,9 @@ static_assert(sizeof(FileInfo) <= sizeof(ExpansionInfo),
465
465
// / SourceManager keeps an array of these objects, and they are uniquely
466
466
// / identified by the FileID datatype.
467
467
class SLocEntry {
468
- unsigned Offset : 31 ;
469
- unsigned IsExpansion : 1 ;
468
+ static constexpr int OffsetBits = 8 * sizeof (SourceLocation::UIntTy) - 1 ;
469
+ SourceLocation::UIntTy Offset : OffsetBits;
470
+ SourceLocation::UIntTy IsExpansion : 1 ;
470
471
union {
471
472
FileInfo File;
472
473
ExpansionInfo Expansion;
@@ -475,7 +476,7 @@ class SLocEntry {
475
476
public:
476
477
SLocEntry () : Offset(), IsExpansion(), File() {}
477
478
478
- unsigned getOffset () const { return Offset; }
479
+ SourceLocation::UIntTy getOffset () const { return Offset; }
479
480
480
481
bool isExpansion () const { return IsExpansion; }
481
482
bool isFile () const { return !isExpansion (); }
@@ -490,17 +491,18 @@ class SLocEntry {
490
491
return Expansion;
491
492
}
492
493
493
- static SLocEntry get (unsigned Offset, const FileInfo &FI) {
494
- assert (!(Offset & (1u << 31 )) && " Offset is too large" );
494
+ static SLocEntry get (SourceLocation::UIntTy Offset, const FileInfo &FI) {
495
+ assert (!(Offset & (1ULL << OffsetBits )) && " Offset is too large" );
495
496
SLocEntry E;
496
497
E.Offset = Offset;
497
498
E.IsExpansion = false ;
498
499
E.File = FI;
499
500
return E;
500
501
}
501
502
502
- static SLocEntry get (unsigned Offset, const ExpansionInfo &Expansion) {
503
- assert (!(Offset & (1u << 31 )) && " Offset is too large" );
503
+ static SLocEntry get (SourceLocation::UIntTy Offset,
504
+ const ExpansionInfo &Expansion) {
505
+ assert (!(Offset & (1ULL << OffsetBits)) && " Offset is too large" );
504
506
SLocEntry E;
505
507
E.Offset = Offset;
506
508
E.IsExpansion = true ;
@@ -690,17 +692,18 @@ class SourceManager : public RefCountedBase<SourceManager> {
690
692
// / The starting offset of the next local SLocEntry.
691
693
// /
692
694
// / This is LocalSLocEntryTable.back().Offset + the size of that entry.
693
- unsigned NextLocalOffset;
695
+ SourceLocation::UIntTy NextLocalOffset;
694
696
695
697
// / The starting offset of the latest batch of loaded SLocEntries.
696
698
// /
697
699
// / This is LoadedSLocEntryTable.back().Offset, except that that entry might
698
700
// / not have been loaded, so that value would be unknown.
699
- unsigned CurrentLoadedOffset;
701
+ SourceLocation::UIntTy CurrentLoadedOffset;
700
702
701
- // / The highest possible offset is 2^31-1, so CurrentLoadedOffset
702
- // / starts at 2^31.
703
- static const unsigned MaxLoadedOffset = 1U << 31U ;
703
+ // / The highest possible offset is 2^32-1 (2^63-1 for 64-bit source
704
+ // / locations), so CurrentLoadedOffset starts at 2^31 (2^63 resp.).
705
+ static const SourceLocation::UIntTy MaxLoadedOffset =
706
+ 1ULL << (8 * sizeof (SourceLocation::UIntTy) - 1 );
704
707
705
708
// / A bitmap that indicates whether the entries of LoadedSLocEntryTable
706
709
// / have already been loaded from the external source.
@@ -865,19 +868,21 @@ class SourceManager : public RefCountedBase<SourceManager> {
865
868
// / This translates NULL into standard input.
866
869
FileID createFileID (const FileEntry *SourceFile, SourceLocation IncludePos,
867
870
SrcMgr::CharacteristicKind FileCharacter,
868
- int LoadedID = 0 , unsigned LoadedOffset = 0 );
871
+ int LoadedID = 0 ,
872
+ SourceLocation::UIntTy LoadedOffset = 0 );
869
873
870
874
FileID createFileID (FileEntryRef SourceFile, SourceLocation IncludePos,
871
875
SrcMgr::CharacteristicKind FileCharacter,
872
- int LoadedID = 0 , unsigned LoadedOffset = 0 );
876
+ int LoadedID = 0 ,
877
+ SourceLocation::UIntTy LoadedOffset = 0 );
873
878
874
879
// / Create a new FileID that represents the specified memory buffer.
875
880
// /
876
881
// / This does no caching of the buffer and takes ownership of the
877
882
// / MemoryBuffer, so only pass a MemoryBuffer to this once.
878
883
FileID createFileID (std::unique_ptr<llvm::MemoryBuffer> Buffer,
879
884
SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User,
880
- int LoadedID = 0 , unsigned LoadedOffset = 0 ,
885
+ int LoadedID = 0 , SourceLocation::UIntTy LoadedOffset = 0 ,
881
886
SourceLocation IncludeLoc = SourceLocation());
882
887
883
888
// / Create a new FileID that represents the specified memory buffer.
@@ -886,7 +891,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
886
891
// / outlive the SourceManager.
887
892
FileID createFileID (const llvm::MemoryBufferRef &Buffer,
888
893
SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User,
889
- int LoadedID = 0 , unsigned LoadedOffset = 0 ,
894
+ int LoadedID = 0 , SourceLocation::UIntTy LoadedOffset = 0 ,
890
895
SourceLocation IncludeLoc = SourceLocation());
891
896
892
897
// / Get the FileID for \p SourceFile if it exists. Otherwise, create a
@@ -905,13 +910,11 @@ class SourceManager : public RefCountedBase<SourceManager> {
905
910
// / Return a new SourceLocation that encodes the fact
906
911
// / that a token from SpellingLoc should actually be referenced from
907
912
// / ExpansionLoc.
908
- SourceLocation createExpansionLoc (SourceLocation Loc,
909
- SourceLocation ExpansionLocStart,
910
- SourceLocation ExpansionLocEnd,
911
- unsigned TokLength,
912
- bool ExpansionIsTokenRange = true ,
913
- int LoadedID = 0 ,
914
- unsigned LoadedOffset = 0 );
913
+ SourceLocation
914
+ createExpansionLoc (SourceLocation Loc, SourceLocation ExpansionLocStart,
915
+ SourceLocation ExpansionLocEnd, unsigned TokLength,
916
+ bool ExpansionIsTokenRange = true , int LoadedID = 0 ,
917
+ SourceLocation::UIntTy LoadedOffset = 0 );
915
918
916
919
// / Return a new SourceLocation that encodes that the token starting
917
920
// / at \p TokenStart ends prematurely at \p TokenEnd.
@@ -1098,7 +1101,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
1098
1101
// / the entry in SLocEntryTable which contains the specified location.
1099
1102
// /
1100
1103
FileID getFileID (SourceLocation SpellingLoc) const {
1101
- unsigned SLocOffset = SpellingLoc.getOffset ();
1104
+ SourceLocation::UIntTy SLocOffset = SpellingLoc.getOffset ();
1102
1105
1103
1106
// If our one-entry cache covers this offset, just return it.
1104
1107
if (isOffsetInFileID (LastFileIDLookup, SLocOffset))
@@ -1221,7 +1224,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
1221
1224
if (!Entry)
1222
1225
return SourceLocation ();
1223
1226
1224
- unsigned GlobalOffset = Entry->getOffset () + Offset;
1227
+ SourceLocation::UIntTy GlobalOffset = Entry->getOffset () + Offset;
1225
1228
return Entry->isFile () ? SourceLocation::getFileLoc (GlobalOffset)
1226
1229
: SourceLocation::getMacroLoc (GlobalOffset);
1227
1230
}
@@ -1326,17 +1329,17 @@ class SourceManager : public RefCountedBase<SourceManager> {
1326
1329
// /
1327
1330
// / If it's true and \p RelativeOffset is non-null, it will be set to the
1328
1331
// / relative offset of \p Loc inside the chunk.
1329
- bool isInSLocAddrSpace (SourceLocation Loc,
1330
- SourceLocation Start, unsigned Length,
1331
- unsigned *RelativeOffset = nullptr ) const {
1332
+ bool
1333
+ isInSLocAddrSpace (SourceLocation Loc, SourceLocation Start, unsigned Length,
1334
+ SourceLocation::UIntTy *RelativeOffset = nullptr ) const {
1332
1335
assert (((Start.getOffset () < NextLocalOffset &&
1333
1336
Start.getOffset ()+Length <= NextLocalOffset) ||
1334
1337
(Start.getOffset () >= CurrentLoadedOffset &&
1335
1338
Start.getOffset ()+Length < MaxLoadedOffset)) &&
1336
1339
" Chunk is not valid SLoc address space" );
1337
- unsigned LocOffs = Loc.getOffset ();
1338
- unsigned BeginOffs = Start.getOffset ();
1339
- unsigned EndOffs = BeginOffs + Length;
1340
+ SourceLocation::UIntTy LocOffs = Loc.getOffset ();
1341
+ SourceLocation::UIntTy BeginOffs = Start.getOffset ();
1342
+ SourceLocation::UIntTy EndOffs = BeginOffs + Length;
1340
1343
if (LocOffs >= BeginOffs && LocOffs < EndOffs) {
1341
1344
if (RelativeOffset)
1342
1345
*RelativeOffset = LocOffs - BeginOffs;
@@ -1352,8 +1355,8 @@ class SourceManager : public RefCountedBase<SourceManager> {
1352
1355
// / If it's true and \p RelativeOffset is non-null, it will be set to the
1353
1356
// / offset of \p RHS relative to \p LHS.
1354
1357
bool isInSameSLocAddrSpace (SourceLocation LHS, SourceLocation RHS,
1355
- int *RelativeOffset) const {
1356
- unsigned LHSOffs = LHS.getOffset (), RHSOffs = RHS.getOffset ();
1358
+ SourceLocation::IntTy *RelativeOffset) const {
1359
+ SourceLocation::UIntTy LHSOffs = LHS.getOffset (), RHSOffs = RHS.getOffset ();
1357
1360
bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;
1358
1361
bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;
1359
1362
@@ -1517,7 +1520,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
1517
1520
// / of FileID) to \p relativeOffset.
1518
1521
bool isInFileID (SourceLocation Loc, FileID FID,
1519
1522
unsigned *RelativeOffset = nullptr ) const {
1520
- unsigned Offs = Loc.getOffset ();
1523
+ SourceLocation::UIntTy Offs = Loc.getOffset ();
1521
1524
if (isOffsetInFileID (FID, Offs)) {
1522
1525
if (RelativeOffset)
1523
1526
*RelativeOffset = Offs - getSLocEntry (FID).getOffset ();
@@ -1636,8 +1639,9 @@ class SourceManager : public RefCountedBase<SourceManager> {
1636
1639
// / offset in the "source location address space".
1637
1640
// /
1638
1641
// / Note that we always consider source locations loaded from
1639
- bool isBeforeInSLocAddrSpace (SourceLocation LHS, unsigned RHS) const {
1640
- unsigned LHSOffset = LHS.getOffset ();
1642
+ bool isBeforeInSLocAddrSpace (SourceLocation LHS,
1643
+ SourceLocation::UIntTy RHS) const {
1644
+ SourceLocation::UIntTy LHSOffset = LHS.getOffset ();
1641
1645
bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
1642
1646
bool RHSLoaded = RHS >= CurrentLoadedOffset;
1643
1647
if (LHSLoaded == RHSLoaded)
@@ -1699,7 +1703,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
1699
1703
return getSLocEntryByID (FID.ID , Invalid);
1700
1704
}
1701
1705
1702
- unsigned getNextLocalOffset () const { return NextLocalOffset; }
1706
+ SourceLocation::UIntTy getNextLocalOffset () const { return NextLocalOffset; }
1703
1707
1704
1708
void setExternalSLocEntrySource (ExternalSLocEntrySource *Source) {
1705
1709
assert (LoadedSLocEntryTable.empty () &&
@@ -1713,8 +1717,9 @@ class SourceManager : public RefCountedBase<SourceManager> {
1713
1717
// / NumSLocEntries will be allocated, which occupy a total of TotalSize space
1714
1718
// / in the global source view. The lowest ID and the base offset of the
1715
1719
// / entries will be returned.
1716
- std::pair<int , unsigned >
1717
- AllocateLoadedSLocEntries (unsigned NumSLocEntries, unsigned TotalSize);
1720
+ std::pair<int , SourceLocation::UIntTy>
1721
+ AllocateLoadedSLocEntries (unsigned NumSLocEntries,
1722
+ SourceLocation::UIntTy TotalSize);
1718
1723
1719
1724
// / Returns true if \p Loc came from a PCH/Module.
1720
1725
bool isLoadedSourceLocation (SourceLocation Loc) const {
@@ -1795,14 +1800,15 @@ class SourceManager : public RefCountedBase<SourceManager> {
1795
1800
1796
1801
// / Implements the common elements of storing an expansion info struct into
1797
1802
// / the SLocEntry table and producing a source location that refers to it.
1798
- SourceLocation createExpansionLocImpl ( const SrcMgr::ExpansionInfo &Expansion,
1799
- unsigned TokLength ,
1800
- int LoadedID = 0 ,
1801
- unsigned LoadedOffset = 0 );
1803
+ SourceLocation
1804
+ createExpansionLocImpl ( const SrcMgr::ExpansionInfo &Expansion ,
1805
+ unsigned TokLength, int LoadedID = 0 ,
1806
+ SourceLocation::UIntTy LoadedOffset = 0 );
1802
1807
1803
1808
// / Return true if the specified FileID contains the
1804
1809
// / specified SourceLocation offset. This is a very hot method.
1805
- inline bool isOffsetInFileID (FileID FID, unsigned SLocOffset) const {
1810
+ inline bool isOffsetInFileID (FileID FID,
1811
+ SourceLocation::UIntTy SLocOffset) const {
1806
1812
const SrcMgr::SLocEntry &Entry = getSLocEntry (FID);
1807
1813
// If the entry is after the offset, it can't contain it.
1808
1814
if (SLocOffset < Entry.getOffset ()) return false ;
@@ -1836,7 +1842,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
1836
1842
FileID createFileIDImpl (SrcMgr::ContentCache &File, StringRef Filename,
1837
1843
SourceLocation IncludePos,
1838
1844
SrcMgr::CharacteristicKind DirCharacter, int LoadedID,
1839
- unsigned LoadedOffset);
1845
+ SourceLocation::UIntTy LoadedOffset);
1840
1846
1841
1847
SrcMgr::ContentCache &getOrCreateContentCache (FileEntryRef SourceFile,
1842
1848
bool isSystemFile = false );
@@ -1845,9 +1851,9 @@ class SourceManager : public RefCountedBase<SourceManager> {
1845
1851
SrcMgr::ContentCache &
1846
1852
createMemBufferContentCache (std::unique_ptr<llvm::MemoryBuffer> Buf);
1847
1853
1848
- FileID getFileIDSlow (unsigned SLocOffset) const ;
1849
- FileID getFileIDLocal (unsigned SLocOffset) const ;
1850
- FileID getFileIDLoaded (unsigned SLocOffset) const ;
1854
+ FileID getFileIDSlow (SourceLocation::UIntTy SLocOffset) const ;
1855
+ FileID getFileIDLocal (SourceLocation::UIntTy SLocOffset) const ;
1856
+ FileID getFileIDLoaded (SourceLocation::UIntTy SLocOffset) const ;
1851
1857
1852
1858
SourceLocation getExpansionLocSlowCase (SourceLocation Loc) const ;
1853
1859
SourceLocation getSpellingLocSlowCase (SourceLocation Loc) const ;
0 commit comments