================
@@ -4469,6 +4469,52 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New,
NamedDecl *&OldD, Scope *S,
return true;
}
+/// Check if a function has a lifetimebound attribute on its function type
+/// (which represents the implicit 'this' parameter for methods).
+/// Returns the attribute if found, nullptr otherwise.
+static const LifetimeBoundAttr *
+getLifetimeBoundAttrFromType(const TypeSourceInfo *TSI) {
+ if (!TSI)
+ return nullptr;
+
+ for (TypeLoc TL = TSI->getTypeLoc();;) {
+ auto ATL = TL.getAsAdjusted<AttributedTypeLoc>();
+ if (!ATL)
+ break;
+ if (auto *LBAttr = ATL.getAttrAs<LifetimeBoundAttr>())
+ return LBAttr;
+ TL = ATL.getModifiedLoc();
+ }
+ return nullptr;
+}
+
+/// Merge lifetimebound attribute on function type (implicit 'this')
+/// from Old to New method declaration.
+static void mergeLifetimeBoundAttrOnMethod(Sema &S, CXXMethodDecl *New,
+ const CXXMethodDecl *Old) {
+ const TypeSourceInfo *OldTSI = Old->getTypeSourceInfo();
+ const TypeSourceInfo *NewTSI = New->getTypeSourceInfo();
+
+ if (!OldTSI || !NewTSI)
+ return;
+
+ const LifetimeBoundAttr *OldLBAttr = getLifetimeBoundAttrFromType(OldTSI);
+ const LifetimeBoundAttr *NewLBAttr = getLifetimeBoundAttrFromType(NewTSI);
+
+ // If Old has lifetimebound but New doesn't, add it to New
+ if (OldLBAttr && !NewLBAttr) {
+ QualType NewMethodType = New->getType();
+ QualType AttributedType =
+ S.Context.getAttributedType(OldLBAttr, NewMethodType, NewMethodType);
+ TypeLocBuilder TLB;
+ TLB.pushFullCopy(NewTSI->getTypeLoc());
+ AttributedTypeLoc TyLoc = TLB.push<AttributedTypeLoc>(AttributedType);
+ TyLoc.setAttr(OldLBAttr);
+ New->setType(AttributedType);
+ New->setTypeSourceInfo(TLB.getTypeSourceInfo(S.Context, AttributedType));
+ }
+}
----------------
usx95 wrote:
The idea is to read mostRecentDecl for analysis and it would reflect all the
merged attributes seen until now.
https://github.com/llvm/llvm-project/pull/172146
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits