================
@@ -792,6 +757,20 @@ void FactsGenerator::handleLifetimeEnds(const 
CFGLifetimeEnds &LifetimeEnds) {
   const VarDecl *LifetimeEndsVD = LifetimeEnds.getVarDecl();
   if (!LifetimeEndsVD)
     return;
+  // A non-trivial destructor at scope exit may read a borrow the object holds
+  // (e.g. a [[gsl::Pointer]] whose out-of-line ~T() dereferences its view). 
The
+  // analysis never sees that body, so model the destruction as a use, keeping
+  // the borrow live to that point so a borrowed-from object destroyed earlier
+  // (reverse-declaration order) is reported. Owners are excluded: their
+  // destruction frees their own storage (modeled by the ExpireFact), not a
+  // borrow into another object.
+  QualType VDTy = LifetimeEndsVD->getType();
+  if (const CXXRecordDecl *RD = VDTy->getAsCXXRecordDecl();
+      RD && RD->hasDefinition() && RD->hasNonTrivialDestructor() &&
+      !isGslOwnerType(VDTy) && hasOrigins(VDTy))
----------------
Xazax-hun wrote:

Added.

https://github.com/llvm/llvm-project/pull/204650
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to