[clang] [LifetimeSafety] Model scope-exit destructor and cleanup callback as a use (PR #204650)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 19 19:26:47 PDT 2026


================
@@ -807,6 +786,19 @@ void FactsGenerator::handleLifetimeEnds(const CFGLifetimeEnds &LifetimeEnds) {
       ExpiredOID));
 }
 
+void FactsGenerator::handleCleanupFunction(
+    const CFGCleanupFunction &CleanupFunction) {
+  // A variable with __attribute__((cleanup(fn))) has fn(&var) called at scope
+  // exit; like a non-trivial destructor, that callback may read a borrow the
+  // variable holds, so model it as a use of the variable.
+  const VarDecl *VD = CleanupFunction.getVarDecl();
+  if (!VD || !hasOrigins(VD->getType()))
----------------
NeKon69 wrote:

Why do you not check for `isGslOwnerType` like you do in `handleLifetimeEnds`? I am a bit confused..

https://github.com/llvm/llvm-project/pull/204650


More information about the cfe-commits mailing list