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

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 16 00:47:17 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();
----------------
ChuanqiXu9 wrote:

Now it assumes that `readAttr()` should be called after the skip bit. Then the caller has more responsibility. I feel it better to skip it in `readAttr` and not read here.

e.g.,
```suggestion
  unsigned SkipCount = Record.peekInt();
  if (!SkipCount)
    return readAttr();
```

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


More information about the cfe-commits mailing list