[clang] [WIP] [Modules] Delay reading type source info of the preferred_name attribute. (PR #122250)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 10 04:56:58 PST 2025
================
@@ -9860,6 +9860,33 @@ void ASTReader::finishPendingActions() {
}
PendingDeducedVarTypes.clear();
+ ASTContext &Context = getContext();
+ for (unsigned I = 0; I != PendingPreferredNameAttributes.size(); ++I) {
+ auto *D = PendingPreferredNameAttributes[I].D;
+ QualType InfoTy = GetType(PendingPreferredNameAttributes[I].TypeID);
+ TypeSourceInfo *TInfo = nullptr;
+ if (!InfoTy.isNull()) {
+ TInfo = getContext().CreateTypeSourceInfo(InfoTy);
+ if (auto Loc = TInfo->getTypeLoc().getAs<ElaboratedTypeLoc>()) {
+ Loc.setElaboratedKeywordLoc(
+ PendingPreferredNameAttributes[I].ElaboratedTypedefSL);
+ Loc.setQualifierLoc(PendingPreferredNameAttributes[I].NestedNameSL);
+ if (auto TypedefLoc = Loc.getNextTypeLoc().getAs<TypedefTypeLoc>())
+ TypedefLoc.setNameLoc(PendingPreferredNameAttributes[I].TypedefSL);
+ }
+ }
+
+ AttrVec &Attrs = getContext().getDeclAttrs(D);
+ PreferredNameAttr *New = new (Context) PreferredNameAttr(
+ Context, PendingPreferredNameAttributes[I].Info, TInfo);
+ cast<InheritableAttr>(New)->setInherited(
+ PendingPreferredNameAttributes[I].isInherited);
+ New->setImplicit(PendingPreferredNameAttributes[I].isImplicit);
----------------
ilya-biryukov wrote:
Duplicating the code here may lead to errors later.
Could we ensure that's the only code path that's being used to read preferred_name attributes? That would entail asserting that the common `readAttr` asserts the attribute is **not** PreferredName and I'd also suggest adding a documentation comment in `Attr.td` that PreferredName has a custom deserialization logic pointing to that function.
https://github.com/llvm/llvm-project/pull/122250
More information about the cfe-commits
mailing list