5252#include " clang/AST/DeclTemplate.h"
5353#include " clang/AST/Expr.h"
5454#include " clang/AST/ExprCXX.h"
55-
5655#include " clang/AST/ParentMap.h"
5756#include " clang/ASTMatchers/ASTMatchFinder.h"
5857#include " clang/ASTMatchers/ASTMatchers.h"
@@ -1116,6 +1115,15 @@ class EscapeTrackedCallback final : public SymbolVisitor {
11161115
11171116 explicit EscapeTrackedCallback (ProgramStateRef S) : State(std::move(S)) {}
11181117
1118+ bool VisitSymbol (SymbolRef Sym) override {
1119+ if (const RefState *RS = State->get <RegionState>(Sym)) {
1120+ if (RS->isAllocated () || RS->isAllocatedOfSizeZero ()) {
1121+ State = State->set <RegionState>(Sym, RefState::getEscaped (RS));
1122+ }
1123+ }
1124+ return true ;
1125+ }
1126+
11191127public:
11201128 // / Escape tracked regions reachable from the given roots.
11211129 static ProgramStateRef
@@ -1125,19 +1133,10 @@ class EscapeTrackedCallback final : public SymbolVisitor {
11251133 for (const MemRegion *R : Roots) {
11261134 State->scanReachableSymbols (loc::MemRegionVal (R), Visitor);
11271135 }
1128- return Visitor.getState () ;
1136+ return Visitor.State ;
11291137 }
11301138
1131- ProgramStateRef getState () const { return State; }
1132-
1133- bool VisitSymbol (SymbolRef Sym) override {
1134- if (const RefState *RS = State->get <RegionState>(Sym)) {
1135- if (RS->isAllocated () || RS->isAllocatedOfSizeZero ()) {
1136- State = State->set <RegionState>(Sym, RefState::getEscaped (RS));
1137- }
1138- }
1139- return true ;
1140- }
1139+ friend class SymbolVisitor ;
11411140};
11421141} // end anonymous namespace
11431142
@@ -3111,17 +3110,13 @@ void MallocChecker::checkDeadSymbols(SymbolReaper &SymReaper,
31113110 C.addTransition (state->set <RegionState>(RS), N);
31123111}
31133112
3114- // Use isWithinStdNamespace from CheckerHelpers.h instead of custom
3115- // implementation
3116-
31173113// Allowlist of owning smart pointers we want to recognize.
31183114// Start with unique_ptr and shared_ptr. (intentionally exclude weak_ptr)
31193115static bool isSmartOwningPtrType (QualType QT) {
31203116 QT = QT->getCanonicalTypeUnqualified ();
31213117
31223118 // First try TemplateSpecializationType (for std smart pointers)
3123- const auto *TST = QT->getAs <TemplateSpecializationType>();
3124- if (TST) {
3119+ if (const auto *TST = QT->getAs <TemplateSpecializationType>()) {
31253120 const TemplateDecl *TD = TST->getTemplateName ().getAsTemplateDecl ();
31263121 if (!TD)
31273122 return false ;
@@ -3139,8 +3134,7 @@ static bool isSmartOwningPtrType(QualType QT) {
31393134 }
31403135
31413136 // Also try RecordType (for custom smart pointer implementations)
3142- const auto *RD = QT->getAsCXXRecordDecl ();
3143- if (RD) {
3137+ if (const auto *RD = QT->getAsCXXRecordDecl ()) {
31443138 StringRef Name = RD->getName ();
31453139 if (Name == " unique_ptr" || Name == " shared_ptr" ) {
31463140 // Accept any custom unique_ptr or shared_ptr implementation
0 commit comments