[clang] [clang] [Serialization] No transitive change for MacroID and PreprocessedEntityID (PR #166346)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 4 08:33:21 PST 2025


================
@@ -6718,11 +6698,23 @@ SourceRange ASTReader::ReadSkippedRange(unsigned GlobalIndex) {
   return Range;
 }
 
+unsigned
+ASTReader::translatePreprocessedEntityIDToIndex(PreprocessedEntityID ID) const {
+  unsigned ModuleFileIndex = ID >> 32;
+  assert(ModuleFileIndex && "not translating loaded MacroID?");
+  assert(getModuleManager().size() > ModuleFileIndex - 1);
+  ModuleFile &MF = getModuleManager()[ModuleFileIndex - 1];
+
+  ID &= llvm::maskTrailingOnes<PreprocessedEntityID>(32);
+  return MF.BasePreprocessedEntityID + ID;
+}
+
 PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) {
-  PreprocessedEntityID PPID = Index+1;
   std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index);
   ModuleFile &M = *PPInfo.first;
   unsigned LocalIndex = PPInfo.second;
+  PreprocessedEntityID PPID =
+      (((PreprocessedEntityID)M.Index + 1) << 32) | LocalIndex;
----------------
jansvoboda11 wrote:

Another C-style cast.

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


More information about the cfe-commits mailing list