https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/181005
None >From 7a1489fd021abe42231736afb40a6d458f848979 Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena <[email protected]> Date: Wed, 11 Feb 2026 19:53:42 +0000 Subject: [PATCH] move_unique_ptr_release --- .../LifetimeSafety/FactsGenerator.cpp | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp index b69f69ddbae34..0b25a6a401e08 100644 --- a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp +++ b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp @@ -523,9 +523,20 @@ void FactsGenerator::handleGSLPointerConstruction(const CXXConstructExpr *CCE) { void FactsGenerator::handleMovedArgsInCall(const FunctionDecl *FD, ArrayRef<const Expr *> Args) { unsigned IsInstance = 0; - if (const auto *Method = dyn_cast<CXXMethodDecl>(FD); - Method && Method->isInstance() && !isa<CXXConstructorDecl>(FD)) + if (const auto *MD = dyn_cast<CXXMethodDecl>(FD); + MD && MD->isInstance() && !isa<CXXConstructorDecl>(FD)) { IsInstance = 1; + // std::unique_ptr::release() transfers ownership. + // Treat it as a move to prevent false-positive warnings when the unique_ptr + // destructor runs after ownership has been transferred. + if (isUniquePtrRelease(*MD)) { + const Expr *UniquePtrExpr = Args[0]; + OriginList *MovedOrigins = getOriginsList(*UniquePtrExpr); + if (MovedOrigins) + CurrentBlockFacts.push_back(FactMgr.createFact<MovedOriginFact>( + UniquePtrExpr, MovedOrigins->getOuterOriginID())); + } + } // Skip 'this' arg as it cannot be moved. for (unsigned I = IsInstance; @@ -549,16 +560,6 @@ void FactsGenerator::handleInvalidatingCall(const Expr *Call, const auto *MD = dyn_cast<CXXMethodDecl>(FD); if (!MD || !MD->isInstance()) return; - // std::unique_ptr::release() transfers ownership. - // Treat it as a move to prevent false-positive warnings when the unique_ptr - // destructor runs after ownership has been transferred. - if (isUniquePtrRelease(*MD)) { - const Expr *UniquePtrExpr = Args[0]; - OriginList *MovedOrigins = getOriginsList(*UniquePtrExpr); - if (MovedOrigins) - CurrentBlockFacts.push_back(FactMgr.createFact<MovedOriginFact>( - UniquePtrExpr, MovedOrigins->getOuterOriginID())); - } if (!isContainerInvalidationMethod(*MD)) return; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
