[clang] [analyzer] MallocChecker – Fix false positive leak for smart pointers in temporary objects (PR #152751)
Donát Nagy via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 29 05:40:27 PDT 2025
================
@@ -1096,6 +1104,54 @@ class StopTrackingCallback final : public SymbolVisitor {
return true;
}
};
+
+/// EscapeTrackedCallback - A SymbolVisitor that marks allocated symbols as
+/// escaped.
+///
+/// This visitor is used to suppress false positive leak reports when smart
+/// pointers are nested in temporary objects passed by value to functions. When
+/// the analyzer can't see the destructor calls for temporary objects, it may
+/// incorrectly report leaks for memory that will be properly freed by the smart
+/// pointer destructors.
+///
+/// The visitor traverses reachable symbols from a given set of memory regions
+/// (typically smart pointer field regions) and marks any allocated symbols as
+/// escaped. Escaped symbols are not reported as leaks by checkDeadSymbols.
+class EscapeTrackedCallback final : public SymbolVisitor {
+ ProgramStateRef State;
+
+ explicit EscapeTrackedCallback(ProgramStateRef S) : State(std::move(S)) {}
+
+ bool VisitSymbol(SymbolRef Sym) override {
----------------
NagyDonat wrote:
@ivanmurashko it seems that you forgot to update this part of the code in https://github.com/llvm/llvm-project/commit/08a24effa0007135844fb37d0ecf6e8f1972a45b, because this method is still `private`.
https://github.com/llvm/llvm-project/pull/152751
More information about the cfe-commits
mailing list