[cfe-commits] r126618 - in /cfe/trunk/lib/StaticAnalyzer/Checkers: Checkers.td ExprEngine.cpp InternalChecks.h UndefinedArraySubscriptChecker.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Sun Feb 27 17:27:41 PST 2011
Author: akirtzidis
Date: Sun Feb 27 19:27:41 2011
New Revision: 126618
URL: http://llvm.org/viewvc/llvm-project?rev=126618&view=rev
Log:
[analyzer] Migrate UndefinedArraySubscriptChecker to CheckerV2.
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/InternalChecks.h
cfe/trunk/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td?rev=126618&r1=126617&r2=126618&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td Sun Feb 27 19:27:41 2011
@@ -75,6 +75,10 @@
let ParentPackage = Core in {
+def UndefinedArraySubscriptChecker : Checker<"UndefArraySubscript">,
+ HelpText<"Check for undefined array subscripts">,
+ DescFile<"UndefinedArraySubscriptChecker.cpp">;
+
def UndefinedAssignmentChecker : Checker<"UndefAssign">,
HelpText<"Check for assigning undefined values">,
DescFile<"UndefinedAssignmentChecker.cpp">;
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ExprEngine.cpp?rev=126618&r1=126617&r2=126618&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ExprEngine.cpp Sun Feb 27 19:27:41 2011
@@ -328,7 +328,6 @@
RegisterVLASizeChecker(Eng);
RegisterDivZeroChecker(Eng);
RegisterReturnUndefChecker(Eng);
- RegisterUndefinedArraySubscriptChecker(Eng);
}
ExprEngine::ExprEngine(AnalysisManager &mgr, TransferFuncs *tf)
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/InternalChecks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/InternalChecks.h?rev=126618&r1=126617&r2=126618&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/InternalChecks.h (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/InternalChecks.h Sun Feb 27 19:27:41 2011
@@ -28,7 +28,6 @@
void RegisterDereferenceChecker(ExprEngine &Eng);
void RegisterDivZeroChecker(ExprEngine &Eng);
void RegisterReturnUndefChecker(ExprEngine &Eng);
-void RegisterUndefinedArraySubscriptChecker(ExprEngine &Eng);
void RegisterVLASizeChecker(ExprEngine &Eng);
} // end GR namespace
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp?rev=126618&r1=126617&r2=126618&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UndefinedArraySubscriptChecker.cpp Sun Feb 27 19:27:41 2011
@@ -12,39 +12,32 @@
//
//===----------------------------------------------------------------------===//
-#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 UndefinedArraySubscriptChecker
- : public CheckerVisitor<UndefinedArraySubscriptChecker> {
- BugType *BT;
+ : public CheckerV2< check::PreStmt<ArraySubscriptExpr> > {
+ mutable llvm::OwningPtr<BugType> BT;
+
public:
- UndefinedArraySubscriptChecker() : BT(0) {}
- static void *getTag() {
- static int x = 0;
- return &x;
- }
- void PreVisitArraySubscriptExpr(CheckerContext &C,
- const ArraySubscriptExpr *A);
+ void checkPreStmt(const ArraySubscriptExpr *A, CheckerContext &C) const;
};
} // end anonymous namespace
-void ento::RegisterUndefinedArraySubscriptChecker(ExprEngine &Eng) {
- Eng.registerCheck(new UndefinedArraySubscriptChecker());
-}
-
void
-UndefinedArraySubscriptChecker::PreVisitArraySubscriptExpr(CheckerContext &C,
- const ArraySubscriptExpr *A) {
+UndefinedArraySubscriptChecker::checkPreStmt(const ArraySubscriptExpr *A,
+ CheckerContext &C) const {
if (C.getState()->getSVal(A->getIdx()).isUndef()) {
if (ExplodedNode *N = C.generateSink()) {
if (!BT)
- BT = new BuiltinBug("Array subscript is undefined");
+ BT.reset(new BuiltinBug("Array subscript is undefined"));
// Generate a report for this bug.
EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName(), N);
@@ -55,3 +48,7 @@
}
}
}
+
+void ento::registerUndefinedArraySubscriptChecker(CheckerManager &mgr) {
+ mgr.registerChecker<UndefinedArraySubscriptChecker>();
+}
More information about the cfe-commits
mailing list