]> granicus.if.org Git - clang/commitdiff
Require that all static analyzer issues have a category. As part of this change,
authorTed Kremenek <kremenek@apple.com>
Thu, 5 Apr 2012 20:43:28 +0000 (20:43 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 5 Apr 2012 20:43:28 +0000 (20:43 +0000)
consolidate some commonly used category strings into global references (more of this can be done, I just did a few).

Fixes <rdar://problem/11191537>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154121 91177308-0d34-0410-b5e6-96231b3b80d8

15 files changed:
include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h [new file with mode: 0644]
include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
lib/StaticAnalyzer/Checkers/CMakeLists.txt
lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp
lib/StaticAnalyzer/Checkers/ClangSACheckers.h
lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp [new file with mode: 0644]
lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp
lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp
lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp
lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
lib/StaticAnalyzer/Core/BugReporter.cpp

diff --git a/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h b/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h
new file mode 100644 (file)
index 0000000..9d4251b
--- /dev/null
@@ -0,0 +1,24 @@
+//=--- 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
+
index 9890a808ad8a07eabfb17f6b20e711198fdeed04..2b699a85f8ef89012e64e945b2660ed59f4cd24b 100644 (file)
@@ -357,36 +357,17 @@ public:
   /// reports.
   void EmitReport(BugReport *R);
 
-  void EmitBasicReport(const Decl *DeclWithIssue,
-                       StringRef BugName, StringRef BugStr,
-                       PathDiagnosticLocation Loc,
-                       SourceRange* RangeBeg, unsigned NumRanges);
-
   void EmitBasicReport(const Decl *DeclWithIssue,
                        StringRef BugName, StringRef BugCategory,
                        StringRef BugStr, PathDiagnosticLocation Loc,
                        SourceRange* RangeBeg, unsigned NumRanges);
 
-
-  void EmitBasicReport(const Decl *DeclWithIssue,
-                       StringRef BugName, StringRef BugStr,
-                       PathDiagnosticLocation Loc) {
-    EmitBasicReport(DeclWithIssue, BugName, BugStr, Loc, 0, 0);
-  }
-
   void EmitBasicReport(const Decl *DeclWithIssue,
                        StringRef BugName, StringRef BugCategory,
                        StringRef BugStr, PathDiagnosticLocation Loc) {
     EmitBasicReport(DeclWithIssue, BugName, BugCategory, BugStr, Loc, 0, 0);
   }
 
-  void EmitBasicReport(const Decl *DeclWithIssue,
-                       StringRef BugName, StringRef BugStr,
-                       PathDiagnosticLocation Loc,
-                       SourceRange R) {
-    EmitBasicReport(DeclWithIssue, BugName, BugStr, Loc, &R, 1);
-  }
-
   void EmitBasicReport(const Decl *DeclWithIssue,
                        StringRef BugName, StringRef Category,
                        StringRef BugStr, PathDiagnosticLocation Loc,
index 096e3f32ea324d4448d878aec7f413209e439b3b..a377ca9e4d49df5a36ffd6dd8def77394a7d045d 100644 (file)
@@ -26,6 +26,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   CheckerDocumentation.cpp
   ChrootChecker.cpp
   ClangCheckers.cpp
+  CommonBugCategories.cpp
   DeadStoresChecker.cpp
   DebugCheckers.cpp
   DereferenceChecker.cpp
index 690e2ce346f2857a0213a5281bfb0d922670bd55..133204a6d350cb12db42fd8c16c8be941dd2bb09 100644 (file)
@@ -179,7 +179,8 @@ static void checkObjCDealloc(const ObjCImplementationDecl *D,
     llvm::raw_string_ostream os(buf);
     os << "Objective-C class '" << *D << "' lacks a 'dealloc' instance method";
 
-    BR.EmitBasicReport(D, name, os.str(), DLoc);
+    BR.EmitBasicReport(D, name, categories::CoreFoundationObjectiveC,
+                       os.str(), DLoc);
     return;
   }
 
@@ -196,7 +197,8 @@ static void checkObjCDealloc(const ObjCImplementationDecl *D,
        << "' does not send a 'dealloc' message to its super class"
            " (missing [super dealloc])";
 
-    BR.EmitBasicReport(MD, name, os.str(), DLoc);
+    BR.EmitBasicReport(MD, name, categories::CoreFoundationObjectiveC,
+                       os.str(), DLoc);
     return;
   }
 
@@ -236,9 +238,7 @@ static void checkObjCDealloc(const ObjCImplementationDecl *D,
     bool requiresRelease = PD->getSetterKind() != ObjCPropertyDecl::Assign;
     if (scan_ivar_release(MD->getBody(), ID, PD, RS, SelfII, Ctx)
        != requiresRelease) {
-      const char *name;
-      const char* category = "Memory (Core Foundation/Objective-C)";
-
+      const char *name = 0;
       std::string buf;
       llvm::raw_string_ostream os(buf);
 
@@ -263,7 +263,8 @@ static void checkObjCDealloc(const ObjCImplementationDecl *D,
       PathDiagnosticLocation SDLoc =
         PathDiagnosticLocation::createBegin((*I), BR.getSourceManager());
 
-      BR.EmitBasicReport(MD, name, category, os.str(), SDLoc);
+      BR.EmitBasicReport(MD, name, categories::CoreFoundationObjectiveC,
+                         os.str(), SDLoc);
     }
   }
 }
index d7321fa3cffb76b5cdd5d99108308f0c5133fbb3..6df47b1d9998d02a94785815c905f382d4bff0e4 100644 (file)
@@ -72,6 +72,7 @@ static void CompareReturnTypes(const ObjCMethodDecl *MethDerived,
 
     BR.EmitBasicReport(MethDerived,
                        "Incompatible instance method return type",
+                       categories::CoreFoundationObjectiveC,
                        os.str(), MethDLoc);
   }
 }
index 289ce8d8c3baa45a3f91cba1cb5a548c2b34f0da..230baa759c5ac83ab7fe16a9bd1c3287e8c17890 100644 (file)
@@ -12,6 +12,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "clang/StaticAnalyzer/Checkers/CommonBugCategories.h"
+
 #ifndef LLVM_CLANG_SA_LIB_CHECKERS_CLANGSACHECKERS_H
 #define LLVM_CLANG_SA_LIB_CHECKERS_CLANGSACHECKERS_H
 
diff --git a/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp b/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp
new file mode 100644 (file)
index 0000000..e2a8ea6
--- /dev/null
@@ -0,0 +1,18 @@
+//=--- 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";
+}}}
+
index b11c94793f5d708afe9a5c9c400eab87ff968284..daec4180a0c2063bc6f5fbaa5b4aeeb9d91adc1b 100644 (file)
@@ -214,7 +214,7 @@ void MallocOverflowSecurityChecker::OutputPossibleOverflows(
        i != e;
        ++i) {
     SourceRange R = i->mulop->getSourceRange();
-    BR.EmitBasicReport(D, "malloc() size overflow",
+    BR.EmitBasicReport(D, "malloc() size overflow", categories::UnixAPI,
       "the computation of the size of the memory allocation may overflow",
       PathDiagnosticLocation::createOperatorLoc(i->mulop,
                                                 BR.getSourceManager()), &R, 1);
index 4e10633da7bd5df0482cf5f0008c3548b5378ed7..08a9da1fe3ef9a8880be6bd8a7be54fc5c4213af 100644 (file)
@@ -194,7 +194,9 @@ public:
             PathDiagnosticLocation::createBegin(i->AllocCall->getCallee(),
                                                 BR.getSourceManager(), ADC);
 
-          BR.EmitBasicReport(D, "allocator sizeof operand mismatch", OS.str(),
+          BR.EmitBasicReport(D, "allocator sizeof operand mismatch",
+                             categories::UnixAPI,
+                             OS.str(),
                              L, Ranges.data(), Ranges.size());
         }
       }
index aeb90a6e51043545a4ad2a5f87ec94fde0caf52f..f2929c03cc0be974605adfc211fabbbba85cc5dc 100644 (file)
@@ -143,7 +143,7 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
     PathDiagnosticLocation CELoc =
         PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);
     BR.EmitBasicReport(AC->getDecl(),
-                       OsName.str(), "Core Foundation/Objective-C",
+                       OsName.str(), categories::CoreFoundationObjectiveC,
                        Os.str(), CELoc, &R, 1);
   }
 
