[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.

llvm-svn: 191937
This commit is contained in:
Jordan Rose 2013-10-04 00:25:24 +00:00
parent 25d8e737d8
commit 6feda28756
9 changed files with 27 additions and 21 deletions

View File

@ -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; }
};

View File

@ -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;
}
}
}

View File

@ -23,7 +23,6 @@ add_clang_library(clangStaticAnalyzerCheckers
CheckerDocumentation.cpp
ChrootChecker.cpp
ClangCheckers.cpp
CommonBugCategories.cpp
DeadStoresChecker.cpp
DebugCheckers.cpp
DereferenceChecker.cpp

View File

@ -231,7 +231,7 @@ ProgramStateRef CStringChecker::checkNonNull(CheckerContext &C,
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(CheckerContext &C, ProgramStateRef state,
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(CheckerContext &C, ProgramStateRef &state,
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(CheckerContext &C, ProgramStateRef &state,
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;

View File

@ -65,7 +65,7 @@ void WalkAST::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
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);

View File

@ -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 {

View File

@ -2488,7 +2488,7 @@ static void dropFunctionEntryEdge(PathPieces &Path,
//===----------------------------------------------------------------------===//
// Methods for BugType and subclasses.
//===----------------------------------------------------------------------===//
BugType::~BugType() { }
void BugType::anchor() { }
void BugType::FlushReports(BugReporter &BR) {}

View File

@ -14,6 +14,7 @@ add_clang_library(clangStaticAnalyzerCore
CheckerHelpers.cpp
CheckerManager.cpp
CheckerRegistry.cpp
CommonBugCategories.cpp
ConstraintManager.cpp
CoreEngine.cpp
Environment.cpp

View File

@ -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";
}}}