aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2011-02-26 22:09:03 +0000
committerDimitry Andric <dim@FreeBSD.org>2011-02-26 22:09:03 +0000
commitc3b054d250cdca485c71845089c316e10610ebad (patch)
treeabae0246ec9156cc1a7cbb947b2b0dfe95fa3189 /lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
parentbca07a4524feb4edec581062d631a13116320a24 (diff)
downloadsrc-c3b054d250cdca485c71845089c316e10610ebad.tar.gz
src-c3b054d250cdca485c71845089c316e10610ebad.zip
Vendor import of clang trunk r126547:vendor/clang/clang-r126547
Notes
Notes: svn path=/vendor/clang/dist/; revision=219069 svn path=/vendor/clang/clang-r126547/; revision=219070; tag=vendor/clang/clang-r126547
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp')
-rw-r--r--lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp31
1 files changed, 11 insertions, 20 deletions
diff --git a/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp b/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
index f28fe9a5379e..bf85b959c9ee 100644
--- a/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
@@ -14,31 +14,26 @@
//===----------------------------------------------------------------------===//
#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 PointerSubChecker
- : public CheckerVisitor<PointerSubChecker> {
- BuiltinBug *BT;
+ : public CheckerV2< check::PreStmt<BinaryOperator> > {
+ mutable llvm::OwningPtr<BuiltinBug> BT;
+
public:
- PointerSubChecker() : BT(0) {}
- static void *getTag();
- void PreVisitBinaryOperator(CheckerContext &C, const BinaryOperator *B);
+ void checkPreStmt(const BinaryOperator *B, CheckerContext &C) const;
};
}
-void *PointerSubChecker::getTag() {
- static int x;
- return &x;
-}
-
-void PointerSubChecker::PreVisitBinaryOperator(CheckerContext &C,
- const BinaryOperator *B) {
+void PointerSubChecker::checkPreStmt(const BinaryOperator *B,
+ CheckerContext &C) const {
// When doing pointer subtraction, if the two pointers do not point to the
// same memory chunk, emit a warning.
if (B->getOpcode() != BO_Sub)
@@ -66,19 +61,15 @@ void PointerSubChecker::PreVisitBinaryOperator(CheckerContext &C,
if (ExplodedNode *N = C.generateNode()) {
if (!BT)
- BT = new BuiltinBug("Pointer subtraction",
+ BT.reset(new BuiltinBug("Pointer subtraction",
"Subtraction of two pointers that do not point to "
- "the same memory chunk may cause incorrect result.");
+ "the same memory chunk may cause incorrect result."));
RangedBugReport *R = new RangedBugReport(*BT, BT->getDescription(), N);
R->addRange(B->getSourceRange());
C.EmitReport(R);
}
}
-static void RegisterPointerSubChecker(ExprEngine &Eng) {
- Eng.registerCheck(new PointerSubChecker());
-}
-
void ento::registerPointerSubChecker(CheckerManager &mgr) {
- mgr.addCheckerRegisterFunction(RegisterPointerSubChecker);
+ mgr.registerChecker<PointerSubChecker>();
}