[cfe-commits] r85645 - in /cfe/trunk: include/clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h lib/Analysis/GRExprEngineInternalChecks.cpp lib/Analysis/UndefDerefChecker.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Sat Oct 31 01:44:34 PDT 2009
Author: zhongxingxu
Date: Sat Oct 31 03:44:33 2009
New Revision: 85645
URL: http://llvm.org/viewvc/llvm-project?rev=85645&view=rev
Log:
Move UndefDerefChecker into its own file.
Added:
cfe/trunk/include/clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h
cfe/trunk/lib/Analysis/UndefDerefChecker.cpp
Modified:
cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
Added: cfe/trunk/include/clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h?rev=85645&view=auto
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h (added)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h Sat Oct 31 03:44:33 2009
@@ -0,0 +1,31 @@
+//== UndefDerefChecker.h - Undefined dereference checker --------*- C++ -*--==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This defines UndefDerefChecker, a builtin check in GRExprEngine that performs
+// checks for defined pointers at loads and stores.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Analysis/PathSensitive/Checker.h"
+#include "clang/Analysis/PathSensitive/BugType.h"
+
+namespace clang {
+
+class UndefDerefChecker : public Checker {
+ BuiltinBug *BT;
+public:
+ UndefDerefChecker() : BT(0) {}
+
+ ExplodedNode *CheckLocation(const Stmt *S, ExplodedNode *Pred,
+ const GRState *state, SVal V, GRExprEngine &Eng);
+
+ static void *getTag();
+};
+
+}
Modified: cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp?rev=85645&r1=85644&r2=85645&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp Sat Oct 31 03:44:33 2009
@@ -16,6 +16,7 @@
#include "clang/Analysis/PathSensitive/GRExprEngine.h"
#include "clang/Analysis/PathSensitive/CheckerVisitor.h"
#include "clang/Analysis/PathSensitive/Checkers/NullDerefChecker.h"
+#include "clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h"
#include "clang/Analysis/PathDiagnostic.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/Support/Compiler.h"
@@ -133,20 +134,6 @@
}
};
-
-
-class VISIBILITY_HIDDEN UndefinedDeref : public BuiltinBug {
-public:
- UndefinedDeref()
- : BuiltinBug(0, "Dereference of undefined pointer value") {}
-
- void registerInitialVisitors(BugReporterContext& BRC,
- const ExplodedNode* N,
- BuiltinBugReport *R) {
- registerTrackNullOrUndefValue(BRC, GetDerefExpr(N), N);
- }
-};
-
class VISIBILITY_HIDDEN DivZero : public BuiltinBug {
public:
DivZero(GRExprEngine* eng = 0)
@@ -753,41 +740,6 @@
C.addTransition(C.GenerateNode(B, stateNotZero));
}
-class VISIBILITY_HIDDEN CheckUndefDeref : public Checker {
- UndefinedDeref *BT;
-public:
- CheckUndefDeref() : BT(0) {}
-
- ExplodedNode *CheckLocation(const Stmt *S, ExplodedNode *Pred,
- const GRState *state, SVal V, GRExprEngine &Eng);
-
- static void *getTag() {
- static int x = 0;
- return &x;
- }
-};
-
-ExplodedNode *CheckUndefDeref::CheckLocation(const Stmt *S, ExplodedNode *Pred,
- const GRState *state, SVal V,
- GRExprEngine &Eng) {
- GRStmtNodeBuilder &Builder = Eng.getBuilder();
- BugReporter &BR = Eng.getBugReporter();
-
- if (V.isUndef()) {
- ExplodedNode *N = Builder.generateNode(S, state, Pred,
- ProgramPoint::PostUndefLocationCheckFailedKind);
- if (N) {
- if (!BT)
- BT = new UndefinedDeref();
-
- N->markAsSink();
- BR.EmitReport(new BuiltinBugReport(*BT, BT->getDescription().c_str(), N));
- }
- return 0;
- }
-
- return Pred;
-}
} // end clang namespace
@@ -821,6 +773,6 @@
registerCheck<CheckUndefinedArg>(new CheckUndefinedArg());
registerCheck<CheckBadCall>(new CheckBadCall());
registerCheck<CheckDivZero>(new CheckDivZero());
- registerCheck<CheckUndefDeref>(new CheckUndefDeref());
+ registerCheck<UndefDerefChecker>(new UndefDerefChecker());
registerCheck<NullDerefChecker>(new NullDerefChecker());
}
Added: cfe/trunk/lib/Analysis/UndefDerefChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UndefDerefChecker.cpp?rev=85645&view=auto
==============================================================================
--- cfe/trunk/lib/Analysis/UndefDerefChecker.cpp (added)
+++ cfe/trunk/lib/Analysis/UndefDerefChecker.cpp Sat Oct 31 03:44:33 2009
@@ -0,0 +1,53 @@
+// UndefDerefChecker.cpp - Undefined dereference checker ----------*- C++ -*--//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This defines UndefDerefChecker, a builtin check in GRExprEngine that performs
+// checks for defined pointers at loads and stores.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h"
+#include "clang/Analysis/PathSensitive/GRExprEngine.h"
+#include "clang/Analysis/PathSensitive/BugReporter.h"
+
+using namespace clang;
+
+void *UndefDerefChecker::getTag() {
+ static int x = 0;
+ return &x;
+}
+
+ExplodedNode *UndefDerefChecker::CheckLocation(const Stmt *S,
+ ExplodedNode *Pred,
+ const GRState *state, SVal V,
+ GRExprEngine &Eng) {
+ GRStmtNodeBuilder &Builder = Eng.getBuilder();
+ BugReporter &BR = Eng.getBugReporter();
+
+ if (V.isUndef()) {
+ ExplodedNode *N = Builder.generateNode(S, state, Pred,
+ ProgramPoint::PostUndefLocationCheckFailedKind);
+ if (N) {
+ N->markAsSink();
+
+ if (!BT)
+ BT = new BuiltinBug(0, "Undefined dereference",
+ "Dereference of undefined pointer value");
+
+ EnhancedBugReport *R =
+ new EnhancedBugReport(*BT, BT->getDescription().c_str(), N);
+ R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
+ bugreporter::GetDerefExpr(N));
+ BR.EmitReport(R);
+ }
+ return 0;
+ }
+
+ return Pred;
+}
More information about the cfe-commits
mailing list