Skip to content

Commit 8cce7af

Browse files
[SourceManager] don't check invalid param of getLocalSLocEntry()
Forked from D80681. getLocalSLocEntry() has an unused parameter used to satisfy an interface of libclang (see getInclusions() in clang/tools/libclang/CIndexInclusionStack.cpp). It's pointless for callers to construct/pass/check this inout parameter that can never signify that a FileID is invalid. Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D82498
1 parent a95796a commit 8cce7af

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

clang/include/clang/Basic/SourceManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,8 +1645,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
16451645
unsigned local_sloc_entry_size() const { return LocalSLocEntryTable.size(); }
16461646

16471647
/// Get a local SLocEntry. This is exposed for indexing.
1648-
const SrcMgr::SLocEntry &getLocalSLocEntry(unsigned Index,
1649-
bool *Invalid = nullptr) const {
1648+
const SrcMgr::SLocEntry &getLocalSLocEntry(unsigned Index) const {
16501649
assert(Index < LocalSLocEntryTable.size() && "Invalid index");
16511650
return LocalSLocEntryTable[Index];
16521651
}
@@ -1739,12 +1738,13 @@ class SourceManager : public RefCountedBase<SourceManager> {
17391738
const SrcMgr::SLocEntry &loadSLocEntry(unsigned Index, bool *Invalid) const;
17401739

17411740
/// Get the entry with the given unwrapped FileID.
1741+
/// Invalid will not be modified for Local IDs.
17421742
const SrcMgr::SLocEntry &getSLocEntryByID(int ID,
17431743
bool *Invalid = nullptr) const {
17441744
assert(ID != -1 && "Using FileID sentinel value");
17451745
if (ID < 0)
17461746
return getLoadedSLocEntryByID(ID, Invalid);
1747-
return getLocalSLocEntry(static_cast<unsigned>(ID), Invalid);
1747+
return getLocalSLocEntry(static_cast<unsigned>(ID));
17481748
}
17491749

17501750
const SrcMgr::SLocEntry &

clang/lib/Basic/SourceManager.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -882,11 +882,8 @@ FileID SourceManager::getFileIDLocal(unsigned SLocOffset) const {
882882
unsigned LessIndex = 0;
883883
NumProbes = 0;
884884
while (true) {
885-
bool Invalid = false;
886885
unsigned MiddleIndex = (GreaterIndex-LessIndex)/2+LessIndex;
887-
unsigned MidOffset = getLocalSLocEntry(MiddleIndex, &Invalid).getOffset();
888-
if (Invalid)
889-
return FileID::get(0);
886+
unsigned MidOffset = getLocalSLocEntry(MiddleIndex).getOffset();
890887

891888
++NumProbes;
892889

@@ -1694,11 +1691,7 @@ FileID SourceManager::translateFile(const FileEntry *SourceFile) const {
16941691
// The location we're looking for isn't in the main file; look
16951692
// through all of the local source locations.
16961693
for (unsigned I = 0, N = local_sloc_entry_size(); I != N; ++I) {
1697-
bool Invalid = false;
1698-
const SLocEntry &SLoc = getLocalSLocEntry(I, &Invalid);
1699-
if (Invalid)
1700-
return FileID();
1701-
1694+
const SLocEntry &SLoc = getLocalSLocEntry(I);
17021695
if (SLoc.isFile() && SLoc.getFile().getContentCache() &&
17031696
SLoc.getFile().getContentCache()->OrigEntry == SourceFile)
17041697
return FileID::get(I);

0 commit comments

Comments
 (0)