[clang] 684778b - [LifetimeSafety] Move unique_ptr::release() handling to handleMovedArgsInCall (#181005)

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 16 12:14:54 PST 2026


Author: Utkarsh Saxena
Date: 2026-02-16T20:14:50Z
New Revision: 684778b71094c3a119f00aeaf423c98937f2ae57

URL: https://github.com/llvm/llvm-project/commit/684778b71094c3a119f00aeaf423c98937f2ae57
DIFF: https://github.com/llvm/llvm-project/commit/684778b71094c3a119f00aeaf423c98937f2ae57.diff

LOG: [LifetimeSafety] Move unique_ptr::release() handling to handleMovedArgsInCall (#181005)

Added: 
    

Modified: 
    clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp

Removed: 
    


################################################################################
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;


        


More information about the cfe-commits mailing list