24using namespace iterator;
28class InvalidatedIteratorChecker
29 :
public Checker<check::PreCall, check::PreStmt<UnaryOperator>,
30 check::PreStmt<BinaryOperator>,
31 check::PreStmt<ArraySubscriptExpr>,
32 check::PreStmt<MemberExpr>> {
34 const BugType InvalidatedBugType{
this,
"Iterator invalidated",
35 "Misuse of STL APIs"};
52void InvalidatedIteratorChecker::checkPreCall(
const CallEvent &
Call,
55 const auto *
Func = dyn_cast_or_null<FunctionDecl>(
Call.getDecl());
59 if (
Func->isOverloadedOperator() &&
62 if (
const auto *InstCall = dyn_cast<CXXInstanceCall>(&
Call)) {
63 verifyAccess(
C, InstCall->getCXXThisVal());
65 verifyAccess(
C,
Call.getArgSVal(0));
70void InvalidatedIteratorChecker::checkPreStmt(
const UnaryOperator *UO,
80 verifyAccess(
C, SubVal);
84void InvalidatedIteratorChecker::checkPreStmt(
const BinaryOperator *BO,
88 SVal LVal = State->getSVal(BO->
getLHS(),
C.getLocationContext());
91 verifyAccess(
C, LVal);
98 SVal LVal = State->getSVal(ASE->
getLHS(),
C.getLocationContext());
99 verifyAccess(
C, LVal);
102void InvalidatedIteratorChecker::checkPreStmt(
const MemberExpr *ME,
108 SVal BaseVal = State->getSVal(ME->
getBase(),
C.getLocationContext());
109 verifyAccess(
C, BaseVal);
114 auto State =
C.getState();
116 if (Pos && !Pos->isValid()) {
117 auto *N =
C.generateErrorNode(State);
121 reportBug(
"Invalidated iterator accessed.", Val,
C, N);
125void InvalidatedIteratorChecker::reportBug(StringRef Message,
SVal Val,
128 auto R = std::make_unique<PathSensitiveBugReport>(InvalidatedBugType, Message,
130 R->markInteresting(Val);
131 C.emitReport(std::move(R));
134void ento::registerInvalidatedIteratorChecker(
CheckerManager &mgr) {
138bool ento::shouldRegisterInvalidatedIteratorChecker(
const CheckerManager &mgr) {
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
A builtin binary operation expression such as "x + y" or "x <= y".
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
bool isImplicitAccess() const
Determine whether the base of this explicit is implicit.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
Represents an abstract call to a function or method along a particular path.
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
const IteratorPosition * getIteratorPosition(ProgramStateRef State, SVal Val)
bool isAccessOperator(OverloadedOperatorKind OK)
The JSON file list parser is used to communicate input to InstallAPI.