[llvm-branch-commits] [clang] [serialization] No transitive type change (PR #92511)

Ilya Biryukov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jun 19 09:55:29 PDT 2024


================
@@ -7100,14 +7084,25 @@ TypeSourceInfo *ASTRecordReader::readTypeSourceInfo() {
   return TInfo;
 }
 
+std::pair<ModuleFile *, unsigned>
+ASTReader::translateTypeIDToIndex(serialization::TypeID ID) const {
+  unsigned Index =
+      (ID & llvm::maskTrailingOnes<TypeID>(32)) >> Qualifiers::FastWidth;
+
+  ModuleFile *OwningModuleFile = getOwningModuleFile(ID);
+  assert(OwningModuleFile &&
+         "untranslated type ID or local type ID shouldn't be in TypesLoaded");
+  return {OwningModuleFile, OwningModuleFile->BaseTypeIndex + Index};
+}
+
 QualType ASTReader::GetType(TypeID ID) {
   assert(ContextObj && "reading type with no AST context");
   ASTContext &Context = *ContextObj;
 
   unsigned FastQuals = ID & Qualifiers::FastMask;
-  unsigned Index = ID >> Qualifiers::FastWidth;
 
-  if (Index < NUM_PREDEF_TYPE_IDS) {
+  if (uint64_t Index = ID >> Qualifiers::FastWidth;
----------------
ilya-biryukov wrote:

Higher bits still represent the module file index here, right?
Could you clarify why it's correct to compare with `NUM_PREDEF_TYPE_IDS` without first extracting those bits?

Are the higher bits of predefined types always `0`?
(If this was done on top of results `translateTypeIDToIndex`, it would be very clear that the code is correct, not sure if there are reasons to postpone this call).

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


More information about the llvm-branch-commits mailing list