r191937 - [analyzer] Replace bug category magic strings with shared constants, take 2.

Jordan Rose jordan_rose at apple.com
Thu Oct 3 17:25:24 PDT 2013


Author: jrose
Date: Thu Oct  3 19:25:24 2013
New Revision: 191937

URL: http://llvm.org/viewvc/llvm-project?rev=191937&view=rev
Log:
[analyzer] Replace bug category magic strings with shared constants, take 2.

Re-commit r191910 (reverted in r191936) with layering violation fixed, by
moving the bug categories to StaticAnalyzerCore instead of ...Checkers.

Added:
    cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
      - copied, changed from r191936, cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h
    cfe/trunk/lib/StaticAnalyzer/Core/CommonBugCategories.cpp
      - copied, changed from r191936, cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp
Removed:
    cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h
    cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp
Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
    cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
    cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
    cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp
    cfe/trunk/lib/StaticAnalyzer/Checkers/ClangSACheckers.h
    cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt

Removed: cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h?rev=191936&view=auto
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h (removed)
@@ -1,24 +0,0 @@
-//=--- CommonBugCategories.h - Provides common issue categories -*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_STATIC_ANALYZER_CHECKER_CATEGORIES_H
-#define LLVM_CLANG_STATIC_ANALYZER_CHECKER_CATEGORIES_H
-
-// Common strings used for the "category" of many static analyzer issues.
-namespace clang {
-  namespace ento {
-    namespace categories {
-      extern const char *CoreFoundationObjectiveC;
-      extern const char *MemoryCoreFoundationObjectiveC;
-      extern const char *UnixAPI;
-    }
-  }
-}
-#endif
-

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h?rev=191937&r1=191936&r2=191937&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h Thu Oct  3 19:25:24 2013
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_ANALYSIS_BUGTYPE
 #define LLVM_CLANG_ANALYSIS_BUGTYPE
 
+#include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/FoldingSet.h"
 #include <string>
@@ -31,10 +32,12 @@ private:
   const std::string Name;
   const std::string Category;
   bool SuppressonSink;
+
+  virtual void anchor();
 public:
   BugType(StringRef name, StringRef cat)
     : Name(name), Category(cat), SuppressonSink(false) {}
-  virtual ~BugType();
+  virtual ~BugType() {}
 
   // FIXME: Should these be made strings as well?
   StringRef getName() const { return Name; }
@@ -50,14 +53,14 @@ public:
 };
 
 class BuiltinBug : public BugType {
-  virtual void anchor();
   const std::string desc;
+  virtual void anchor();
 public:
   BuiltinBug(const char *name, const char *description)
-    : BugType(name, "Logic error"), desc(description) {}
+    : BugType(name, categories::LogicError), desc(description) {}
   
   BuiltinBug(const char *name)
-    : BugType(name, "Logic error"), desc(name) {}
+    : BugType(name, categories::LogicError), desc(name) {}
   
   StringRef getDescription() const { return desc; }
 };

