]> granicus.if.org Git - clang/commitdiff
Merge ZeroSizedVLAChecker and UndefSizedVLAChecker.
authorZhongxing Xu <xuzhongxing@gmail.com>
Wed, 4 Nov 2009 01:43:07 +0000 (01:43 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Wed, 4 Nov 2009 01:43:07 +0000 (01:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85996 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/Checkers/UndefSizedVLAChecker.h [deleted file]
include/clang/Analysis/PathSensitive/Checkers/VLASizeChecker.h [moved from include/clang/Analysis/PathSensitive/Checkers/ZeroSizedVLAChecker.h with 60% similarity]
lib/Analysis/CMakeLists.txt
lib/Analysis/GRExprEngineInternalChecks.cpp
lib/Analysis/UndefSizedVLAChecker.cpp [deleted file]
lib/Analysis/VLASizeChecker.cpp [moved from lib/Analysis/ZeroSizedVLAChecker.cpp with 58% similarity]

diff --git a/include/clang/Analysis/PathSensitive/Checkers/UndefSizedVLAChecker.h b/include/clang/Analysis/PathSensitive/Checkers/UndefSizedVLAChecker.h
deleted file mode 100644 (file)
index 9d4507c..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-//=== UndefSizedVLAChecker.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 UndefSizedVLAChecker, a builtin check in GRExprEngine that 
-// performs checks for declaration of VLA of undefined size.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Analysis/PathSensitive/Checker.h"
-
-namespace clang {
-
-class UndefSizedVLAChecker : public Checker {
-  BugType *BT;
-
-public:
-  UndefSizedVLAChecker() : BT(0) {}
-  static void *getTag();
-  ExplodedNode *CheckType(QualType T, ExplodedNode *Pred, 
-                          const GRState *state, Stmt *S, GRExprEngine &Eng);
-};
-
-}
similarity index 60%
rename from include/clang/Analysis/PathSensitive/Checkers/ZeroSizedVLAChecker.h
rename to include/clang/Analysis/PathSensitive/Checkers/VLASizeChecker.h
index 4d3be31acfc9a7649d8d7bd9d31fb0b8cbd39eee..b339b3d301417072394a8d214d13854c655e8822 100644 (file)
@@ -1,4 +1,4 @@
-//=== ZeroSizedVLAChecker.cpp - Undefined dereference checker ---*- C++ -*-===//
+//=== VLASizeChecker.h - Undefined dereference checker ----------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This defines ZeorSizedVLAChecker, a builtin check in GRExprEngine that 
-// performs checks for declaration of VLA of zero size.
+// This defines two VLASizeCheckers, a builtin check in GRExprEngine that 
+// performs checks for declaration of VLA of undefined or zero size.
 //
 //===----------------------------------------------------------------------===//
 
 
 namespace clang {
 
+class UndefSizedVLAChecker : public Checker {
+  BugType *BT;
+
+public:
+  UndefSizedVLAChecker() : BT(0) {}
+  static void *getTag();
+  ExplodedNode *CheckType(QualType T, ExplodedNode *Pred, 
+                          const GRState *state, Stmt *S, GRExprEngine &Eng);
+};
+
 class ZeroSizedVLAChecker : public Checker {
   BugType *BT;
 
index 9661335a1e64715709250269b03f0dcd679825e8..ce34f1b3d7a983e30e3a9eaeb5ae836d9ca5fdb1 100644 (file)
@@ -42,11 +42,10 @@ add_clang_library(clangAnalysis
   SimpleSValuator.cpp
   Store.cpp
   SymbolManager.cpp
-  UndefSizedVLAChecker.cpp
   UndefinedArgChecker.cpp
   UninitializedValues.cpp
   ValueManager.cpp
-  ZeroSizedVLAChecker.cpp
+  VLASizeChecker.cpp
   )
 
 add_dependencies(clangAnalysis ClangDiagnosticAnalysis)
index 23ef2885a49029ddda6d09256cca23ee36e86907..e0112ee9843adfec0fe3fba3884a62ffebdf591c 100644 (file)
@@ -20,8 +20,7 @@
 #include "clang/Analysis/PathSensitive/Checkers/BadCallChecker.h"
 #include "clang/Analysis/PathSensitive/Checkers/UndefinedArgChecker.h"
 #include "clang/Analysis/PathSensitive/Checkers/AttrNonNullChecker.h"
-#include "clang/Analysis/PathSensitive/Checkers/UndefSizedVLAChecker.h"
-#include "clang/Analysis/PathSensitive/Checkers/ZeroSizedVLAChecker.h"
+#include "clang/Analysis/PathSensitive/Checkers/VLASizeChecker.h"
 #include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/Support/Compiler.h"
diff --git a/lib/Analysis/UndefSizedVLAChecker.cpp b/lib/Analysis/UndefSizedVLAChecker.cpp
deleted file mode 100644 (file)
index e51e10e..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-//=== UndefSizedVLAChecker.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 UndefSizedVLAChecker, a builtin check in GRExprEngine that 
-// performs checks for declaration of VLA of undefined size.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Analysis/PathSensitive/Checkers/UndefSizedVLAChecker.h"
-#include "clang/Analysis/PathSensitive/GRExprEngine.h"
-#include "clang/Analysis/PathSensitive/BugReporter.h"
-
-using namespace clang;
-
-void *UndefSizedVLAChecker::getTag() {
-  static int x = 0;
-  return &x;
-}
-
-ExplodedNode *UndefSizedVLAChecker::CheckType(QualType T, ExplodedNode *Pred,
-                                              const GRState *state,
-                                              Stmt *S, GRExprEngine &Eng) {
-  GRStmtNodeBuilder &Builder = Eng.getBuilder();
-  BugReporter &BR = Eng.getBugReporter();
-
-  if (VariableArrayType* VLA = dyn_cast<VariableArrayType>(T)) {
-    // FIXME: Handle multi-dimensional VLAs.
-    Expr* SE = VLA->getSizeExpr();
-    SVal Size_untested = state->getSVal(SE);
-
-    if (Size_untested.isUndef()) {
-      if (ExplodedNode* N = Builder.generateNode(S, state, Pred)) {
-        N->markAsSink();
-        if (!BT)
-          BT = new BugType("Declare variable-length array (VLA) of undefined "
-                            "size", "Logic error");
-
-        EnhancedBugReport *R =
-                          new EnhancedBugReport(*BT, BT->getName().c_str(), N);
-        R->addRange(SE->getSourceRange());
-        R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, SE);
-        BR.EmitReport(R);
-      }
-      return 0;    
-    }
-  }
-  return Pred;
-}
similarity index 58%
rename from lib/Analysis/ZeroSizedVLAChecker.cpp
rename to lib/Analysis/VLASizeChecker.cpp
index 8984a5f39058a878c789171d3119593eebd56ddf..76e4477449ed46792c181f3af5e53839ab9878b3 100644 (file)
@@ -1,4 +1,4 @@
-//=== ZeroSizedVLAChecker.cpp - Undefined dereference checker ---*- C++ -*-===//
+//=== VLASizeChecker.cpp - Undefined dereference checker --------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,17 +7,52 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This defines ZeorSizedVLAChecker, a builtin check in GRExprEngine that 
-// performs checks for declaration of VLA of zero size.
+// This defines two VLASizeCheckers, a builtin check in GRExprEngine that 
+// performs checks for declaration of VLA of undefined or zero size.
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Analysis/PathSensitive/Checkers/ZeroSizedVLAChecker.h"
+#include "clang/Analysis/PathSensitive/Checkers/VLASizeChecker.h"
 #include "clang/Analysis/PathSensitive/GRExprEngine.h"
 #include "clang/Analysis/PathSensitive/BugReporter.h"
 
 using namespace clang;
 
+void *UndefSizedVLAChecker::getTag() {
+  static int x = 0;
+  return &x;
+}
+
+ExplodedNode *UndefSizedVLAChecker::CheckType(QualType T, ExplodedNode *Pred,
+                                              const GRState *state,
+                                              Stmt *S, GRExprEngine &Eng) {
+  GRStmtNodeBuilder &Builder = Eng.getBuilder();
+  BugReporter &BR = Eng.getBugReporter();
+
+  if (VariableArrayType* VLA = dyn_cast<VariableArrayType>(T)) {
+    // FIXME: Handle multi-dimensional VLAs.
+    Expr* SE = VLA->getSizeExpr();
+    SVal Size_untested = state->getSVal(SE);
+
+    if (Size_untested.isUndef()) {
+      if (ExplodedNode* N = Builder.generateNode(S, state, Pred)) {
+        N->markAsSink();
+        if (!BT)
+          BT = new BugType("Declare variable-length array (VLA) of undefined "
+                            "size", "Logic error");
+
+        EnhancedBugReport *R =
+                          new EnhancedBugReport(*BT, BT->getName().c_str(), N);
+        R->addRange(SE->getSourceRange());
+        R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, SE);
+        BR.EmitReport(R);
+      }
+      return 0;    
+    }
+  }
+  return Pred;
+}
+
 void *ZeroSizedVLAChecker::getTag() {
   static int x;
   return &x;
@@ -64,3 +99,4 @@ ExplodedNode *ZeroSizedVLAChecker::CheckType(QualType T, ExplodedNode *Pred,
   else
     return Pred;
 }
+