1 //===--- UndefinedAssignmentChecker.h ---------------------------*- C++ -*--==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This defines UndefinedAssginmentChecker, a builtin check in GRExprEngine that
11 // checks for assigning undefined values.
13 //===----------------------------------------------------------------------===//
15 #include "GRExprEngineInternalChecks.h"
16 #include "clang/Checker/PathSensitive/CheckerVisitor.h"
17 #include "clang/Checker/BugReporter/BugReporter.h"
19 using namespace clang;
22 class UndefinedAssignmentChecker
23 : public CheckerVisitor<UndefinedAssignmentChecker> {
26 UndefinedAssignmentChecker() : BT(0) {}
27 static void *getTag();
28 virtual void PreVisitBind(CheckerContext &C, const Stmt *AssignE,
29 const Stmt *StoreE, SVal location,
34 void clang::RegisterUndefinedAssignmentChecker(GRExprEngine &Eng){
35 Eng.registerCheck(new UndefinedAssignmentChecker());
38 void *UndefinedAssignmentChecker::getTag() {
43 void UndefinedAssignmentChecker::PreVisitBind(CheckerContext &C,
51 ExplodedNode *N = C.GenerateSink();
57 BT = new BuiltinBug("Assigned value is garbage or undefined");
59 // Generate a report for this bug.
60 EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName(), N);
65 if (const BinaryOperator *B = dyn_cast<BinaryOperator>(AssignE))
67 else if (const DeclStmt *DS = dyn_cast<DeclStmt>(AssignE)) {
68 const VarDecl* VD = dyn_cast<VarDecl>(DS->getSingleDecl());
72 R->addRange(ex->getSourceRange());
73 R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, ex);