Copied: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h (from r191936, cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h?p2=cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h&p1=cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h&r1=191936&r2=191937&rev=191937&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h Thu Oct  3 19:25:24 2013
@@ -7,16 +7,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_CLANG_STATIC_ANALYZER_CHECKER_CATEGORIES_H
-#define LLVM_CLANG_STATIC_ANALYZER_CHECKER_CATEGORIES_H
+#ifndef LLVM_CLANG_STATIC_ANALYZER_BUG_CATEGORIES_H
+#define LLVM_CLANG_STATIC_ANALYZER_BUG_CATEGORIES_H
 
 // Common strings used for the "category" of many static analyzer issues.
 namespace clang {
   namespace ento {
     namespace categories {
-      extern const char *CoreFoundationObjectiveC;
-      extern const char *MemoryCoreFoundationObjectiveC;
-      extern const char *UnixAPI;
+      extern const char * const CoreFoundationObjectiveC;
+      extern const char * const LogicError;
+      extern const char * const MemoryCoreFoundationObjectiveC;
+      extern const char * const UnixAPI;
     }
   }
 }

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=191937&r1=191936&r2=191937&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Thu Oct  3 19:25:24 2013
@@ -23,7 +23,6 @@ add_clang_library(clangStaticAnalyzerChe
   CheckerDocumentation.cpp
   ChrootChecker.cpp
   ClangCheckers.cpp
-  CommonBugCategories.cpp
   DeadStoresChecker.cpp
   DebugCheckers.cpp
   DereferenceChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=191937&r1=191936&r2=191937&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Thu Oct  3 19:25:24 2013
@@ -231,7 +231,7 @@ ProgramStateRef CStringChecker::checkNon
       return NULL;
 
     if (!BT_Null)
-      BT_Null.reset(new BuiltinBug("Unix API",
+      BT_Null.reset(new BuiltinBug(categories::UnixAPI,
         "Null pointer argument in call to byte string function"));
 
     SmallString<80> buf;
@@ -525,7 +525,7 @@ void CStringChecker::emitOverlapBug(Chec
     return;
 
   if (!BT_Overlap)
-    BT_Overlap.reset(new BugType("Unix API", "Improper arguments"));
+    BT_Overlap.reset(new BugType(categories::UnixAPI, "Improper arguments"));
 
   // Generate a report for this bug.
   BugReport *report = 
@@ -702,7 +702,7 @@ SVal CStringChecker::getCStringLength(Ch
 
       if (ExplodedNode *N = C.addTransition(state)) {
         if (!BT_NotCString)
-          BT_NotCString.reset(new BuiltinBug("Unix API",
+          BT_NotCString.reset(new BuiltinBug(categories::UnixAPI,
             "Argument is not a null-terminated string."));
 
         SmallString<120> buf;
@@ -762,7 +762,7 @@ SVal CStringChecker::getCStringLength(Ch
 
     if (ExplodedNode *N = C.addTransition(state)) {
       if (!BT_NotCString)
-        BT_NotCString.reset(new BuiltinBug("Unix API",
+        BT_NotCString.reset(new BuiltinBug(categories::UnixAPI,
           "Argument is not a null-terminated string."));
 
       SmallString<120> buf;

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp?rev=191937&r1=191936&r2=191937&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp Thu Oct  3 19:25:24 2013
@@ -65,7 +65,7 @@ void WalkAST::VisitUnaryExprOrTypeTraitE
       PathDiagnosticLocation::createBegin(E, BR.getSourceManager(), AC);
     BR.EmitBasicReport(AC->getDecl(),
                        "Potential unintended use of sizeof() on pointer type",
-                       "Logic",
+                       categories::LogicError,
                        "The code calls sizeof() on a pointer type. "
                        "This can produce an unexpected result.",
                        ELoc, &R, 1);

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ClangSACheckers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ClangSACheckers.h?rev=191937&r1=191936&r2=191937&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ClangSACheckers.h (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ClangSACheckers.h Thu Oct  3 19:25:24 2013
@@ -15,7 +15,7 @@
 #ifndef LLVM_CLANG_SA_LIB_CHECKERS_CLANGSACHECKERS_H
 #define LLVM_CLANG_SA_LIB_CHECKERS_CLANGSACHECKERS_H
 
-#include "clang/StaticAnalyzer/Checkers/CommonBugCategories.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
 
 namespace clang {
 

Removed: cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp?rev=191936&view=auto
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp (removed)
@@ -1,18 +0,0 @@
-//=--- CommonBugCategories.cpp - Provides common issue categories -*- C++ -*-=//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// Common strings used for the "category" of many static analyzer issues.
-namespace clang { namespace ento { namespace categories {
-
-const char *CoreFoundationObjectiveC = "Core Foundation/Objective-C";
-const char *MemoryCoreFoundationObjectiveC =
-  "Memory (Core Foundation/Objective-C)";
-const char *UnixAPI = "Unix API";
-}}}
-

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=191937&r1=191936&r2=191937&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Thu Oct  3 19:25:24 2013
@@ -2488,7 +2488,7 @@ static void dropFunctionEntryEdge(PathPi
 //===----------------------------------------------------------------------===//
 // Methods for BugType and subclasses.
 //===----------------------------------------------------------------------===//
-BugType::~BugType() { }
+void BugType::anchor() { }
 
 void BugType::FlushReports(BugReporter &BR) {}
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt?rev=191937&r1=191936&r2=191937&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt Thu Oct  3 19:25:24 2013
@@ -14,6 +14,7 @@ add_clang_library(clangStaticAnalyzerCor
   CheckerHelpers.cpp
   CheckerManager.cpp
   CheckerRegistry.cpp
+  CommonBugCategories.cpp
   ConstraintManager.cpp
   CoreEngine.cpp
   Environment.cpp

Copied: cfe/trunk/lib/StaticAnalyzer/Core/CommonBugCategories.cpp (from r191936, cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CommonBugCategories.cpp?p2=cfe/trunk/lib/StaticAnalyzer/Core/CommonBugCategories.cpp&p1=cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp&r1=191936&r2=191937&rev=191937&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CommonBugCategories.cpp Thu Oct  3 19:25:24 2013
@@ -7,12 +7,14 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
+
 // Common strings used for the "category" of many static analyzer issues.
 namespace clang { namespace ento { namespace categories {
 
-const char *CoreFoundationObjectiveC = "Core Foundation/Objective-C";
-const char *MemoryCoreFoundationObjectiveC =
+const char * const CoreFoundationObjectiveC = "Core Foundation/Objective-C";
+const char * const LogicError = "Logic error";
+const char * const MemoryCoreFoundationObjectiveC =
   "Memory (Core Foundation/Objective-C)";
-const char *UnixAPI = "Unix API";
+const char * const UnixAPI = "Unix API";
 }}}
-





More information about the cfe-commits mailing list