================ @@ -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) { + const TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl(); + if (!TD) + return false; + + const auto *ND = dyn_cast_or_null<NamedDecl>(TD->getTemplatedDecl()); + if (!ND) + return false; + + // Check if it's in std namespace + if (!isWithinStdNamespace(ND)) + return false; + + StringRef Name = ND->getName(); + return Name == "unique_ptr" || Name == "shared_ptr"; + } + + // Also try RecordType (for custom smart pointer implementations) + const auto *RD = QT->getAsCXXRecordDecl(); + if (RD) { + StringRef Name = RD->getName(); + if (Name == "unique_ptr" || Name == "shared_ptr") { ---------------- ivanmurashko wrote:
I introduced `isSmartPtrName` lambda and eliminate the dublication https://github.com/llvm/llvm-project/pull/152751 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits