52
52
#include " clang/AST/DeclTemplate.h"
53
53
#include " clang/AST/Expr.h"
54
54
#include " clang/AST/ExprCXX.h"
55
-
56
55
#include " clang/AST/ParentMap.h"
57
56
#include " clang/ASTMatchers/ASTMatchFinder.h"
58
57
#include " clang/ASTMatchers/ASTMatchers.h"
@@ -1116,6 +1115,15 @@ class EscapeTrackedCallback final : public SymbolVisitor {
1116
1115
1117
1116
explicit EscapeTrackedCallback (ProgramStateRef S) : State(std::move(S)) {}
1118
1117
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
+
1119
1127
public:
1120
1128
// / Escape tracked regions reachable from the given roots.
1121
1129
static ProgramStateRef
@@ -1125,19 +1133,10 @@ class EscapeTrackedCallback final : public SymbolVisitor {
1125
1133
for (const MemRegion *R : Roots) {
1126
1134
State->scanReachableSymbols (loc::MemRegionVal (R), Visitor);
1127
1135
}
1128
- return Visitor.getState () ;
1136
+ return Visitor.State ;
1129
1137
}
1130
1138
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 ;
1141
1140
};
1142
1141
} // end anonymous namespace
1143
1142
@@ -3111,17 +3110,13 @@ void MallocChecker::checkDeadSymbols(SymbolReaper &SymReaper,
3111
3110
C.addTransition (state->set <RegionState>(RS), N);
3112
3111
}
3113
3112
3114
- // Use isWithinStdNamespace from CheckerHelpers.h instead of custom
3115
- // implementation
3116
-
3117
3113
// Allowlist of owning smart pointers we want to recognize.
3118
3114
// Start with unique_ptr and shared_ptr. (intentionally exclude weak_ptr)
3119
3115
static bool isSmartOwningPtrType (QualType QT) {
3120
3116
QT = QT->getCanonicalTypeUnqualified ();
3121
3117
3122
3118
// 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>()) {
3125
3120
const TemplateDecl *TD = TST->getTemplateName ().getAsTemplateDecl ();
3126
3121
if (!TD)
3127
3122
return false ;
@@ -3139,8 +3134,7 @@ static bool isSmartOwningPtrType(QualType QT) {
3139
3134
}
3140
3135
3141
3136
// Also try RecordType (for custom smart pointer implementations)
3142
- const auto *RD = QT->getAsCXXRecordDecl ();
3143
- if (RD) {
3137
+ if (const auto *RD = QT->getAsCXXRecordDecl ()) {
3144
3138
StringRef Name = RD->getName ();
3145
3139
if (Name == " unique_ptr" || Name == " shared_ptr" ) {
3146
3140
// Accept any custom unique_ptr or shared_ptr implementation
0 commit comments