let ParentPackage = Core in {
+def UndefinedAssignmentChecker : Checker<"UndefAssign">,
+ HelpText<"Check for assigning undefined values">,
+ DescFile<"UndefinedAssignmentChecker.cpp">;
+
def UndefBranchChecker : Checker<"UndefBranch">,
HelpText<"Check for undefined branch conditions">,
DescFile<"UndefBranchChecker.cpp">;
//
//===----------------------------------------------------------------------===//
//
-// This defines UndefinedAssginmentChecker, a builtin check in ExprEngine that
+// This defines UndefinedAssignmentChecker, a builtin check in ExprEngine that
// checks for assigning undefined values.
//
//===----------------------------------------------------------------------===//
-#include "InternalChecks.h"
+#include "ClangSACheckers.h"
+#include "clang/StaticAnalyzer/Core/CheckerV2.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerVisitor.h"
using namespace clang;
using namespace ento;
namespace {
class UndefinedAssignmentChecker
- : public CheckerVisitor<UndefinedAssignmentChecker> {
- BugType *BT;
+ : public CheckerV2<check::Bind> {
+ mutable llvm::OwningPtr<BugType> BT;
+
public:
- UndefinedAssignmentChecker() : BT(0) {}
- static void *getTag();
- virtual void PreVisitBind(CheckerContext &C, const Stmt *StoreE,
- SVal location, SVal val);
+ void checkBind(SVal location, SVal val, CheckerContext &C) const;
};
}
-void ento::RegisterUndefinedAssignmentChecker(ExprEngine &Eng){
- Eng.registerCheck(new UndefinedAssignmentChecker());
-}
-
-void *UndefinedAssignmentChecker::getTag() {
- static int x = 0;
- return &x;
-}
-
-void UndefinedAssignmentChecker::PreVisitBind(CheckerContext &C,
- const Stmt *StoreE,
- SVal location,
- SVal val) {
+void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
+ CheckerContext &C) const {
if (!val.isUndef())
return;
const char *str = "Assigned value is garbage or undefined";
if (!BT)
- BT = new BuiltinBug(str);
+ BT.reset(new BuiltinBug(str));
// Generate a report for this bug.
const Expr *ex = 0;
+ const Stmt *StoreE = C.getStmt();
while (StoreE) {
if (const BinaryOperator *B = dyn_cast<BinaryOperator>(StoreE)) {
if (B->isCompoundAssignmentOp()) {
C.EmitReport(R);
}
+void ento::registerUndefinedAssignmentChecker(CheckerManager &mgr) {
+ mgr.registerChecker<UndefinedAssignmentChecker>();
+}