From 57b4d9371be42b9f82cb528b5318dbb445fb068e Mon Sep 17 00:00:00 2001 From: Anton Yartsev Date: Tue, 10 Mar 2015 22:24:21 +0000 Subject: [PATCH] [analyzer] Make getCheckIfTracked() return either leak or regular checker. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@231863 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index b6db893cb5..41559989c1 100644 --- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -334,10 +334,13 @@ private: /// Tells if a given family/call/symbol is tracked by the current checker. /// Sets CheckKind to the kind of the checker responsible for this /// family/call/symbol. - Optional getCheckIfTracked(AllocationFamily Family) const; + Optional getCheckIfTracked(AllocationFamily Family, + bool IsALeakCheck = false) const; Optional getCheckIfTracked(CheckerContext &C, - const Stmt *AllocDeallocStmt) const; - Optional getCheckIfTracked(CheckerContext &C, SymbolRef Sym) const; + const Stmt *AllocDeallocStmt, + bool IsALeakCheck = false) const; + Optional getCheckIfTracked(CheckerContext &C, SymbolRef Sym, + bool IsALeakCheck = false) const; ///@} static bool SummarizeValue(raw_ostream &os, SVal V); static bool SummarizeRegion(raw_ostream &os, const MemRegion *MR); @@ -1342,7 +1345,8 @@ ProgramStateRef MallocChecker::FreeMemAux(CheckerContext &C, } Optional -MallocChecker::getCheckIfTracked(AllocationFamily Family) const { +MallocChecker::getCheckIfTracked(AllocationFamily Family, + bool IsALeakCheck) const { switch (Family) { case AF_Malloc: case AF_Alloca: @@ -1354,8 +1358,13 @@ MallocChecker::getCheckIfTracked(AllocationFamily Family) const { } case AF_CXXNew: case AF_CXXNewArray: { - if (ChecksEnabled[CK_NewDeleteChecker]) { - return CK_NewDeleteChecker; + if (IsALeakCheck) { + if (ChecksEnabled[CK_NewDeleteLeaksChecker]) + return CK_NewDeleteLeaksChecker; + } + else { + if (ChecksEnabled[CK_NewDeleteChecker]) + return CK_NewDeleteChecker; } return Optional(); } @@ -1368,16 +1377,18 @@ MallocChecker::getCheckIfTracked(AllocationFamily Family) const { Optional MallocChecker::getCheckIfTracked(CheckerContext &C, - const Stmt *AllocDeallocStmt) const { - return getCheckIfTracked(getAllocationFamily(C, AllocDeallocStmt)); + const Stmt *AllocDeallocStmt, + bool IsALeakCheck) const { + return getCheckIfTracked(getAllocationFamily(C, AllocDeallocStmt), + IsALeakCheck); } Optional -MallocChecker::getCheckIfTracked(CheckerContext &C, SymbolRef Sym) const { - +MallocChecker::getCheckIfTracked(CheckerContext &C, SymbolRef Sym, + bool IsALeakCheck) const { const RefState *RS = C.getState()->get(Sym); assert(RS); - return getCheckIfTracked(RS->getAllocationFamily()); + return getCheckIfTracked(RS->getAllocationFamily(), IsALeakCheck); } bool MallocChecker::SummarizeValue(raw_ostream &os, SVal V) { @@ -1906,17 +1917,14 @@ void MallocChecker::reportLeak(SymbolRef Sym, ExplodedNode *N, const RefState *RS = C.getState()->get(Sym); assert(RS && "cannot leak an untracked symbol"); AllocationFamily Family = RS->getAllocationFamily(); - Optional CheckKind = getCheckIfTracked(Family); - if (!CheckKind.hasValue()) + + if (Family == AF_Alloca) return; - // Special case for new and new[]; these are controlled by a separate checker - // flag so that they can be selectively disabled. - if (Family == AF_CXXNew || Family == AF_CXXNewArray) - if (!ChecksEnabled[CK_NewDeleteLeaksChecker]) - return; + Optional + CheckKind = getCheckIfTracked(Family, true); - if (RS->getAllocationFamily() == AF_Alloca) + if (!CheckKind.hasValue()) return; assert(N); @@ -2529,6 +2537,8 @@ void MallocChecker::printState(raw_ostream &Out, ProgramStateRef State, const RefState *RefS = State->get(I.getKey()); AllocationFamily Family = RefS->getAllocationFamily(); Optional CheckKind = getCheckIfTracked(Family); + if (!CheckKind.hasValue()) + CheckKind = getCheckIfTracked(Family, true); I.getKey()->dumpToStream(Out); Out << " : "; -- 2.40.0