23using namespace iterator;
27class STLAlgorithmModeling :
public Checker<eval::Call> {
36 {{CDM::SimpleFunc, {
"std",
"find"}, 3}, &STLAlgorithmModeling::evalFind},
37 {{CDM::SimpleFunc, {
"std",
"find"}, 4}, &STLAlgorithmModeling::evalFind},
38 {{CDM::SimpleFunc, {
"std",
"find_if"}, 3},
39 &STLAlgorithmModeling::evalFind},
40 {{CDM::SimpleFunc, {
"std",
"find_if"}, 4},
41 &STLAlgorithmModeling::evalFind},
42 {{CDM::SimpleFunc, {
"std",
"find_if_not"}, 3},
43 &STLAlgorithmModeling::evalFind},
44 {{CDM::SimpleFunc, {
"std",
"find_if_not"}, 4},
45 &STLAlgorithmModeling::evalFind},
46 {{CDM::SimpleFunc, {
"std",
"find_first_of"}, 4},
47 &STLAlgorithmModeling::evalFind},
48 {{CDM::SimpleFunc, {
"std",
"find_first_of"}, 5},
49 &STLAlgorithmModeling::evalFind},
50 {{CDM::SimpleFunc, {
"std",
"find_first_of"}, 6},
51 &STLAlgorithmModeling::evalFind},
52 {{CDM::SimpleFunc, {
"std",
"find_end"}, 4},
53 &STLAlgorithmModeling::evalFind},
54 {{CDM::SimpleFunc, {
"std",
"find_end"}, 5},
55 &STLAlgorithmModeling::evalFind},
56 {{CDM::SimpleFunc, {
"std",
"find_end"}, 6},
57 &STLAlgorithmModeling::evalFind},
58 {{CDM::SimpleFunc, {
"std",
"lower_bound"}, 3},
59 &STLAlgorithmModeling::evalFind},
60 {{CDM::SimpleFunc, {
"std",
"lower_bound"}, 4},
61 &STLAlgorithmModeling::evalFind},
62 {{CDM::SimpleFunc, {
"std",
"upper_bound"}, 3},
63 &STLAlgorithmModeling::evalFind},
64 {{CDM::SimpleFunc, {
"std",
"upper_bound"}, 4},
65 &STLAlgorithmModeling::evalFind},
66 {{CDM::SimpleFunc, {
"std",
"search"}, 3},
67 &STLAlgorithmModeling::evalFind},
68 {{CDM::SimpleFunc, {
"std",
"search"}, 4},
69 &STLAlgorithmModeling::evalFind},
70 {{CDM::SimpleFunc, {
"std",
"search"}, 5},
71 &STLAlgorithmModeling::evalFind},
72 {{CDM::SimpleFunc, {
"std",
"search"}, 6},
73 &STLAlgorithmModeling::evalFind},
74 {{CDM::SimpleFunc, {
"std",
"search_n"}, 4},
75 &STLAlgorithmModeling::evalFind},
76 {{CDM::SimpleFunc, {
"std",
"search_n"}, 5},
77 &STLAlgorithmModeling::evalFind},
78 {{CDM::SimpleFunc, {
"std",
"search_n"}, 6},
79 &STLAlgorithmModeling::evalFind},
83 STLAlgorithmModeling() =
default;
85 bool AggressiveStdFindModeling =
false;
92 const auto *CE = dyn_cast_or_null<CallExpr>(
Call.getOriginExpr());
96 const FnCheck *Handler = Callbacks.lookup(
Call);
100 return (this->**Handler)(
C, CE);
130 unsigned paramNum)
const {
131 auto State =
C.getState();
132 auto &SVB =
C.getSValBuilder();
133 const auto *LCtx =
C.getLocationContext();
135 SVal RetVal = SVB.conjureSymbolVal(
nullptr, CE, LCtx,
C.blockCount());
136 SVal Param = State->getSVal(CE->
getArg(paramNum), LCtx);
138 auto StateFound = State->BindExpr(CE, LCtx, RetVal);
147 CE, LCtx,
C.blockCount());
149 assert(NewPos &&
"Failed to create new iterator position.");
151 SVal GreaterOrEqual = SVB.evalBinOp(StateFound, BO_GE,
154 SVB.getConditionType());
155 assert(isa<DefinedSVal>(GreaterOrEqual) &&
156 "Symbol comparison must be a `DefinedSVal`");
160 Param = State->getSVal(CE->
getArg(paramNum + 1), LCtx);
169 CE, LCtx,
C.blockCount());
171 assert(NewPos &&
"Failed to create new iterator position.");
173 SVal Less = SVB.evalBinOp(StateFound, BO_LT,
176 SVB.getConditionType());
177 assert(isa<DefinedSVal>(
Less) &&
178 "Symbol comparison must be a `DefinedSVal`");
182 C.addTransition(StateFound);
184 if (AggressiveStdFindModeling) {
185 auto StateNotFound = State->BindExpr(CE, LCtx, Param);
186 C.addTransition(StateNotFound);
194 Checker->AggressiveStdFindModeling =
196 "AggressiveStdFindModeling");
199bool ento::shouldRegisterSTLAlgorithmModeling(
const CheckerManager &mgr) {
bool getCheckerBooleanOption(StringRef CheckerName, StringRef OptionName, bool SearchInParents=false) const
Interprets an option's string value as a boolean.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
An immutable map from CallDescriptions to arbitrary data.
Represents an abstract call to a function or method along a particular path.
const AnalyzerOptions & getAnalyzerOptions() const
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.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Represents symbolic expression that isn't a location.
const IteratorPosition * getIteratorPosition(ProgramStateRef State, SVal Val)
bool isIteratorType(const QualType &Type)
ProgramStateRef createIteratorPosition(ProgramStateRef State, SVal Val, const MemRegion *Cont, const Stmt *S, const LocationContext *LCtx, unsigned blockCount)
The JSON file list parser is used to communicate input to InstallAPI.