From 4587cace907ed9a68256bdae506fbb8d93ac232c Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 3 Oct 2013 16:57:20 +0000 Subject: [PATCH] [analyzer] Replace bug category magic strings with shared constants. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit One small functionality change is to bring the sizeof-pointer checker in line with the other checkers by making its category be "Logic error" instead of just "Logic". There should be no other functionality changes. Patch by Daniel Marjamäki! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191910 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../clang/StaticAnalyzer/Checkers/CommonBugCategories.h | 1 + include/clang/StaticAnalyzer/Core/BugReporter/BugType.h | 5 +++-- lib/StaticAnalyzer/Checkers/CStringChecker.cpp | 8 ++++---- lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp | 2 +- lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp | 1 + 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h b/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h index 9d4251b1a7..be4ec5effb 100644 --- a/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h +++ b/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h @@ -15,6 +15,7 @@ namespace clang { namespace ento { namespace categories { extern const char *CoreFoundationObjectiveC; + extern const char *LogicError; extern const char *MemoryCoreFoundationObjectiveC; extern const char *UnixAPI; } diff --git a/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h b/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h index 644aa31593..60397f5d47 100644 --- a/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h +++ b/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h @@ -15,6 +15,7 @@ #define LLVM_CLANG_ANALYSIS_BUGTYPE #include "clang/Basic/LLVM.h" +#include "clang/StaticAnalyzer/Checkers/CommonBugCategories.h" #include "llvm/ADT/FoldingSet.h" #include @@ -54,10 +55,10 @@ class BuiltinBug : public BugType { const std::string desc; 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; } }; diff --git a/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/lib/StaticAnalyzer/Checkers/CStringChecker.cpp index ba1d9b9ff6..e642c2974e 100644 --- a/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -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; diff --git a/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp b/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp index f2c50501a6..3eeb948798 100644 --- a/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp +++ b/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp @@ -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); diff --git a/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp b/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp index e2a8ea6166..c53e98f631 100644 --- a/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp +++ b/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp @@ -11,6 +11,7 @@ namespace clang { namespace ento { namespace categories { const char *CoreFoundationObjectiveC = "Core Foundation/Objective-C"; +const char *LogicError = "Logic error"; const char *MemoryCoreFoundationObjectiveC = "Memory (Core Foundation/Objective-C)"; const char *UnixAPI = "Unix API"; -- 2.40.0