================
@@ -46,13 +47,60 @@ class MissingOriginCollector
private:
const llvm::DenseMap<const clang::Expr *, OriginList *> &ExprToOriginList;
+ const OriginManager &OM;
LifetimeSafetyStats &LSStats;
};
+
+class LifetimeboundOriginTypeCollector
+ : public RecursiveASTVisitor<LifetimeboundOriginTypeCollector> {
+public:
+ LifetimeboundOriginTypeCollector(OriginManager &OM) : OM(OM) {}
+
+ bool VisitCallExpr(const CallExpr *CE) {
+ if (const auto *FD = CE->getDirectCallee())
+ collect(FD, FD->getReturnType());
+ return true;
+ }
+
+ bool VisitCXXConstructExpr(const CXXConstructExpr *CCE) {
+ collect(CCE->getConstructor(), CCE->getType());
+ return true;
+ }
+
+ bool shouldVisitLambdaBody() const { return false; }
+
+private:
+ OriginManager &OM;
+
+ void collect(const FunctionDecl *FD, QualType RetType) {
+ if (!FD)
+ return;
+ FD = getDeclWithMergedLifetimeBoundAttrs(FD);
+
+ if (const auto *MD = dyn_cast<CXXMethodDecl>(FD);
+ MD && MD->isInstance() && !isa<CXXConstructorDecl>(MD) &&
+ implicitObjectParamIsLifetimeBound(MD)) {
+ OM.registerLifetimeboundOriginType(RetType);
+ return;
+ }
+
+ for (const auto *Param : FD->parameters()) {
+ if (Param->hasAttr<LifetimeBoundAttr>()) {
+ OM.registerLifetimeboundOriginType(RetType);
+ return;
+ }
+ }
+ }
+};
+
} // namespace
-bool hasOrigins(QualType QT) {
+bool OriginManager::hasOrigins(QualType QT) const {
----------------
aeft wrote:
Updated in place to make it easier to review. Happy to move it to a more
appropriate location in a separate PR if you prefer.
https://github.com/llvm/llvm-project/pull/187917
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits