[clang] [clang] Delete duplicate code in sourcemanager (PR #166236)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 4 07:59:12 PST 2025


================
@@ -1275,43 +1275,24 @@ 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);
----------------
AaronBallman wrote:

I think we can run into the case where the file ID has no sloc entry (thinking about things like modules or imported AST units), so I think the original code was correct and the new code will quietly return an invalid `SLocEntry`, won't it?

https://github.com/llvm/llvm-project/pull/166236


More information about the cfe-commits mailing list