https://github.com/SergejSalnikov updated https://github.com/llvm/llvm-project/pull/166236
>From 6d82050994e03c246b24601abccd80bafcd2cc73 Mon Sep 17 00:00:00 2001 From: SKill <[email protected]> Date: Mon, 3 Nov 2025 22:01:37 +0100 Subject: [PATCH 1/2] [clang] Delete duplicate code in sourcemanager --- clang/include/clang/Basic/SourceManager.h | 31 +++----------------- clang/lib/Basic/SourceManager.cpp | 35 ----------------------- 2 files changed, 4 insertions(+), 62 deletions(-) diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index ed967fd47dc83..7cd46a0fc56e4 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -1275,10 +1275,8 @@ class SourceManager : public RefCountedBase<SourceManager> { /// start of the buffer of the location. FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const { FileID FID = getFileID(Loc); - auto *Entry = getSLocEntryOrNull(FID); - if (!Entry) - return std::make_pair(FileID(), 0); - return std::make_pair(FID, Loc.getOffset() - Entry->getOffset()); + const SrcMgr::SLocEntry &Entry = getSLocEntry(FID); + return std::make_pair(FID, Loc.getOffset() - Entry.getOffset()); } /// Decompose the specified location into a raw FileID + Offset pair. @@ -1286,16 +1284,7 @@ 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)); } /// Decompose the specified location into a raw FileID + Offset pair. @@ -1303,15 +1292,7 @@ class SourceManager : public RefCountedBase<SourceManager> { /// 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 @@ -1979,10 +1960,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, diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 97aa0f2aa59b9..7dc81c50f87a2 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -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 >From 17980bd91e9908ea9449eac7f1a659b01644b634 Mon Sep 17 00:00:00 2001 From: SKill <[email protected]> Date: Tue, 4 Nov 2025 20:47:25 +0100 Subject: [PATCH 2/2] Restore getDecompiledLoc --- clang/include/clang/Basic/SourceManager.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 7cd46a0fc56e4..6d9d074d78026 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -1275,8 +1275,10 @@ class SourceManager : public RefCountedBase<SourceManager> { /// start of the buffer of the location. FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const { FileID FID = getFileID(Loc); - const SrcMgr::SLocEntry &Entry = getSLocEntry(FID); - return std::make_pair(FID, Loc.getOffset() - Entry.getOffset()); + auto *Entry = getSLocEntryOrNull(FID); + if (!Entry) + return std::make_pair(FileID(), 0); + return std::make_pair(FID, Loc.getOffset() - Entry->getOffset()); } /// Decompose the specified location into a raw FileID + Offset pair. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