index 207d65ad8fbed49b926e352f149a47722eb87c8c..f4655b6793d25097237b7359c7f4d7653ef303c1 100644 (file)
@@ -34,7 +34,8 @@ class ObjCContainersChecker : public Checker< check::PreStmt<CallExpr>,
   mutable OwningPtr<BugType> BT;
   inline void initBugType() const {
     if (!BT)
-      BT.reset(new BugType("CFArray API", "Core Foundation/Objective-C"));
+      BT.reset(new BugType("CFArray API",
+                           categories::CoreFoundationObjectiveC));
   }
 
   inline SymbolRef getArraySym(const Expr *E, CheckerContext &C) const {
index 9d77ad4daaacac6fbb0fed19d257d10801f74574..d15c8ba408a42c2beaf6cff6e2e2a9f61c65ba12 100644 (file)
@@ -83,7 +83,7 @@ class InitSelfBug : public BugType {
   const std::string desc;
 public:
   InitSelfBug() : BugType("Missing \"self = [(super or self) init...]\"",
-                          "Core Foundation/Objective-C") {}
+                          categories::CoreFoundationObjectiveC) {}
 };
 
 } // end anonymous namespace
index 7fa6975478bc430f6a6ab1e886f3b938673d9532..b569e412c41f48463eddcff3803c57bbdb8b74f8 100644 (file)
@@ -1620,7 +1620,7 @@ namespace {
   class CFRefBug : public BugType {
   protected:
     CFRefBug(StringRef name)
-    : BugType(name, "Memory (Core Foundation/Objective-C)") {}
+    : BugType(name, categories::MemoryCoreFoundationObjectiveC) {}
   public:
 
     // FIXME: Eventually remove.
index e68ab2a8b2a372ada415823d64e70d61da655e8a..60e665fed3b064bd7564b0ab1bef1ed8d5279731 100644 (file)
@@ -67,7 +67,7 @@ static inline void LazyInitialize(OwningPtr<BugType> &BT,
                                   const char *name) {
   if (BT)
     return;
-  BT.reset(new BugType(name, "Unix API"));
+  BT.reset(new BugType(name, categories::UnixAPI));
 }
 
 //===----------------------------------------------------------------------===//
index 2752e32e50862d51ec1f1e8c268eab82e41aec8b..a2642120b70f8ace26499a863ab19fcb47e43eac 100644 (file)
@@ -2027,13 +2027,6 @@ void BugReporter::FlushReport(BugReportEquivClass& EQ) {
   PD->HandlePathDiagnostic(D.take());
 }
 
-void BugReporter::EmitBasicReport(const Decl *DeclWithIssue,
-                                  StringRef name, StringRef str,
-                                  PathDiagnosticLocation Loc,
-                                  SourceRange* RBeg, unsigned NumRanges) {
-  EmitBasicReport(DeclWithIssue, name, "", str, Loc, RBeg, NumRanges);
-}
-
 void BugReporter::EmitBasicReport(const Decl *DeclWithIssue,
                                   StringRef name,
                                   StringRef category,