24class UndefinedAssignmentChecker
26 mutable std::unique_ptr<BugType> BT;
34void UndefinedAssignmentChecker::checkBind(
SVal location,
SVal val,
43 dyn_cast<FunctionDecl>(
C.getStackFrame()->getDecl()))
44 if (
C.getCalleeName(EnclosingFunctionDecl) ==
"swap")
52 static const char *
const DefaultMsg =
53 "Assigned value is garbage or undefined";
55 BT.reset(
new BugType(
this, DefaultMsg));
59 llvm::raw_svector_ostream OS(Str);
61 const Expr *ex =
nullptr;
65 OS <<
"The expression is an uninitialized value. "
66 "The computed value will also be garbage";
73 if (B->isCompoundAssignmentOp()) {
74 if (
C.getSVal(B->getLHS()).isUndef()) {
75 OS <<
"The left expression of the compound assignment is an "
76 "uninitialized value. The computed value will also be garbage";
86 if (
const DeclStmt *DS = dyn_cast<DeclStmt>(StoreE)) {
87 const VarDecl *VD = cast<VarDecl>(DS->getSingleDecl());
92 dyn_cast<CXXConstructorDecl>(
C.getStackFrame()->getDecl())) {
93 if (CD->isImplicit()) {
94 for (
auto *I : CD->inits()) {
95 if (I->getInit()->IgnoreImpCasts() == StoreE) {
96 OS <<
"Value assigned to field '" << I->getMember()->getName()
97 <<
"' in implicit constructor is garbage or undefined";
107 if (OS.str().empty())
110 auto R = std::make_unique<PathSensitiveBugReport>(*BT, OS.str(), N);
115 C.emitReport(std::move(R));
118void ento::registerUndefinedAssignmentChecker(
CheckerManager &mgr) {
122bool ento::shouldRegisterUndefinedAssignmentChecker(
const CheckerManager &mgr) {
A builtin binary operation expression such as "x + y" or "x <= y".
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
This represents one expression.
Represents a function declaration or definition.
Stmt - This represents one statement.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Represents a variable declaration or definition.
const Expr * getInit() 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.
bool trackExpressionValue(const ExplodedNode *N, const Expr *E, PathSensitiveBugReport &R, TrackingOptions Opts={})
Attempts to add visitors to track expression value back to its point of origin.