Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions clang/include/clang/Basic/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -1286,32 +1286,15 @@ class SourceManager : public RefCountedBase<SourceManager> {
/// If the location is an expansion record, walk through it until we find
/// the final location expanded.
FileIDAndOffset getDecomposedExpansionLoc(SourceLocation Loc) const {
FileID FID = getFileID(Loc);
auto *E = getSLocEntryOrNull(FID);
if (!E)
return std::make_pair(FileID(), 0);

unsigned Offset = Loc.getOffset()-E->getOffset();
if (Loc.isFileID())
return std::make_pair(FID, Offset);

return getDecomposedExpansionLocSlowCase(E);
return getDecomposedLoc(getExpansionLoc(Loc));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this going to now do the wrong thing when the expansion location is itself a macro ID rather than a file ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look into implementation of getDecomposedExpansionLocSlowCase it does
Loc = E->getExpansion().getExpansionLocStart() in a while loop, that's exactly the same as what getExpansionLoc does.

I've actually added the assertion about old result == new result and run all tests. and they all pass.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're likely correct, but I'd appreciate some eyes from @cor3ntin to double-check. He's away at C++ standards meetings this week, so it may be a bit before he responds, just FYI.

}

/// Decompose the specified location into a raw FileID + Offset pair.
///
/// If the location is an expansion record, walk through it until we find
/// its spelling record.
FileIDAndOffset getDecomposedSpellingLoc(SourceLocation Loc) const {
FileID FID = getFileID(Loc);
auto *E = getSLocEntryOrNull(FID);
if (!E)
return std::make_pair(FileID(), 0);

unsigned Offset = Loc.getOffset()-E->getOffset();
if (Loc.isFileID())
return std::make_pair(FID, Offset);
return getDecomposedSpellingLocSlowCase(E, Offset);
return getDecomposedLoc(getSpellingLoc(Loc));
}

/// Returns the "included/expanded in" decomposed location of the given
Expand Down Expand Up @@ -1979,10 +1962,6 @@ class SourceManager : public RefCountedBase<SourceManager> {
SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const;
SourceLocation getFileLocSlowCase(SourceLocation Loc) const;

FileIDAndOffset
getDecomposedExpansionLocSlowCase(const SrcMgr::SLocEntry *E) const;
FileIDAndOffset getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
unsigned Offset) const;
void computeMacroArgsCache(MacroArgsMap &MacroArgsCache, FileID FID) const;
void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
FileID FID,
Expand Down
35 changes: 0 additions & 35 deletions clang/lib/Basic/SourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,41 +928,6 @@ SourceLocation SourceManager::getFileLocSlowCase(SourceLocation Loc) const {
return Loc;
}

FileIDAndOffset SourceManager::getDecomposedExpansionLocSlowCase(
const SrcMgr::SLocEntry *E) const {
// If this is an expansion record, walk through all the expansion points.
FileID FID;
SourceLocation Loc;
unsigned Offset;
do {
Loc = E->getExpansion().getExpansionLocStart();

FID = getFileID(Loc);
E = &getSLocEntry(FID);
Offset = Loc.getOffset()-E->getOffset();
} while (!Loc.isFileID());

return std::make_pair(FID, Offset);
}

FileIDAndOffset
SourceManager::getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
unsigned Offset) const {
// If this is an expansion record, walk through all the expansion points.
FileID FID;
SourceLocation Loc;
do {
Loc = E->getExpansion().getSpellingLoc();
Loc = Loc.getLocWithOffset(Offset);

FID = getFileID(Loc);
E = &getSLocEntry(FID);
Offset = Loc.getOffset()-E->getOffset();
} while (!Loc.isFileID());

return std::make_pair(FID, Offset);
}

/// getImmediateSpellingLoc - Given a SourceLocation object, return the
/// spelling location referenced by the ID. This is the first level down
/// towards the place where the characters that make up the lexed token can be
Expand Down