[clang] [llvm] [clang][Modules][Serialization] Avoid serializing duplicate source location entries for shared input files (PR #209795)
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 17 01:36:39 PDT 2026
================
@@ -6789,9 +6839,39 @@ unsigned ASTWriter::getAdjustedNumCreatedFIDs(FileID FID) const {
return AdjustedNumCreatedFIDs;
}
+SourceLocation ASTWriter::getRedirectedLocation(SourceLocation Loc) const {
+ if (NonAffectingRedirectAdjustments.empty())
+ return SourceLocation();
+
+ SourceLocation::UIntTy Offset = Loc.getOffset();
+ if (PP->getSourceManager().isLoadedOffset(Offset))
+ return SourceLocation();
+
+ unsigned Idx = getNonAffectingRangeLowerBound(Offset);
+ if (Idx == NonAffectingRanges.size())
+ return SourceLocation();
+
+ // The search only rules out ranges ending before the offset, so check that
+ // the offset really is inside the one we landed on.
+ if (Offset < NonAffectingRanges[Idx].getBegin().getOffset())
+ return SourceLocation();
+
+ int64_t Adjustment = NonAffectingRedirectAdjustments[Idx];
+ if (!Adjustment)
+ return SourceLocation();
+ return SourceLocation::getFileLoc(static_cast<SourceLocation::UIntTy>(
+ static_cast<int64_t>(Offset) - Adjustment));
----------------
ChuanqiXu9 wrote:
I failed to understand this. What is Adjustment? And why do we need Offset - Adjustment?
https://github.com/llvm/llvm-project/pull/209795
More information about the cfe-commits
mailing list