]> granicus.if.org Git - clang/commitdiff
Move UndefDerefChecker into its own file.
authorZhongxing Xu <xuzhongxing@gmail.com>
Sat, 31 Oct 2009 08:44:33 +0000 (08:44 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Sat, 31 Oct 2009 08:44:33 +0000 (08:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85645 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h [new file with mode: 0644]
lib/Analysis/GRExprEngineInternalChecks.cpp
lib/Analysis/UndefDerefChecker.cpp [new file with mode: 0644]

diff --git a/include/clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h b/include/clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h
new file mode 100644 (file)
index 0000000..e5c346e
--- /dev/null
@@ -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();
+};
+
+}
index 239d04c09b75ff97dae1f30e4a0d89a50392cef6..bfaf0f03795cb7fd321afdb218de844404fb3dc2 100644 (file)
@@ -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 @@ public:
   }
 };
 
-
-
-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 @@ void CheckDivZero::PreVisitBinaryOperator(CheckerContext &C,
     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 @@ void GRExprEngine::RegisterInternalChecks() {
   registerCheck<CheckUndefinedArg>(new CheckUndefinedArg());
   registerCheck<CheckBadCall>(new CheckBadCall());
   registerCheck<CheckDivZero>(new CheckDivZero());
-  registerCheck<CheckUndefDeref>(new CheckUndefDeref());
+  registerCheck<UndefDerefChecker>(new UndefDerefChecker());
   registerCheck<NullDerefChecker>(new NullDerefChecker());
 }
diff --git a/lib/Analysis/UndefDerefChecker.cpp b/lib/Analysis/UndefDerefChecker.cpp
new file mode 100644 (file)
index 0000000..da04826
--- /dev/null
@@ -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;
+}