21 using namespace clang;
25 class UndefinedAssignmentChecker
27 mutable std::unique_ptr<BugType> BT;
35 void UndefinedAssignmentChecker::checkBind(
SVal location,
SVal val,
54 static const char *
const DefaultMsg =
55 "Assigned value is garbage or undefined";
61 llvm::raw_svector_ostream OS(Str);
63 const Expr *ex =
nullptr;
66 if (
const UnaryOperator *U = dyn_cast<UnaryOperator>(StoreE)) {
67 OS <<
"The expression is an uninitialized value. " 68 "The computed value will also be garbage";
75 if (B->isCompoundAssignmentOp()) {
76 if (C.
getSVal(B->getLHS()).isUndef()) {
77 OS <<
"The left expression of the compound assignment is an " 78 "uninitialized value. The computed value will also be garbage";
88 if (
const DeclStmt *DS = dyn_cast<DeclStmt>(StoreE)) {
95 if (CD->isImplicit()) {
96 for (
auto I : CD->inits()) {
97 if (I->getInit()->IgnoreImpCasts() == StoreE) {
98 OS <<
"Value assigned to field '" << I->getMember()->getName()
99 <<
"' in implicit constructor is garbage or undefined";
109 if (OS.str().empty())
112 auto R = llvm::make_unique<BugReport>(*BT, OS.str(), N);
114 R->addRange(ex->getSourceRange());
115 bugreporter::trackNullOrUndefValue(N, ex, *R);
120 void ento::registerUndefinedAssignmentChecker(
CheckerManager &mgr) {
Represents a function declaration or definition.
ExplodedNode * generateErrorNode(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generate a transition to a node that will be used to report an error.
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.
StringRef getCalleeName(const FunctionDecl *FunDecl) const
Get the name of the called function (path-sensitive).
A builtin binary operation expression such as "x + y" or "x <= y".
Expr - This represents one expression.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
CHECKER * registerChecker(AT... Args)
Used to register checkers.
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Dataflow Directional Tag Classes.
const Expr * getInit() const
const Decl * getDecl() const
const StackFrameContext * getStackFrame() const