24using namespace iterator;
28class DebugIteratorModeling
31 std::unique_ptr<BugType> DebugMsgBugType;
33 template <
typename Getter>
41 typedef void (DebugIteratorModeling::*FnCheck)(
const CallExpr *,
45 {{{
"clang_analyzer_iterator_position"}, 1},
46 &DebugIteratorModeling::analyzerIteratorPosition},
47 {{{
"clang_analyzer_iterator_container"}, 1},
48 &DebugIteratorModeling::analyzerIteratorContainer},
49 {{{
"clang_analyzer_iterator_validity"}, 1},
50 &DebugIteratorModeling::analyzerIteratorValidity},
54 DebugIteratorModeling();
61DebugIteratorModeling::DebugIteratorModeling() {
62 DebugMsgBugType.reset(
63 new BugType(
this,
"Checking analyzer assumptions",
"debug",
69 const auto *CE = dyn_cast_or_null<CallExpr>(
Call.getOriginExpr());
73 const FnCheck *Handler = Callbacks.lookup(
Call);
77 (this->**Handler)(CE,
C);
81template <
typename Getter>
82void DebugIteratorModeling::analyzerIteratorDataField(
const CallExpr *CE,
87 reportDebugMsg(
"Missing iterator argument",
C);
91 auto State =
C.getState();
95 State = State->BindExpr(CE,
C.getLocationContext(), get(Pos));
97 State = State->BindExpr(CE,
C.getLocationContext(),
Default);
99 C.addTransition(State);
102void DebugIteratorModeling::analyzerIteratorPosition(
const CallExpr *CE,
104 auto &BVF =
C.getSValBuilder().getBasicValueFactory();
110void DebugIteratorModeling::analyzerIteratorContainer(
const CallExpr *CE,
112 auto &BVF =
C.getSValBuilder().getBasicValueFactory();
118void DebugIteratorModeling::analyzerIteratorValidity(
const CallExpr *CE,
120 auto &BVF =
C.getSValBuilder().getBasicValueFactory();
127ExplodedNode *DebugIteratorModeling::reportDebugMsg(llvm::StringRef Msg,
133 auto &BR =
C.getBugReporter();
134 BR.emitReport(std::make_unique<PathSensitiveBugReport>(*DebugMsgBugType,
143bool ento::shouldRegisterDebugIteratorModeling(
const CheckerManager &mgr) {
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
An immutable map from CallDescriptions to arbitrary data.
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.
Value representing integer constant.
Represents symbolic expression that isn't a location.
const IteratorPosition * getIteratorPosition(ProgramStateRef State, const SVal &Val)