r191910 - [analyzer] Replace bug category magic strings with shared constants.
Eric Christopher
echristo at gmail.com
Thu Oct 3 11:24:29 PDT 2013
So this patch makes the core static analyzer depend upon headers in
the checkers. I don't know if that's something we want to do?
-eric
On Thu, Oct 3, 2013 at 9:57 AM, Jordan Rose <jordan_rose at apple.com> wrote:
> Author: jrose
> Date: Thu Oct 3 11:57:20 2013
> New Revision: 191910
>
> URL: http://llvm.org/viewvc/llvm-project?rev=191910&view=rev
> Log:
> [analyzer] Replace bug category magic strings with shared constants.
>
> 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!
>
> Modified:
> cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h
> cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
> cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
> cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp
> cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp
>
> Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h?rev=191910&r1=191909&r2=191910&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h (original)
> +++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/CommonBugCategories.h Thu Oct 3 11:57:20 2013
> @@ -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;
> }
>
> 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=191910&r1=191909&r2=191910&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h (original)
> +++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h Thu Oct 3 11:57:20 2013
> @@ -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 <string>
>
> @@ -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; }
> };
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=191910&r1=191909&r2=191910&view=diff
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Thu Oct 3 11:57:20 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=191910&r1=191909&r2=191910&view=diff
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSizeofPointer.cpp Thu Oct 3 11:57:20 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/CommonBugCategories.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp?rev=191910&r1=191909&r2=191910&view=diff
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/CommonBugCategories.cpp Thu Oct 3 11:57:20 2013
> @@ -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";
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list