21 #include "llvm/ADT/SmallString.h" 22 #include "llvm/Support/raw_ostream.h" 24 using namespace clang;
28 class UndefCapturedBlockVarChecker
29 :
public Checker< check::PostStmt<BlockExpr> > {
30 mutable std::unique_ptr<BugType> BT;
39 if (
const DeclRefExpr *BR = dyn_cast<DeclRefExpr>(S))
40 if (BR->getDecl() == VD)
52 UndefCapturedBlockVarChecker::checkPostStmt(
const BlockExpr *BE,
61 E = R->referenced_vars_end();
66 const VarRegion *VR = I.getCapturedRegion();
74 state->getSVal(I.getOriginalRegion()).getAs<UndefinedVal>()) {
78 new BuiltinBug(
this,
"uninitialized variable captured by block"));
82 llvm::raw_svector_ostream os(buf);
84 os <<
"Variable '" << VD->
getName()
85 <<
"' is uninitialized when captured by block";
87 auto R = llvm::make_unique<BugReport>(*BT, os.str(), N);
89 R->addRange(Ex->getSourceRange());
90 R->addVisitor(llvm::make_unique<FindLastStoreBRVisitor>(
92 R->disablePathPruning();
100 void ento::registerUndefCapturedBlockVarChecker(
CheckerManager &mgr) {
const BlockDecl * getBlockDecl() const
ExplodedNode * generateErrorNode(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generate a transition to a node that will be used to report an error.
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
static const DeclRefExpr * FindBlockDeclRefExpr(const Stmt *S, const VarDecl *VD)
Stmt - This represents one statement.
Represents a variable declaration or definition.
SVal getSVal(const Stmt *S) const
Get the value of arbitrary expressions at this point in the path.
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
const Stmt * getBody() const
Expr - This represents one expression.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
const VarDecl * getDecl() const
CHECKER * registerChecker(AT... Args)
Used to register checkers.
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
const MemRegion * getAsRegion() const
Dataflow Directional Tag Classes.
const ProgramStateRef & getState() const
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
A reference to a declared variable, function, enum, etc.