[clang] [LifetimeSafety] Detect use-after-scope through fields in member calls (PR #191731)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 13 06:35:47 PDT 2026
================
@@ -723,6 +723,40 @@ void FactsGenerator::handleInvalidatingCall(const Expr *Call,
ThisList->getOuterOriginID(), Call));
}
+void FactsGenerator::handleImplicitObjectFieldUses(const Expr *Call,
+ const FunctionDecl *FD) {
+ const auto *MD = dyn_cast<CXXMethodDecl>(FD);
+ if (!MD || !MD->isInstance())
+ return;
+
+ const auto *ClassDecl = MD->getParent()->getDefinition();
+ if (!ClassDecl)
+ return;
+
+ const auto UseFields = [&](const CXXRecordDecl *RD) {
+ const auto *MemberCall = dyn_cast_or_null<CXXMemberCallExpr>(Call);
+ if (!MemberCall)
+ return;
+
+ const auto *This =
+ dyn_cast_or_null<CXXThisExpr>(MemberCall->getImplicitObjectArgument());
+ if (!This)
+ return;
----------------
usx95 wrote:
This looks correct except that this should happen outside the lambda and early exit if this is not the case.
Also you can inline the `This` decl into the if condition.
`if(!isa_and_present<CXXThisExpr>(MemberCall->getImplicitObjectArgument())) return;`
Does the LifetimeSafetyTest.cpp still fails ? Ideally we would like to revert the change in that file.
https://github.com/llvm/llvm-project/pull/191731
More information about the cfe-commits
mailing list