26class UndefCapturedBlockVarChecker
27 :
public Checker< check::PostStmt<BlockExpr> > {
28 const BugType BT{
this,
"uninitialized variable captured by block"};
31 void checkPostStmt(
const BlockExpr *BE, CheckerContext &
C)
const;
37 if (
const DeclRefExpr *BR = dyn_cast<DeclRefExpr>(S))
38 if (BR->getDecl() == VD)
50UndefCapturedBlockVarChecker::checkPostStmt(
const BlockExpr *BE,
58 for (
auto Var :
R->referenced_vars()) {
61 const VarRegion *VR = Var.getCapturedRegion();
62 const VarDecl *VD = VR->
getDecl();
68 if (std::optional<UndefinedVal>
V =
69 state->getSVal(Var.getOriginalRegion()).getAs<UndefinedVal>()) {
70 if (ExplodedNode *N =
C.generateErrorNode()) {
71 auto R = std::make_unique<PathSensitiveBugReport>(
73 "Variable '" + Twine(VD->
getName()) +
74 "' is uninitialized when captured by block",
77 R->addRange(Ex->getSourceRange());
79 {bugreporter::TrackingKind::Thorough,
81 R->disablePathPruning();
83 C.emitReport(std::move(R));
89void ento::registerUndefCapturedBlockVarChecker(CheckerManager &mgr) {
93bool ento::shouldRegisterUndefCapturedBlockVarChecker(
const CheckerManager &mgr) {
static const DeclRefExpr * FindBlockDeclRefExpr(const Stmt *S, const VarDecl *VD)
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
const Stmt * getBody() const
const BlockDecl * getBlockDecl() const
A reference to a declared variable, function, enum, etc.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Stmt - This represents one statement.
Represents a variable declaration or definition.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
const VarDecl * getDecl() const override=0
void trackStoredValue(SVal V, const MemRegion *R, PathSensitiveBugReport &Report, TrackingOptions Opts={}, const StackFrame *Origin=nullptr)
Track how the value got stored into the given region and where it came from.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
The JSON file list parser is used to communicate input to InstallAPI.
U cast(CodeGen::Address addr)