[cfe-commits] r85868 - in /cfe/trunk: include/clang/Analysis/PathSensitive/Checkers/BadCallChecker.h lib/Analysis/BadCallChecker.cpp lib/Analysis/GRExprEngineInternalChecks.cpp

Zhongxing Xu xuzhongxing at gmail.com
Mon Nov 2 21:48:05 PST 2009


Author: zhongxingxu
Date: Mon Nov  2 23:48:04 2009
New Revision: 85868

URL: http://llvm.org/viewvc/llvm-project?rev=85868&view=rev
Log:
Pull BadCallChecker into its own files.

Added:
    cfe/trunk/include/clang/Analysis/PathSensitive/Checkers/BadCallChecker.h
    cfe/trunk/lib/Analysis/BadCallChecker.cpp
Modified:
    cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp

Added: cfe/trunk/include/clang/Analysis/PathSensitive/Checkers/BadCallChecker.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/Checkers/BadCallChecker.h?rev=85868&view=auto

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/Checkers/BadCallChecker.h (added)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/Checkers/BadCallChecker.h Mon Nov  2 23:48:04 2009
@@ -0,0 +1,30 @@
+//===--- BadCallChecker.h - Bad call 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 BadCallChecker, a builtin check in GRExprEngine that performs
+// checks for bad callee at call sites.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Analysis/PathSensitive/CheckerVisitor.h"
+
+namespace clang {
+
+class BadCallChecker : public CheckerVisitor<BadCallChecker> {
+  BuiltinBug *BT;
+
+public:
+  BadCallChecker() : BT(0) {}
+
+  static void *getTag();
+
+  void PreVisitCallExpr(CheckerContext &C, const CallExpr *CE);
+};
+
+}

Added: cfe/trunk/lib/Analysis/BadCallChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BadCallChecker.cpp?rev=85868&view=auto

==============================================================================
--- cfe/trunk/lib/Analysis/BadCallChecker.cpp (added)
+++ cfe/trunk/lib/Analysis/BadCallChecker.cpp Mon Nov  2 23:48:04 2009
@@ -0,0 +1,44 @@
+//===--- BadCallChecker.h - Bad call 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 BadCallChecker, a builtin check in GRExprEngine that performs
+// checks for bad callee at call sites.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Analysis/PathSensitive/Checkers/BadCallChecker.h"
+#include "clang/Analysis/PathSensitive/BugReporter.h"
+
+using namespace clang;
+
+void *BadCallChecker::getTag() {
+  static int x = 0;
+  return &x;
+}
+
+void BadCallChecker::PreVisitCallExpr(CheckerContext &C, const CallExpr *CE) {
+  const Expr *Callee = CE->getCallee()->IgnoreParens();
+  SVal L = C.getState()->getSVal(Callee);
+
+  if (L.isUndef() || isa<loc::ConcreteInt>(L)) {
+    if (ExplodedNode *N = C.GenerateNode(CE, true)) {
+      if (!BT)
+        BT = new BuiltinBug(0, "Invalid function call",
+                "Called function pointer is a null or undefined pointer value");
+
+      EnhancedBugReport *R =
+        new EnhancedBugReport(*BT, BT->getDescription().c_str(), N);
+        
+      R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
+                           bugreporter::GetCalleeExpr(N));
+
+      C.EmitReport(R);
+    }
+  }
+}

Modified: cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp?rev=85868&r1=85867&r2=85868&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp Mon Nov  2 23:48:04 2009
@@ -18,6 +18,7 @@
 #include "clang/Analysis/PathSensitive/Checkers/NullDerefChecker.h"
 #include "clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h"
 #include "clang/Analysis/PathSensitive/Checkers/DivZeroChecker.h"
+#include "clang/Analysis/PathSensitive/Checkers/BadCallChecker.h"
 #include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/Support/Compiler.h"
@@ -211,20 +212,6 @@
   }
 };
 
-class VISIBILITY_HIDDEN BadCall : public BuiltinBug {
-public:
-  BadCall(GRExprEngine *eng = 0)
-  : BuiltinBug(eng, "Invalid function call",
-        "Called function pointer is a null or undefined pointer value") {}
-
-  void registerInitialVisitors(BugReporterContext& BRC,
-                               const ExplodedNode* N,
-                               BuiltinBugReport *R) {
-    registerTrackNullOrUndefValue(BRC, GetCalleeExpr(N), N);
-  }
-};
-
-
 class VISIBILITY_HIDDEN ArgReport : public BuiltinBugReport {
   const Stmt *Arg;
 public:
@@ -645,34 +632,6 @@
   }
 }
 
-class VISIBILITY_HIDDEN CheckBadCall : public CheckerVisitor<CheckBadCall> {
-  BadCall *BT;
-
-public:
-  CheckBadCall() : BT(0) {}
-  ~CheckBadCall() {}
-
-  static void *getTag() {
-    static int x = 0;
-    return &x;
-  }
-
-  void PreVisitCallExpr(CheckerContext &C, const CallExpr *CE);
-};
-
-void CheckBadCall::PreVisitCallExpr(CheckerContext &C, const CallExpr *CE) {
-  const Expr *Callee = CE->getCallee()->IgnoreParens();
-  SVal L = C.getState()->getSVal(Callee);
-
-  if (L.isUndef() || isa<loc::ConcreteInt>(L)) {
-    if (ExplodedNode *N = C.GenerateNode(CE, true)) {
-      if (!BT)
-        BT = new BadCall();
-      C.EmitReport(new BuiltinBugReport(*BT, BT->getDescription().c_str(), N));
-    }
-  }
-}
-
 } // end clang namespace
 
 //===----------------------------------------------------------------------===//
@@ -703,7 +662,7 @@
   // object.
   registerCheck<CheckAttrNonNull>(new CheckAttrNonNull());
   registerCheck<CheckUndefinedArg>(new CheckUndefinedArg());
-  registerCheck<CheckBadCall>(new CheckBadCall());
+  registerCheck<BadCallChecker>(new BadCallChecker());
   registerCheck<DivZeroChecker>(new DivZeroChecker());
   registerCheck<UndefDerefChecker>(new UndefDerefChecker());
   registerCheck<NullDerefChecker>(new NullDerefChecker());





More information about the cfe-commits mailing list