2018-02-27 07:15:52 +08:00
|
|
|
//===- CheckerManager.cpp - Static Analyzer Checker Manager ---------------===//
|
2011-02-15 02:13:31 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Defines the Static Analyzer Checker Manager.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/DeclBase.h"
|
2018-02-27 07:15:52 +08:00
|
|
|
#include "clang/AST/Stmt.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Analysis/ProgramPoint.h"
|
2018-02-27 07:15:52 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
2011-08-13 07:04:46 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/Checker.h"
|
2012-07-27 05:39:41 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
2018-02-27 07:15:52 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <vector>
|
2011-02-15 02:13:31 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace ento;
|
|
|
|
|
2011-03-01 03:49:17 +08:00
|
|
|
bool CheckerManager::hasPathSensitiveCheckers() const {
|
|
|
|
return !StmtCheckers.empty() ||
|
|
|
|
!PreObjCMessageCheckers.empty() ||
|
|
|
|
!PostObjCMessageCheckers.empty() ||
|
2012-07-03 03:28:16 +08:00
|
|
|
!PreCallCheckers.empty() ||
|
|
|
|
!PostCallCheckers.empty() ||
|
2011-03-01 03:49:17 +08:00
|
|
|
!LocationCheckers.empty() ||
|
|
|
|
!BindCheckers.empty() ||
|
|
|
|
!EndAnalysisCheckers.empty() ||
|
2013-01-03 08:25:29 +08:00
|
|
|
!EndFunctionCheckers.empty() ||
|
2011-03-01 03:49:17 +08:00
|
|
|
!BranchConditionCheckers.empty() ||
|
|
|
|
!LiveSymbolsCheckers.empty() ||
|
|
|
|
!DeadSymbolsCheckers.empty() ||
|
|
|
|
!RegionChangesCheckers.empty() ||
|
|
|
|
!EvalAssumeCheckers.empty() ||
|
2012-10-13 13:05:13 +08:00
|
|
|
!EvalCallCheckers.empty();
|
2011-03-01 03:49:17 +08:00
|
|
|
}
|
|
|
|
|
2011-03-01 01:36:09 +08:00
|
|
|
void CheckerManager::finishedCheckerRegistration() {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// Make sure that for every event that has listeners, there is at least
|
|
|
|
// one dispatcher registered for it.
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto &Event : Events)
|
|
|
|
assert(Event.second.HasDispatcher &&
|
|
|
|
"No dispatcher registered for an event");
|
2011-03-01 01:36:09 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Functions for running checkers for AST traversing..
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-02-18 05:39:24 +08:00
|
|
|
void CheckerManager::runCheckersOnASTDecl(const Decl *D, AnalysisManager& mgr,
|
|
|
|
BugReporter &BR) {
|
|
|
|
assert(D);
|
|
|
|
|
|
|
|
unsigned DeclKind = D->getKind();
|
2014-05-27 10:45:47 +08:00
|
|
|
CachedDeclCheckers *checkers = nullptr;
|
2011-02-18 05:39:24 +08:00
|
|
|
CachedDeclCheckersMapTy::iterator CCI = CachedDeclCheckersMap.find(DeclKind);
|
|
|
|
if (CCI != CachedDeclCheckersMap.end()) {
|
|
|
|
checkers = &(CCI->second);
|
|
|
|
} else {
|
|
|
|
// Find the checkers that should run for this Decl and cache them.
|
|
|
|
checkers = &CachedDeclCheckersMap[DeclKind];
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto &info : DeclCheckers)
|
2011-02-18 05:39:24 +08:00
|
|
|
if (info.IsForDeclFn(D))
|
2011-02-23 01:30:38 +08:00
|
|
|
checkers->push_back(info.CheckFn);
|
2011-02-18 05:39:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(checkers);
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto checker : *checkers)
|
|
|
|
checker(D, mgr, BR);
|
2011-02-18 05:39:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckerManager::runCheckersOnASTBody(const Decl *D, AnalysisManager& mgr,
|
|
|
|
BugReporter &BR) {
|
|
|
|
assert(D && D->hasBody());
|
|
|
|
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto BodyChecker : BodyCheckers)
|
|
|
|
BodyChecker(D, mgr, BR);
|
2011-02-23 01:30:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Functions for running checkers for path-sensitive checking.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
template <typename CHECK_CTX>
|
2011-02-24 03:38:41 +08:00
|
|
|
static void expandGraphWithCheckers(CHECK_CTX checkCtx,
|
|
|
|
ExplodedNodeSet &Dst,
|
2011-02-24 03:38:45 +08:00
|
|
|
const ExplodedNodeSet &Src) {
|
2011-10-25 02:25:58 +08:00
|
|
|
const NodeBuilderContext &BldrCtx = checkCtx.Eng.getBuilderContext();
|
|
|
|
if (Src.empty())
|
|
|
|
return;
|
2011-02-23 01:30:38 +08:00
|
|
|
|
2011-02-24 03:38:39 +08:00
|
|
|
typename CHECK_CTX::CheckersTy::const_iterator
|
|
|
|
I = checkCtx.checkers_begin(), E = checkCtx.checkers_end();
|
|
|
|
if (I == E) {
|
2011-02-23 01:30:38 +08:00
|
|
|
Dst.insert(Src);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-24 03:38:45 +08:00
|
|
|
ExplodedNodeSet Tmp1, Tmp2;
|
|
|
|
const ExplodedNodeSet *PrevSet = &Src;
|
2011-02-23 01:30:38 +08:00
|
|
|
|
2011-02-24 03:38:39 +08:00
|
|
|
for (; I != E; ++I) {
|
2014-05-27 10:45:47 +08:00
|
|
|
ExplodedNodeSet *CurrSet = nullptr;
|
2011-02-23 01:30:38 +08:00
|
|
|
if (I+1 == E)
|
|
|
|
CurrSet = &Dst;
|
|
|
|
else {
|
2011-02-24 03:38:45 +08:00
|
|
|
CurrSet = (PrevSet == &Tmp1) ? &Tmp2 : &Tmp1;
|
2011-02-23 01:30:38 +08:00
|
|
|
CurrSet->clear();
|
|
|
|
}
|
|
|
|
|
2011-10-25 02:25:58 +08:00
|
|
|
NodeBuilder B(*PrevSet, *CurrSet, BldrCtx);
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto &NI : *PrevSet)
|
|
|
|
checkCtx.runChecker(*I, B, NI);
|
2011-10-25 02:25:58 +08:00
|
|
|
|
|
|
|
// If all the produced transitions are sinks, stop.
|
|
|
|
if (CurrSet->empty())
|
|
|
|
return;
|
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
// Update which NodeSet is the current one.
|
|
|
|
PrevSet = CurrSet;
|
2011-02-18 05:39:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
namespace {
|
2018-02-27 07:15:52 +08:00
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
struct CheckStmtContext {
|
2018-02-27 07:15:52 +08:00
|
|
|
using CheckersTy = SmallVectorImpl<CheckerManager::CheckStmtFunc>;
|
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
bool IsPreVisit;
|
|
|
|
const CheckersTy &Checkers;
|
|
|
|
const Stmt *S;
|
|
|
|
ExprEngine &Eng;
|
2012-07-31 07:39:47 +08:00
|
|
|
bool WasInlined;
|
2011-02-23 01:30:38 +08:00
|
|
|
|
|
|
|
CheckStmtContext(bool isPreVisit, const CheckersTy &checkers,
|
2012-03-23 14:26:56 +08:00
|
|
|
const Stmt *s, ExprEngine &eng, bool wasInlined = false)
|
2018-02-27 07:15:52 +08:00
|
|
|
: IsPreVisit(isPreVisit), Checkers(checkers), S(s), Eng(eng),
|
|
|
|
WasInlined(wasInlined) {}
|
|
|
|
|
|
|
|
CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
|
|
|
|
CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
|
2011-02-23 01:30:38 +08:00
|
|
|
|
|
|
|
void runChecker(CheckerManager::CheckStmtFunc checkFn,
|
2011-10-25 02:25:58 +08:00
|
|
|
NodeBuilder &Bldr, ExplodedNode *Pred) {
|
2011-02-23 01:30:38 +08:00
|
|
|
// FIXME: Remove respondsToCallback from CheckerContext;
|
2011-10-08 05:52:33 +08:00
|
|
|
ProgramPoint::Kind K = IsPreVisit ? ProgramPoint::PreStmtKind :
|
|
|
|
ProgramPoint::PostStmtKind;
|
|
|
|
const ProgramPoint &L = ProgramPoint::getProgramPoint(S, K,
|
|
|
|
Pred->getLocationContext(), checkFn.Checker);
|
2012-07-31 07:39:47 +08:00
|
|
|
CheckerContext C(Bldr, Eng, Pred, L, WasInlined);
|
2011-02-23 01:30:38 +08:00
|
|
|
checkFn(S, C);
|
|
|
|
}
|
|
|
|
};
|
2018-02-27 07:15:52 +08:00
|
|
|
|
|
|
|
} // namespace
|
2011-02-23 01:30:38 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for visiting Stmts.
|
2011-02-23 01:30:38 +08:00
|
|
|
void CheckerManager::runCheckersForStmt(bool isPreVisit,
|
|
|
|
ExplodedNodeSet &Dst,
|
2011-02-24 03:38:45 +08:00
|
|
|
const ExplodedNodeSet &Src,
|
2011-02-23 01:30:38 +08:00
|
|
|
const Stmt *S,
|
2012-03-23 14:26:56 +08:00
|
|
|
ExprEngine &Eng,
|
2012-07-31 07:39:47 +08:00
|
|
|
bool WasInlined) {
|
2013-08-17 05:57:06 +08:00
|
|
|
CheckStmtContext C(isPreVisit, getCachedStmtCheckersFor(S, isPreVisit),
|
2012-07-31 07:39:47 +08:00
|
|
|
S, Eng, WasInlined);
|
2011-02-24 03:38:41 +08:00
|
|
|
expandGraphWithCheckers(C, Dst, Src);
|
2011-02-23 01:30:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2018-02-27 07:15:52 +08:00
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
struct CheckObjCMessageContext {
|
2018-02-27 07:15:52 +08:00
|
|
|
using CheckersTy = std::vector<CheckerManager::CheckObjCMessageFunc>;
|
2015-09-15 09:13:53 +08:00
|
|
|
|
|
|
|
ObjCMessageVisitKind Kind;
|
|
|
|
bool WasInlined;
|
2011-02-23 01:30:38 +08:00
|
|
|
const CheckersTy &Checkers;
|
2012-07-03 03:28:04 +08:00
|
|
|
const ObjCMethodCall &Msg;
|
2011-02-23 01:30:38 +08:00
|
|
|
ExprEngine &Eng;
|
|
|
|
|
2015-09-15 09:13:53 +08:00
|
|
|
CheckObjCMessageContext(ObjCMessageVisitKind visitKind,
|
|
|
|
const CheckersTy &checkers,
|
2012-07-31 07:39:47 +08:00
|
|
|
const ObjCMethodCall &msg, ExprEngine &eng,
|
|
|
|
bool wasInlined)
|
2018-02-27 07:15:52 +08:00
|
|
|
: Kind(visitKind), WasInlined(wasInlined), Checkers(checkers), Msg(msg),
|
|
|
|
Eng(eng) {}
|
|
|
|
|
|
|
|
CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
|
|
|
|
CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
|
2011-02-23 01:30:38 +08:00
|
|
|
|
|
|
|
void runChecker(CheckerManager::CheckObjCMessageFunc checkFn,
|
2011-10-25 02:25:58 +08:00
|
|
|
NodeBuilder &Bldr, ExplodedNode *Pred) {
|
2015-09-15 09:13:53 +08:00
|
|
|
bool IsPreVisit;
|
|
|
|
|
|
|
|
switch (Kind) {
|
|
|
|
case ObjCMessageVisitKind::Pre:
|
|
|
|
IsPreVisit = true;
|
|
|
|
break;
|
|
|
|
case ObjCMessageVisitKind::MessageNil:
|
|
|
|
case ObjCMessageVisitKind::Post:
|
|
|
|
IsPreVisit = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-07-31 04:22:09 +08:00
|
|
|
const ProgramPoint &L = Msg.getProgramPoint(IsPreVisit,checkFn.Checker);
|
2012-07-31 07:39:47 +08:00
|
|
|
CheckerContext C(Bldr, Eng, Pred, L, WasInlined);
|
2011-10-08 05:52:33 +08:00
|
|
|
|
2012-07-31 04:22:09 +08:00
|
|
|
checkFn(*Msg.cloneWithState<ObjCMethodCall>(Pred->getState()), C);
|
2011-02-23 01:30:38 +08:00
|
|
|
}
|
|
|
|
};
|
2018-02-27 07:15:52 +08:00
|
|
|
|
|
|
|
} // namespace
|
2011-02-23 01:30:38 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for visiting obj-c messages.
|
2015-09-15 09:13:53 +08:00
|
|
|
void CheckerManager::runCheckersForObjCMessage(ObjCMessageVisitKind visitKind,
|
2011-02-23 01:30:38 +08:00
|
|
|
ExplodedNodeSet &Dst,
|
2011-02-24 03:38:45 +08:00
|
|
|
const ExplodedNodeSet &Src,
|
2012-07-03 03:28:04 +08:00
|
|
|
const ObjCMethodCall &msg,
|
2012-07-31 07:39:47 +08:00
|
|
|
ExprEngine &Eng,
|
|
|
|
bool WasInlined) {
|
2015-09-15 09:13:53 +08:00
|
|
|
auto &checkers = getObjCMessageCheckers(visitKind);
|
|
|
|
CheckObjCMessageContext C(visitKind, checkers, msg, Eng, WasInlined);
|
2011-02-24 03:38:41 +08:00
|
|
|
expandGraphWithCheckers(C, Dst, Src);
|
2011-02-23 01:30:38 +08:00
|
|
|
}
|
|
|
|
|
2015-09-15 09:13:53 +08:00
|
|
|
const std::vector<CheckerManager::CheckObjCMessageFunc> &
|
|
|
|
CheckerManager::getObjCMessageCheckers(ObjCMessageVisitKind Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
case ObjCMessageVisitKind::Pre:
|
|
|
|
return PreObjCMessageCheckers;
|
|
|
|
break;
|
|
|
|
case ObjCMessageVisitKind::Post:
|
|
|
|
return PostObjCMessageCheckers;
|
|
|
|
case ObjCMessageVisitKind::MessageNil:
|
|
|
|
return ObjCMessageNilCheckers;
|
|
|
|
}
|
2015-09-15 22:11:32 +08:00
|
|
|
llvm_unreachable("Unknown Kind");
|
2015-09-15 09:13:53 +08:00
|
|
|
}
|
2018-02-27 07:15:52 +08:00
|
|
|
|
2012-07-03 03:28:16 +08:00
|
|
|
namespace {
|
2018-02-27 07:15:52 +08:00
|
|
|
|
2012-07-03 03:28:16 +08:00
|
|
|
// FIXME: This has all the same signatures as CheckObjCMessageContext.
|
|
|
|
// Is there a way we can merge the two?
|
|
|
|
struct CheckCallContext {
|
2018-02-27 07:15:52 +08:00
|
|
|
using CheckersTy = std::vector<CheckerManager::CheckCallFunc>;
|
|
|
|
|
2012-07-31 07:39:47 +08:00
|
|
|
bool IsPreVisit, WasInlined;
|
2012-07-03 03:28:16 +08:00
|
|
|
const CheckersTy &Checkers;
|
|
|
|
const CallEvent &Call;
|
|
|
|
ExprEngine &Eng;
|
|
|
|
|
|
|
|
CheckCallContext(bool isPreVisit, const CheckersTy &checkers,
|
2012-07-31 07:39:47 +08:00
|
|
|
const CallEvent &call, ExprEngine &eng,
|
|
|
|
bool wasInlined)
|
2018-02-27 07:15:52 +08:00
|
|
|
: IsPreVisit(isPreVisit), WasInlined(wasInlined), Checkers(checkers),
|
|
|
|
Call(call), Eng(eng) {}
|
|
|
|
|
|
|
|
CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
|
|
|
|
CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
|
2012-07-03 03:28:16 +08:00
|
|
|
|
|
|
|
void runChecker(CheckerManager::CheckCallFunc checkFn,
|
|
|
|
NodeBuilder &Bldr, ExplodedNode *Pred) {
|
2012-07-31 04:22:09 +08:00
|
|
|
const ProgramPoint &L = Call.getProgramPoint(IsPreVisit,checkFn.Checker);
|
2012-07-31 07:39:47 +08:00
|
|
|
CheckerContext C(Bldr, Eng, Pred, L, WasInlined);
|
2012-07-03 03:28:16 +08:00
|
|
|
|
2012-07-31 04:22:09 +08:00
|
|
|
checkFn(*Call.cloneWithState(Pred->getState()), C);
|
2012-07-03 03:28:16 +08:00
|
|
|
}
|
|
|
|
};
|
2018-02-27 07:15:52 +08:00
|
|
|
|
|
|
|
} // namespace
|
2012-07-03 03:28:16 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for visiting an abstract call event.
|
2012-07-03 03:28:16 +08:00
|
|
|
void CheckerManager::runCheckersForCallEvent(bool isPreVisit,
|
|
|
|
ExplodedNodeSet &Dst,
|
|
|
|
const ExplodedNodeSet &Src,
|
|
|
|
const CallEvent &Call,
|
2012-07-31 07:39:47 +08:00
|
|
|
ExprEngine &Eng,
|
|
|
|
bool WasInlined) {
|
2012-07-03 03:28:16 +08:00
|
|
|
CheckCallContext C(isPreVisit,
|
|
|
|
isPreVisit ? PreCallCheckers
|
|
|
|
: PostCallCheckers,
|
2012-07-31 07:39:47 +08:00
|
|
|
Call, Eng, WasInlined);
|
2012-07-03 03:28:16 +08:00
|
|
|
expandGraphWithCheckers(C, Dst, Src);
|
|
|
|
}
|
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
namespace {
|
2018-02-27 07:15:52 +08:00
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
struct CheckLocationContext {
|
2018-02-27 07:15:52 +08:00
|
|
|
using CheckersTy = std::vector<CheckerManager::CheckLocationFunc>;
|
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
const CheckersTy &Checkers;
|
|
|
|
SVal Loc;
|
|
|
|
bool IsLoad;
|
2012-04-07 06:10:18 +08:00
|
|
|
const Stmt *NodeEx; /* Will become a CFGStmt */
|
|
|
|
const Stmt *BoundEx;
|
2011-02-23 01:30:38 +08:00
|
|
|
ExprEngine &Eng;
|
|
|
|
|
|
|
|
CheckLocationContext(const CheckersTy &checkers,
|
2012-04-07 06:10:18 +08:00
|
|
|
SVal loc, bool isLoad, const Stmt *NodeEx,
|
|
|
|
const Stmt *BoundEx,
|
|
|
|
ExprEngine &eng)
|
2018-02-27 07:15:52 +08:00
|
|
|
: Checkers(checkers), Loc(loc), IsLoad(isLoad), NodeEx(NodeEx),
|
|
|
|
BoundEx(BoundEx), Eng(eng) {}
|
|
|
|
|
|
|
|
CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
|
|
|
|
CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
|
2011-02-23 01:30:38 +08:00
|
|
|
|
|
|
|
void runChecker(CheckerManager::CheckLocationFunc checkFn,
|
2011-10-25 02:25:58 +08:00
|
|
|
NodeBuilder &Bldr, ExplodedNode *Pred) {
|
2011-10-08 05:52:33 +08:00
|
|
|
ProgramPoint::Kind K = IsLoad ? ProgramPoint::PreLoadKind :
|
|
|
|
ProgramPoint::PreStoreKind;
|
2012-04-07 06:10:18 +08:00
|
|
|
const ProgramPoint &L =
|
|
|
|
ProgramPoint::getProgramPoint(NodeEx, K,
|
|
|
|
Pred->getLocationContext(),
|
|
|
|
checkFn.Checker);
|
2011-10-26 03:57:06 +08:00
|
|
|
CheckerContext C(Bldr, Eng, Pred, L);
|
2012-04-07 06:10:18 +08:00
|
|
|
checkFn(Loc, IsLoad, BoundEx, C);
|
2011-02-23 01:30:38 +08:00
|
|
|
}
|
|
|
|
};
|
2018-02-27 07:15:52 +08:00
|
|
|
|
|
|
|
} // namespace
|
2011-02-18 05:39:24 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for load/store of a location.
|
2011-10-25 02:26:19 +08:00
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
void CheckerManager::runCheckersForLocation(ExplodedNodeSet &Dst,
|
2011-02-24 03:38:45 +08:00
|
|
|
const ExplodedNodeSet &Src,
|
2011-02-23 01:30:38 +08:00
|
|
|
SVal location, bool isLoad,
|
2012-04-07 06:10:18 +08:00
|
|
|
const Stmt *NodeEx,
|
|
|
|
const Stmt *BoundEx,
|
|
|
|
ExprEngine &Eng) {
|
|
|
|
CheckLocationContext C(LocationCheckers, location, isLoad, NodeEx,
|
|
|
|
BoundEx, Eng);
|
2011-02-24 03:38:41 +08:00
|
|
|
expandGraphWithCheckers(C, Dst, Src);
|
2011-02-18 05:39:24 +08:00
|
|
|
}
|
|
|
|
|
2011-02-28 09:26:35 +08:00
|
|
|
namespace {
|
2018-02-27 07:15:52 +08:00
|
|
|
|
2011-02-28 09:26:35 +08:00
|
|
|
struct CheckBindContext {
|
2018-02-27 07:15:52 +08:00
|
|
|
using CheckersTy = std::vector<CheckerManager::CheckBindFunc>;
|
|
|
|
|
2011-02-28 09:26:35 +08:00
|
|
|
const CheckersTy &Checkers;
|
|
|
|
SVal Loc;
|
|
|
|
SVal Val;
|
|
|
|
const Stmt *S;
|
|
|
|
ExprEngine &Eng;
|
2012-08-25 09:06:23 +08:00
|
|
|
const ProgramPoint &PP;
|
2011-02-28 09:26:35 +08:00
|
|
|
|
|
|
|
CheckBindContext(const CheckersTy &checkers,
|
2011-10-25 02:26:19 +08:00
|
|
|
SVal loc, SVal val, const Stmt *s, ExprEngine &eng,
|
2012-08-25 09:06:23 +08:00
|
|
|
const ProgramPoint &pp)
|
2018-02-27 07:15:52 +08:00
|
|
|
: Checkers(checkers), Loc(loc), Val(val), S(s), Eng(eng), PP(pp) {}
|
|
|
|
|
|
|
|
CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
|
|
|
|
CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
|
2011-02-28 09:26:35 +08:00
|
|
|
|
|
|
|
void runChecker(CheckerManager::CheckBindFunc checkFn,
|
2011-10-25 02:25:58 +08:00
|
|
|
NodeBuilder &Bldr, ExplodedNode *Pred) {
|
2012-08-25 09:06:23 +08:00
|
|
|
const ProgramPoint &L = PP.withTag(checkFn.Checker);
|
2011-10-26 03:57:06 +08:00
|
|
|
CheckerContext C(Bldr, Eng, Pred, L);
|
2011-10-08 05:52:33 +08:00
|
|
|
|
2011-10-06 08:43:15 +08:00
|
|
|
checkFn(Loc, Val, S, C);
|
2011-02-28 09:26:35 +08:00
|
|
|
}
|
|
|
|
};
|
2018-02-27 07:15:52 +08:00
|
|
|
|
|
|
|
} // namespace
|
2011-02-28 09:26:35 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for binding of a value to a location.
|
2011-02-28 09:26:35 +08:00
|
|
|
void CheckerManager::runCheckersForBind(ExplodedNodeSet &Dst,
|
|
|
|
const ExplodedNodeSet &Src,
|
|
|
|
SVal location, SVal val,
|
2011-10-25 02:26:19 +08:00
|
|
|
const Stmt *S, ExprEngine &Eng,
|
2012-08-25 09:06:23 +08:00
|
|
|
const ProgramPoint &PP) {
|
|
|
|
CheckBindContext C(BindCheckers, location, val, S, Eng, PP);
|
2011-02-28 09:26:35 +08:00
|
|
|
expandGraphWithCheckers(C, Dst, Src);
|
|
|
|
}
|
|
|
|
|
2011-02-23 15:19:23 +08:00
|
|
|
void CheckerManager::runCheckersForEndAnalysis(ExplodedGraph &G,
|
|
|
|
BugReporter &BR,
|
|
|
|
ExprEngine &Eng) {
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto EndAnalysisChecker : EndAnalysisCheckers)
|
|
|
|
EndAnalysisChecker(G, BR, Eng);
|
2011-02-23 15:19:23 +08:00
|
|
|
}
|
|
|
|
|
2016-02-19 09:35:10 +08:00
|
|
|
namespace {
|
2018-02-27 07:15:52 +08:00
|
|
|
|
2016-02-19 09:35:10 +08:00
|
|
|
struct CheckBeginFunctionContext {
|
2018-02-27 07:15:52 +08:00
|
|
|
using CheckersTy = std::vector<CheckerManager::CheckBeginFunctionFunc>;
|
|
|
|
|
2016-02-19 09:35:10 +08:00
|
|
|
const CheckersTy &Checkers;
|
|
|
|
ExprEngine &Eng;
|
|
|
|
const ProgramPoint &PP;
|
|
|
|
|
|
|
|
CheckBeginFunctionContext(const CheckersTy &Checkers, ExprEngine &Eng,
|
|
|
|
const ProgramPoint &PP)
|
|
|
|
: Checkers(Checkers), Eng(Eng), PP(PP) {}
|
|
|
|
|
2018-02-27 07:15:52 +08:00
|
|
|
CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
|
|
|
|
CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
|
|
|
|
|
2016-02-19 09:35:10 +08:00
|
|
|
void runChecker(CheckerManager::CheckBeginFunctionFunc checkFn,
|
|
|
|
NodeBuilder &Bldr, ExplodedNode *Pred) {
|
|
|
|
const ProgramPoint &L = PP.withTag(checkFn.Checker);
|
|
|
|
CheckerContext C(Bldr, Eng, Pred, L);
|
|
|
|
|
|
|
|
checkFn(C);
|
|
|
|
}
|
|
|
|
};
|
2018-02-27 07:15:52 +08:00
|
|
|
|
|
|
|
} // namespace
|
2016-02-19 09:35:10 +08:00
|
|
|
|
|
|
|
void CheckerManager::runCheckersForBeginFunction(ExplodedNodeSet &Dst,
|
|
|
|
const BlockEdge &L,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExprEngine &Eng) {
|
|
|
|
ExplodedNodeSet Src;
|
|
|
|
Src.insert(Pred);
|
|
|
|
CheckBeginFunctionContext C(BeginFunctionCheckers, Eng, L);
|
|
|
|
expandGraphWithCheckers(C, Dst, Src);
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for end of path.
|
2011-10-26 03:56:48 +08:00
|
|
|
// Note, We do not chain the checker output (like in expandGraphWithCheckers)
|
|
|
|
// for this callback since end of path nodes are expected to be final.
|
2013-01-03 08:25:29 +08:00
|
|
|
void CheckerManager::runCheckersForEndFunction(NodeBuilderContext &BC,
|
|
|
|
ExplodedNodeSet &Dst,
|
|
|
|
ExplodedNode *Pred,
|
2018-07-17 04:47:45 +08:00
|
|
|
ExprEngine &Eng,
|
|
|
|
const ReturnStmt *RS) {
|
2011-10-26 03:56:48 +08:00
|
|
|
// We define the builder outside of the loop bacause if at least one checkers
|
2015-09-08 11:50:52 +08:00
|
|
|
// creates a sucsessor for Pred, we do not need to generate an
|
2011-10-26 03:56:48 +08:00
|
|
|
// autotransition for it.
|
|
|
|
NodeBuilder Bldr(Pred, Dst, BC);
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto checkFn : EndFunctionCheckers) {
|
2011-10-26 03:56:48 +08:00
|
|
|
const ProgramPoint &L = BlockEntrance(BC.Block,
|
|
|
|
Pred->getLocationContext(),
|
|
|
|
checkFn.Checker);
|
2011-10-26 03:57:06 +08:00
|
|
|
CheckerContext C(Bldr, Eng, Pred, L);
|
2018-07-17 04:47:45 +08:00
|
|
|
checkFn(RS, C);
|
2011-02-24 05:04:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-26 03:56:54 +08:00
|
|
|
namespace {
|
2018-02-27 07:15:52 +08:00
|
|
|
|
2011-10-26 03:56:54 +08:00
|
|
|
struct CheckBranchConditionContext {
|
2018-02-27 07:15:52 +08:00
|
|
|
using CheckersTy = std::vector<CheckerManager::CheckBranchConditionFunc>;
|
|
|
|
|
2011-10-26 03:56:54 +08:00
|
|
|
const CheckersTy &Checkers;
|
|
|
|
const Stmt *Condition;
|
|
|
|
ExprEngine &Eng;
|
|
|
|
|
|
|
|
CheckBranchConditionContext(const CheckersTy &checkers,
|
|
|
|
const Stmt *Cond, ExprEngine &eng)
|
2018-02-27 07:15:52 +08:00
|
|
|
: Checkers(checkers), Condition(Cond), Eng(eng) {}
|
|
|
|
|
|
|
|
CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
|
|
|
|
CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
|
2011-10-26 03:56:54 +08:00
|
|
|
|
|
|
|
void runChecker(CheckerManager::CheckBranchConditionFunc checkFn,
|
|
|
|
NodeBuilder &Bldr, ExplodedNode *Pred) {
|
|
|
|
ProgramPoint L = PostCondition(Condition, Pred->getLocationContext(),
|
|
|
|
checkFn.Checker);
|
2011-10-26 03:57:06 +08:00
|
|
|
CheckerContext C(Bldr, Eng, Pred, L);
|
2011-10-26 03:56:54 +08:00
|
|
|
checkFn(Condition, C);
|
|
|
|
}
|
|
|
|
};
|
2018-02-27 07:15:52 +08:00
|
|
|
|
|
|
|
} // namespace
|
2011-10-26 03:56:54 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for branch condition.
|
2011-10-26 03:56:54 +08:00
|
|
|
void CheckerManager::runCheckersForBranchCondition(const Stmt *Condition,
|
|
|
|
ExplodedNodeSet &Dst,
|
2011-10-19 07:06:44 +08:00
|
|
|
ExplodedNode *Pred,
|
2011-02-28 09:27:33 +08:00
|
|
|
ExprEngine &Eng) {
|
2011-10-26 03:56:54 +08:00
|
|
|
ExplodedNodeSet Src;
|
|
|
|
Src.insert(Pred);
|
|
|
|
CheckBranchConditionContext C(BranchConditionCheckers, Condition, Eng);
|
|
|
|
expandGraphWithCheckers(C, Dst, Src);
|
2011-02-28 09:27:33 +08:00
|
|
|
}
|
|
|
|
|
2018-01-18 07:46:13 +08:00
|
|
|
namespace {
|
2018-02-27 07:15:52 +08:00
|
|
|
|
2018-01-18 07:46:13 +08:00
|
|
|
struct CheckNewAllocatorContext {
|
2018-02-27 07:15:52 +08:00
|
|
|
using CheckersTy = std::vector<CheckerManager::CheckNewAllocatorFunc>;
|
|
|
|
|
2018-01-18 07:46:13 +08:00
|
|
|
const CheckersTy &Checkers;
|
|
|
|
const CXXNewExpr *NE;
|
|
|
|
SVal Target;
|
|
|
|
bool WasInlined;
|
|
|
|
ExprEngine &Eng;
|
|
|
|
|
|
|
|
CheckNewAllocatorContext(const CheckersTy &Checkers, const CXXNewExpr *NE,
|
|
|
|
SVal Target, bool WasInlined, ExprEngine &Eng)
|
|
|
|
: Checkers(Checkers), NE(NE), Target(Target), WasInlined(WasInlined),
|
|
|
|
Eng(Eng) {}
|
|
|
|
|
2018-02-27 07:15:52 +08:00
|
|
|
CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
|
|
|
|
CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
|
|
|
|
|
2018-01-18 07:46:13 +08:00
|
|
|
void runChecker(CheckerManager::CheckNewAllocatorFunc checkFn,
|
|
|
|
NodeBuilder &Bldr, ExplodedNode *Pred) {
|
2018-01-18 08:50:19 +08:00
|
|
|
ProgramPoint L = PostAllocatorCall(NE, Pred->getLocationContext());
|
2018-01-18 07:46:13 +08:00
|
|
|
CheckerContext C(Bldr, Eng, Pred, L, WasInlined);
|
|
|
|
checkFn(NE, Target, C);
|
|
|
|
}
|
|
|
|
};
|
2018-02-27 07:15:52 +08:00
|
|
|
|
|
|
|
} // namespace
|
2018-01-18 07:46:13 +08:00
|
|
|
|
|
|
|
void CheckerManager::runCheckersForNewAllocator(
|
|
|
|
const CXXNewExpr *NE, SVal Target, ExplodedNodeSet &Dst, ExplodedNode *Pred,
|
|
|
|
ExprEngine &Eng, bool WasInlined) {
|
|
|
|
ExplodedNodeSet Src;
|
|
|
|
Src.insert(Pred);
|
|
|
|
CheckNewAllocatorContext C(NewAllocatorCheckers, NE, Target, WasInlined, Eng);
|
|
|
|
expandGraphWithCheckers(C, Dst, Src);
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for live symbols.
|
2012-01-27 05:29:00 +08:00
|
|
|
void CheckerManager::runCheckersForLiveSymbols(ProgramStateRef state,
|
2011-02-24 09:05:30 +08:00
|
|
|
SymbolReaper &SymReaper) {
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto LiveSymbolsChecker : LiveSymbolsCheckers)
|
|
|
|
LiveSymbolsChecker(state, SymReaper);
|
2011-02-24 09:05:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2018-02-27 07:15:52 +08:00
|
|
|
|
2011-02-24 09:05:30 +08:00
|
|
|
struct CheckDeadSymbolsContext {
|
2018-02-27 07:15:52 +08:00
|
|
|
using CheckersTy = std::vector<CheckerManager::CheckDeadSymbolsFunc>;
|
|
|
|
|
2011-02-24 09:05:30 +08:00
|
|
|
const CheckersTy &Checkers;
|
|
|
|
SymbolReaper &SR;
|
|
|
|
const Stmt *S;
|
|
|
|
ExprEngine &Eng;
|
2012-04-21 05:59:08 +08:00
|
|
|
ProgramPoint::Kind ProgarmPointKind;
|
2011-02-24 09:05:30 +08:00
|
|
|
|
|
|
|
CheckDeadSymbolsContext(const CheckersTy &checkers, SymbolReaper &sr,
|
2012-04-21 05:59:08 +08:00
|
|
|
const Stmt *s, ExprEngine &eng,
|
|
|
|
ProgramPoint::Kind K)
|
2018-02-27 07:15:52 +08:00
|
|
|
: Checkers(checkers), SR(sr), S(s), Eng(eng), ProgarmPointKind(K) {}
|
|
|
|
|
|
|
|
CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
|
|
|
|
CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
|
2011-02-24 09:05:30 +08:00
|
|
|
|
|
|
|
void runChecker(CheckerManager::CheckDeadSymbolsFunc checkFn,
|
2011-10-25 02:25:58 +08:00
|
|
|
NodeBuilder &Bldr, ExplodedNode *Pred) {
|
2012-04-21 05:59:08 +08:00
|
|
|
const ProgramPoint &L = ProgramPoint::getProgramPoint(S, ProgarmPointKind,
|
2011-10-08 05:52:33 +08:00
|
|
|
Pred->getLocationContext(), checkFn.Checker);
|
2011-10-26 03:57:06 +08:00
|
|
|
CheckerContext C(Bldr, Eng, Pred, L);
|
2011-10-08 05:52:33 +08:00
|
|
|
|
2012-04-21 05:59:08 +08:00
|
|
|
// Note, do not pass the statement to the checkers without letting them
|
|
|
|
// differentiate if we ran remove dead bindings before or after the
|
|
|
|
// statement.
|
2011-02-24 09:05:30 +08:00
|
|
|
checkFn(SR, C);
|
|
|
|
}
|
|
|
|
};
|
2018-02-27 07:15:52 +08:00
|
|
|
|
|
|
|
} // namespace
|
2011-02-24 09:05:30 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for dead symbols.
|
2011-02-24 09:05:30 +08:00
|
|
|
void CheckerManager::runCheckersForDeadSymbols(ExplodedNodeSet &Dst,
|
|
|
|
const ExplodedNodeSet &Src,
|
|
|
|
SymbolReaper &SymReaper,
|
|
|
|
const Stmt *S,
|
2012-04-21 05:59:08 +08:00
|
|
|
ExprEngine &Eng,
|
|
|
|
ProgramPoint::Kind K) {
|
|
|
|
CheckDeadSymbolsContext C(DeadSymbolsCheckers, SymReaper, S, Eng, K);
|
2011-02-24 09:05:30 +08:00
|
|
|
expandGraphWithCheckers(C, Dst, Src);
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for region changes.
|
2015-09-08 11:50:52 +08:00
|
|
|
ProgramStateRef
|
2012-01-27 05:29:00 +08:00
|
|
|
CheckerManager::runCheckersForRegionChanges(ProgramStateRef state,
|
2017-01-13 08:50:57 +08:00
|
|
|
const InvalidatedSymbols *invalidated,
|
|
|
|
ArrayRef<const MemRegion *> ExplicitRegions,
|
|
|
|
ArrayRef<const MemRegion *> Regions,
|
|
|
|
const LocationContext *LCtx,
|
|
|
|
const CallEvent *Call) {
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto RegionChangesChecker : RegionChangesCheckers) {
|
2011-02-24 09:05:30 +08:00
|
|
|
// If any checker declares the state infeasible (or if it starts that way),
|
|
|
|
// bail out.
|
|
|
|
if (!state)
|
2014-05-27 10:45:47 +08:00
|
|
|
return nullptr;
|
2018-02-27 07:15:52 +08:00
|
|
|
state = RegionChangesChecker(state, invalidated, ExplicitRegions, Regions,
|
|
|
|
LCtx, Call);
|
2011-02-24 09:05:30 +08:00
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers to process symbol escape event.
|
2012-12-20 08:38:25 +08:00
|
|
|
ProgramStateRef
|
|
|
|
CheckerManager::runCheckersForPointerEscape(ProgramStateRef State,
|
2013-09-25 07:47:29 +08:00
|
|
|
const InvalidatedSymbols &Escaped,
|
|
|
|
const CallEvent *Call,
|
|
|
|
PointerEscapeKind Kind,
|
|
|
|
RegionAndSymbolInvalidationTraits *ETraits) {
|
2014-05-27 10:45:47 +08:00
|
|
|
assert((Call != nullptr ||
|
2013-02-08 07:05:43 +08:00
|
|
|
(Kind != PSK_DirectEscapeOnCall &&
|
|
|
|
Kind != PSK_IndirectEscapeOnCall)) &&
|
|
|
|
"Call must not be NULL when escaping on call");
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto PointerEscapeChecker : PointerEscapeCheckers) {
|
|
|
|
// If any checker declares the state infeasible (or if it starts that
|
|
|
|
// way), bail out.
|
|
|
|
if (!State)
|
|
|
|
return nullptr;
|
|
|
|
State = PointerEscapeChecker(State, Escaped, Call, Kind, ETraits);
|
|
|
|
}
|
2012-12-20 08:38:25 +08:00
|
|
|
return State;
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for handling assumptions on symbolic values.
|
2015-09-08 11:50:52 +08:00
|
|
|
ProgramStateRef
|
2012-01-27 05:29:00 +08:00
|
|
|
CheckerManager::runCheckersForEvalAssume(ProgramStateRef state,
|
2011-02-28 09:26:35 +08:00
|
|
|
SVal Cond, bool Assumption) {
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto EvalAssumeChecker : EvalAssumeCheckers) {
|
2011-02-28 09:26:35 +08:00
|
|
|
// If any checker declares the state infeasible (or if it starts that way),
|
|
|
|
// bail out.
|
|
|
|
if (!state)
|
2014-05-27 10:45:47 +08:00
|
|
|
return nullptr;
|
2018-02-27 07:15:52 +08:00
|
|
|
state = EvalAssumeChecker(state, Cond, Assumption);
|
2011-02-28 09:26:35 +08:00
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for evaluating a call.
|
2011-02-24 03:38:39 +08:00
|
|
|
/// Only one checker will evaluate the call.
|
|
|
|
void CheckerManager::runCheckersForEvalCall(ExplodedNodeSet &Dst,
|
|
|
|
const ExplodedNodeSet &Src,
|
2012-08-14 07:46:05 +08:00
|
|
|
const CallEvent &Call,
|
2012-07-03 03:28:09 +08:00
|
|
|
ExprEngine &Eng) {
|
2012-08-14 07:46:05 +08:00
|
|
|
const CallExpr *CE = cast<CallExpr>(Call.getOriginExpr());
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto Pred : Src) {
|
2011-02-24 03:38:39 +08:00
|
|
|
bool anyEvaluated = false;
|
2011-10-06 07:37:30 +08:00
|
|
|
|
2011-10-25 02:25:58 +08:00
|
|
|
ExplodedNodeSet checkDst;
|
|
|
|
NodeBuilder B(Pred, checkDst, Eng.getBuilderContext());
|
2012-10-13 13:05:13 +08:00
|
|
|
|
|
|
|
// Check if any of the EvalCall callbacks can evaluate the call.
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto EvalCallChecker : EvalCallCheckers) {
|
2011-10-08 05:52:33 +08:00
|
|
|
ProgramPoint::Kind K = ProgramPoint::PostStmtKind;
|
2018-02-27 07:15:52 +08:00
|
|
|
const ProgramPoint &L =
|
|
|
|
ProgramPoint::getProgramPoint(CE, K, Pred->getLocationContext(),
|
|
|
|
EvalCallChecker.Checker);
|
2011-10-12 01:29:59 +08:00
|
|
|
bool evaluated = false;
|
|
|
|
{ // CheckerContext generates transitions(populates checkDest) on
|
|
|
|
// destruction, so introduce the scope to make sure it gets properly
|
|
|
|
// populated.
|
2011-10-26 03:57:06 +08:00
|
|
|
CheckerContext C(B, Eng, Pred, L);
|
2018-02-27 07:15:52 +08:00
|
|
|
evaluated = EvalCallChecker(CE, C);
|
2011-10-12 01:29:59 +08:00
|
|
|
}
|
2011-02-24 03:38:39 +08:00
|
|
|
assert(!(evaluated && anyEvaluated)
|
|
|
|
&& "There are more than one checkers evaluating the call");
|
|
|
|
if (evaluated) {
|
|
|
|
anyEvaluated = true;
|
|
|
|
Dst.insert(checkDst);
|
|
|
|
#ifdef NDEBUG
|
|
|
|
break; // on release don't check that no other checker also evals.
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2011-10-06 07:37:30 +08:00
|
|
|
// If none of the checkers evaluated the call, ask ExprEngine to handle it.
|
2012-07-20 07:38:13 +08:00
|
|
|
if (!anyEvaluated) {
|
|
|
|
NodeBuilder B(Pred, Dst, Eng.getBuilderContext());
|
|
|
|
Eng.defaultEvalCall(B, Pred, Call);
|
|
|
|
}
|
2011-02-24 03:38:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Run checkers for the entire Translation Unit.
|
2011-05-05 11:41:17 +08:00
|
|
|
void CheckerManager::runCheckersOnEndOfTranslationUnit(
|
|
|
|
const TranslationUnitDecl *TU,
|
|
|
|
AnalysisManager &mgr,
|
|
|
|
BugReporter &BR) {
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto EndOfTranslationUnitChecker : EndOfTranslationUnitCheckers)
|
|
|
|
EndOfTranslationUnitChecker(TU, mgr, BR);
|
2011-05-05 11:41:17 +08:00
|
|
|
}
|
|
|
|
|
2011-08-29 03:11:56 +08:00
|
|
|
void CheckerManager::runCheckersForPrintState(raw_ostream &Out,
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef State,
|
2011-08-29 03:11:56 +08:00
|
|
|
const char *NL, const char *Sep) {
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto &CheckerTag : CheckerTags)
|
|
|
|
CheckerTag.second->printState(Out, State, NL, Sep);
|
2011-08-29 03:11:56 +08:00
|
|
|
}
|
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Internal registration functions for AST traversing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void CheckerManager::_registerForDecl(CheckDeclFunc checkfn,
|
|
|
|
HandlesDeclFunc isForDeclFn) {
|
|
|
|
DeclCheckerInfo info = { checkfn, isForDeclFn };
|
|
|
|
DeclCheckers.push_back(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckerManager::_registerForBody(CheckDeclFunc checkfn) {
|
|
|
|
BodyCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Internal registration functions for path-sensitive checking.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void CheckerManager::_registerForPreStmt(CheckStmtFunc checkfn,
|
|
|
|
HandlesStmtFunc isForStmtFn) {
|
|
|
|
StmtCheckerInfo info = { checkfn, isForStmtFn, /*IsPreVisit*/true };
|
|
|
|
StmtCheckers.push_back(info);
|
|
|
|
}
|
2018-02-27 07:15:52 +08:00
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
void CheckerManager::_registerForPostStmt(CheckStmtFunc checkfn,
|
|
|
|
HandlesStmtFunc isForStmtFn) {
|
|
|
|
StmtCheckerInfo info = { checkfn, isForStmtFn, /*IsPreVisit*/false };
|
|
|
|
StmtCheckers.push_back(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckerManager::_registerForPreObjCMessage(CheckObjCMessageFunc checkfn) {
|
|
|
|
PreObjCMessageCheckers.push_back(checkfn);
|
|
|
|
}
|
2015-09-15 09:13:53 +08:00
|
|
|
|
|
|
|
void CheckerManager::_registerForObjCMessageNil(CheckObjCMessageFunc checkfn) {
|
|
|
|
ObjCMessageNilCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
void CheckerManager::_registerForPostObjCMessage(CheckObjCMessageFunc checkfn) {
|
|
|
|
PostObjCMessageCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2012-07-03 03:28:16 +08:00
|
|
|
void CheckerManager::_registerForPreCall(CheckCallFunc checkfn) {
|
|
|
|
PreCallCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
void CheckerManager::_registerForPostCall(CheckCallFunc checkfn) {
|
|
|
|
PostCallCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
void CheckerManager::_registerForLocation(CheckLocationFunc checkfn) {
|
|
|
|
LocationCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2011-02-28 09:26:35 +08:00
|
|
|
void CheckerManager::_registerForBind(CheckBindFunc checkfn) {
|
|
|
|
BindCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2011-02-23 15:19:23 +08:00
|
|
|
void CheckerManager::_registerForEndAnalysis(CheckEndAnalysisFunc checkfn) {
|
|
|
|
EndAnalysisCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2016-02-19 09:35:10 +08:00
|
|
|
void CheckerManager::_registerForBeginFunction(CheckBeginFunctionFunc checkfn) {
|
|
|
|
BeginFunctionCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2013-01-03 08:25:29 +08:00
|
|
|
void CheckerManager::_registerForEndFunction(CheckEndFunctionFunc checkfn) {
|
|
|
|
EndFunctionCheckers.push_back(checkfn);
|
2011-02-24 05:04:54 +08:00
|
|
|
}
|
|
|
|
|
2011-02-28 09:27:33 +08:00
|
|
|
void CheckerManager::_registerForBranchCondition(
|
|
|
|
CheckBranchConditionFunc checkfn) {
|
|
|
|
BranchConditionCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2018-01-18 07:46:13 +08:00
|
|
|
void CheckerManager::_registerForNewAllocator(CheckNewAllocatorFunc checkfn) {
|
|
|
|
NewAllocatorCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2011-02-24 09:05:30 +08:00
|
|
|
void CheckerManager::_registerForLiveSymbols(CheckLiveSymbolsFunc checkfn) {
|
|
|
|
LiveSymbolsCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckerManager::_registerForDeadSymbols(CheckDeadSymbolsFunc checkfn) {
|
|
|
|
DeadSymbolsCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2016-11-17 06:59:01 +08:00
|
|
|
void CheckerManager::_registerForRegionChanges(CheckRegionChangesFunc checkfn) {
|
|
|
|
RegionChangesCheckers.push_back(checkfn);
|
2011-02-24 09:05:30 +08:00
|
|
|
}
|
|
|
|
|
2012-12-20 08:38:25 +08:00
|
|
|
void CheckerManager::_registerForPointerEscape(CheckPointerEscapeFunc checkfn){
|
|
|
|
PointerEscapeCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2013-03-29 07:15:29 +08:00
|
|
|
void CheckerManager::_registerForConstPointerEscape(
|
|
|
|
CheckPointerEscapeFunc checkfn) {
|
|
|
|
PointerEscapeCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2011-02-28 09:26:35 +08:00
|
|
|
void CheckerManager::_registerForEvalAssume(EvalAssumeFunc checkfn) {
|
|
|
|
EvalAssumeCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2011-02-24 03:38:39 +08:00
|
|
|
void CheckerManager::_registerForEvalCall(EvalCallFunc checkfn) {
|
|
|
|
EvalCallCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2011-05-05 11:41:17 +08:00
|
|
|
void CheckerManager::_registerForEndOfTranslationUnit(
|
|
|
|
CheckEndOfTranslationUnit checkfn) {
|
|
|
|
EndOfTranslationUnitCheckers.push_back(checkfn);
|
|
|
|
}
|
|
|
|
|
2011-02-23 01:30:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Implementation details.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-08-17 05:57:06 +08:00
|
|
|
const CheckerManager::CachedStmtCheckers &
|
2011-02-23 01:30:38 +08:00
|
|
|
CheckerManager::getCachedStmtCheckersFor(const Stmt *S, bool isPreVisit) {
|
|
|
|
assert(S);
|
|
|
|
|
2013-08-17 05:57:06 +08:00
|
|
|
unsigned Key = (S->getStmtClass() << 1) | unsigned(isPreVisit);
|
|
|
|
CachedStmtCheckersMapTy::iterator CCI = CachedStmtCheckersMap.find(Key);
|
|
|
|
if (CCI != CachedStmtCheckersMap.end())
|
|
|
|
return CCI->second;
|
|
|
|
|
|
|
|
// Find the checkers that should run for this Stmt and cache them.
|
|
|
|
CachedStmtCheckers &Checkers = CachedStmtCheckersMap[Key];
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto &Info : StmtCheckers)
|
2013-08-17 05:57:06 +08:00
|
|
|
if (Info.IsPreVisit == isPreVisit && Info.IsForStmtFn(S))
|
|
|
|
Checkers.push_back(Info.CheckFn);
|
|
|
|
return Checkers;
|
2011-02-23 01:30:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CheckerManager::~CheckerManager() {
|
2018-02-27 07:15:52 +08:00
|
|
|
for (const auto CheckerDtor : CheckerDtors)
|
|
|
|
CheckerDtor();
|
2011-02-18 05:39:24 +08:00
|
|
|
}
|