]> granicus.if.org Git - clang/commitdiff
Merge NullDerefChecker.[h,cpp] and UndefDerefChecker.[h,cpp]. They are essentially...
authorTed Kremenek <kremenek@apple.com>
Tue, 3 Nov 2009 18:41:06 +0000 (18:41 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 3 Nov 2009 18:41:06 +0000 (18:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85911 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/Checkers/DereferenceChecker.h [moved from include/clang/Analysis/PathSensitive/Checkers/NullDerefChecker.h with 69% similarity]
include/clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h [deleted file]
lib/Analysis/CMakeLists.txt
lib/Analysis/DereferenceChecker.cpp [moved from lib/Analysis/NullDerefChecker.cpp with 68% similarity]
lib/Analysis/GRExprEngineInternalChecks.cpp
lib/Analysis/NSErrorChecker.cpp
lib/Analysis/UndefDerefChecker.cpp [deleted file]

similarity index 69%
rename from include/clang/Analysis/PathSensitive/Checkers/NullDerefChecker.h
rename to include/clang/Analysis/PathSensitive/Checkers/DereferenceChecker.h
index 6905d6834b912f0aef6ae9d16bccfe4fcff98a7c..688cf641491d0f733eec5d4ab4abfebe9456899e 100644 (file)
@@ -7,13 +7,14 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This defines NullDerefChecker, a builtin check in GRExprEngine that performs
-// checks for null pointers at loads and stores.
+// This defines NullDerefChecker and UndefDerefChecker, two builtin checks
+// in GRExprEngine that check for null and undefined pointers at loads
+// and stores.
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_CLANG_NULLDEREFCHECKER
-#define LLVM_CLANG_NULLDEREFCHECKER
+#ifndef LLVM_CLANG_DEREFCHECKER
+#define LLVM_CLANG_DEREFCHECKER
 
 #include "clang/Analysis/PathSensitive/Checker.h"
 #include "clang/Analysis/PathSensitive/BugType.h"
@@ -37,5 +38,16 @@ public:
   iterator implicit_nodes_end() { return ImplicitNullDerefNodes.end(); }
 };
 
+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();
+};
+
 } // end clang namespace
 #endif
diff --git a/include/clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h b/include/clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h
deleted file mode 100644 (file)
index e5c346e..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-//== 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 0e1d9f8cacd589f121cdfa933b91f4e0ce8ebf29..9661335a1e64715709250269b03f0dcd679825e8 100644 (file)
@@ -20,6 +20,7 @@ add_clang_library(clangAnalysis
   CheckObjCInstMethSignature.cpp
   CheckObjCUnusedIVars.cpp
   CheckSecuritySyntaxOnly.cpp
+  DereferenceChecker.cpp
   DivZeroChecker.cpp
   Environment.cpp
   ExplodedGraph.cpp
@@ -32,7 +33,6 @@ add_clang_library(clangAnalysis
   MemRegion.cpp
   NSAutoreleasePoolChecker.cpp
   NSErrorChecker.cpp
-  NullDerefChecker.cpp
   PathDiagnostic.cpp
   RangeConstraintManager.cpp
   RegionStore.cpp
@@ -42,7 +42,6 @@ add_clang_library(clangAnalysis
   SimpleSValuator.cpp
   Store.cpp
   SymbolManager.cpp
-  UndefDerefChecker.cpp
   UndefSizedVLAChecker.cpp
   UndefinedArgChecker.cpp
   UninitializedValues.cpp
similarity index 68%
rename from lib/Analysis/NullDerefChecker.cpp
rename to lib/Analysis/DereferenceChecker.cpp
index ef7da61901a214997beac26576daedb5a540087e..33c85d50746341f9de760f873ba7ba118dab2104 100644 (file)
@@ -12,7 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Analysis/PathSensitive/Checkers/NullDerefChecker.h"
+#include "clang/Analysis/PathSensitive/Checkers/DereferenceChecker.h"
 #include "clang/Analysis/PathSensitive/GRExprEngine.h"
 #include "clang/Analysis/PathSensitive/BugReporter.h"
 
@@ -74,3 +74,39 @@ ExplodedNode *NullDerefChecker::CheckLocation(const Stmt *S, ExplodedNode *Pred,
   return Builder.generateNode(S, NotNullState, Pred, 
                               ProgramPoint::PostLocationChecksSucceedKind);
 }
+
+
+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;
+}
+
index 089d25d6cf5be2167cc3a2f963718fcfef0afb7a..23ef2885a49029ddda6d09256cca23ee36e86907 100644 (file)
@@ -15,8 +15,7 @@
 #include "clang/Analysis/PathSensitive/BugReporter.h"
 #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/PathSensitive/Checkers/DereferenceChecker.h"
 #include "clang/Analysis/PathSensitive/Checkers/DivZeroChecker.h"
 #include "clang/Analysis/PathSensitive/Checkers/BadCallChecker.h"
 #include "clang/Analysis/PathSensitive/Checkers/UndefinedArgChecker.h"
index 2f6df23e08c25ef449a1f0d925173e052b1ca534..307686ff57b331eb5583324a6a91eb4a9d17801b 100644 (file)
@@ -18,7 +18,7 @@
 #include "clang/Analysis/LocalCheckers.h"
 #include "clang/Analysis/PathSensitive/BugReporter.h"
 #include "clang/Analysis/PathSensitive/GRExprEngine.h"
-#include "clang/Analysis/PathSensitive/Checkers/NullDerefChecker.h"
+#include "clang/Analysis/PathSensitive/Checkers/DereferenceChecker.h"
 #include "BasicObjCFoundationChecks.h"
 #include "llvm/Support/Compiler.h"
 #include "clang/AST/DeclObjC.h"
diff --git a/lib/Analysis/UndefDerefChecker.cpp b/lib/Analysis/UndefDerefChecker.cpp
deleted file mode 100644 (file)
index da04826..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-// 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;
-}