[clang] [analyzer] MallocChecker – Fix false positive leak for smart pointers in temporary objects (PR #152751)
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 9 11:26:27 PDT 2025
================
@@ -3068,11 +3111,174 @@ void MallocChecker::checkDeadSymbols(SymbolReaper &SymReaper,
C.addTransition(state->set<RegionState>(RS), N);
}
+// Use isWithinStdNamespace from CheckerHelpers.h instead of custom
+// implementation
+
+// Allowlist of owning smart pointers we want to recognize.
+// Start with unique_ptr and shared_ptr. (intentionally exclude weak_ptr)
+static bool isSmartOwningPtrType(QualType QT) {
+ QT = QT->getCanonicalTypeUnqualified();
+
+ // First try TemplateSpecializationType (for std smart pointers)
+ const auto *TST = QT->getAs<TemplateSpecializationType>();
+ if (TST) {
----------------
steakhal wrote:
```suggestion
if (const auto *TST = QT->getAs<TemplateSpecializationType>()) {
```
https://github.com/llvm/llvm-project/pull/152751
More information about the cfe-commits
mailing list