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,
59 cast<BlockDataRegion>(state->getSVal(BE,
68 const VarRegion *VR = I.getCapturedRegion();
76 state->getSVal(I.getOriginalRegion()).getAs<UndefinedVal>()) {
80 new BuiltinBug(
this,
"uninitialized variable captured by block"));
84 llvm::raw_svector_ostream os(buf);
86 os <<
"Variable '" << VD->
getName()
87 <<
"' is uninitialized when captured by block";
89 auto R = llvm::make_unique<BugReport>(*BT, os.str(), N);
91 R->addRange(Ex->getSourceRange());
92 R->addVisitor(llvm::make_unique<FindLastStoreBRVisitor>(
94 R->disablePathPruning();
102 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
hasCaptures - True if this block (or its nested blocks) captures anything of local storage from its e...
static const DeclRefExpr * FindBlockDeclRefExpr(const Stmt *S, const VarDecl *VD)
Stmt - This represents one statement.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
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
BlockDataRegion - A region that represents a block instance.
referenced_vars_iterator referenced_vars_end() const
const Stmt * getBody() const
Expr - This represents one expression.
bool hasLocalStorage() const
hasLocalStorage - 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
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
CHECKER * registerChecker()
Used to register checkers.
referenced_vars_iterator referenced_vars_begin() const
Dataflow Directional Tag Classes.
const ProgramStateRef & getState() const
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
A reference to a declared variable, function, enum, etc.
const LocationContext * getLocationContext() const