================
@@ -123,6 +123,24 @@ FunctionCallInfo::FunctionCallInfo(const Expr *Call) {
Args = AC->arguments();
}
+const LifetimeCaptureByAttr *
+getCaptureByAttrFromFunctionType(const FunctionDecl *FD) {
+ const TypeSourceInfo *TSI = FD->getTypeSourceInfo();
+ if (!TSI)
+ return nullptr;
+ // Walk through the type layers looking for a capture_by attribute.
+ TypeLoc TL = TSI->getTypeLoc();
+ while (true) {
+ auto ATL = TL.getAsAdjusted<AttributedTypeLoc>();
+ if (!ATL)
+ break;
+ if (auto *Attr = ATL.getAttrAs<LifetimeCaptureByAttr>())
+ return Attr;
+ TL = ATL.getModifiedLoc();
+ }
+ return nullptr;
+}
----------------
usx95 wrote:
Consider refactoring `getCaptureByAttrFromFunctionType` and the existing
`getLifetimeBoundAttrFromFunctionType` into a single template function. For
example:
```cpp
template <typename AttrType>
static const AttrType *
getAttrFromFunctionType(const FunctionDecl *FD) {
const TypeSourceInfo *TSI = FD->getTypeSourceInfo();
if (!TSI)
return nullptr;
TypeLoc TL = TSI->getTypeLoc();
while (true) {
auto ATL = TL.getAsAdjusted<AttributedTypeLoc>();
if (!ATL)
break;
if (auto *Attr = ATL.getAttrAs<AttrType>())
return Attr;
TL = ATL.getModifiedLoc();
}
return nullptr;
}
const LifetimeCaptureByAttr *
getCaptureByAttrFromFunctionType(const FunctionDecl *FD) {
return getAttrFromFunctionType<LifetimeCaptureByAttr>(FD);
}
```
Then `getLifetimeBoundAttrFromFunctionType` could be updated similarly to use
`getAttrFromFunctionType<LifetimeBoundAttr>`.
https://github.com/llvm/llvm-project/pull/219423
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits