[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 01:44:00 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:

Ah nice idea. I didn't realize `peekInt()` is an option.

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


More information about the cfe-commits mailing list