[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

Viktoriia Bakalova via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 16 04:47:56 PST 2025


================
@@ -3159,13 +3164,36 @@ Attr *ASTRecordReader::readAttr() {
   return New;
 }
 
-/// Reads attributes from the current stream position.
-void ASTRecordReader::readAttributes(AttrVec &Attrs) {
+/// Reads attributes from the current stream position, advancing Idx.
+/// For some attributes (where type depends on itself recursively), defer
+/// reading the attribute until the type has been read.
+void ASTRecordReader::readAttributes(AttrVec &Attrs, Decl *D) {
   for (unsigned I = 0, E = readInt(); I != E; ++I)
-    if (auto *A = readAttr())
+    if (auto *A = readOrDeferAttrFor(D))
       Attrs.push_back(A);
 }
 
+
+/// Reads one attribute from the current stream position, advancing Idx.
+/// For some attributes (where type depends on itself recursively), defer
+/// reading the attribute until the type has been read.
+Attr *ASTRecordReader::readOrDeferAttrFor(Decl *D) {
+  AttrReader Record(*this);
+  unsigned SkipCount = Record.readInt();
+  if (!SkipCount)
+    return readAttr();
----------------
VitaNuo wrote:

Makes sense! However, I also had to reorder the fields to write the attribute kind before the skip count, since some code paths depend on reading the (absent) attribute kind first and exiting the `readAtrr` function.

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


More information about the cfe-commits mailing list