diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-02-17 21:39:24 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-02-17 21:39:24 +0000 |
| commit | 24ffc08f394259ab926f2b7c4807e360ef04c51d (patch) | |
| tree | 0d6ece606cb9d54f15da5aff61dae48bdce84897 /clang/lib/StaticAnalyzer/Checkers | |
| parent | 507ff53e39e345e43cea08ab9abf803acba639b3 (diff) | |
| download | bcm5719-llvm-24ffc08f394259ab926f2b7c4807e360ef04c51d.tar.gz bcm5719-llvm-24ffc08f394259ab926f2b7c4807e360ef04c51d.zip | |
[analyzer]
-Introduce CheckerV2, a set of templates for convenient declaration & registration of checkers.
Currently useful just for checkers working on the AST not the path-sensitive ones.
-Enhance CheckerManager to actually collect the checkers and turn it into the entry point for
running the checkers.
-Use the new mechanism for the LLVMConventionsChecker.
llvm-svn: 125778
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers')
| -rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/Checkers.td | 7 | ||||
| -rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp | 48 |
2 files changed, 31 insertions, 24 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/Checkers.td b/clang/lib/StaticAnalyzer/Checkers/Checkers.td index 5d30894ebe1..234c23f298b 100644 --- a/clang/lib/StaticAnalyzer/Checkers/Checkers.td +++ b/clang/lib/StaticAnalyzer/Checkers/Checkers.td @@ -24,6 +24,8 @@ def CoreExperimental : Package<"experimental">, def UnixExperimental : Package<"experimental">, InPackage<Unix>, Hidden; +def LLVM : Package<"llvm">; + //===----------------------------------------------------------------------===// // Groups. //===----------------------------------------------------------------------===// @@ -84,6 +86,11 @@ def CFRetainReleaseChecker : Checker<"CFRetainRelease">, HelpText<"Check for null arguments to CFRetain/CFRelease">, DescFile<"BasicObjCFoundationChecks.cpp">; +def LLVMConventionsChecker : Checker<"Conventions">, + InPackage<LLVM>, + HelpText<"Check code for LLVM codebase conventions">, + DescFile<"LLVMConventionsChecker.cpp">; + //===----------------------------------------------------------------------===// // Hidden experimental checkers. //===----------------------------------------------------------------------===// diff --git a/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp index 92d0424fbaf..9e3adc804f6 100644 --- a/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp @@ -12,10 +12,12 @@ // //===----------------------------------------------------------------------===// -#include "clang/AST/DeclTemplate.h" -#include "clang/AST/StmtVisitor.h" +#include "ClangSACheckers.h" +#include "clang/StaticAnalyzer/Core/CheckerV2.h" #include "clang/StaticAnalyzer/Checkers/LocalCheckers.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h" +#include "clang/AST/DeclTemplate.h" +#include "clang/AST/StmtVisitor.h" #include <string> #include "llvm/ADT/StringRef.h" @@ -210,10 +212,10 @@ static bool IsPartOfAST(const CXXRecordDecl *R) { namespace { class ASTFieldVisitor { llvm::SmallVector<FieldDecl*, 10> FieldChain; - CXXRecordDecl *Root; + const CXXRecordDecl *Root; BugReporter &BR; public: - ASTFieldVisitor(CXXRecordDecl *root, BugReporter &br) + ASTFieldVisitor(const CXXRecordDecl *root, BugReporter &br) : Root(root), BR(br) {} void Visit(FieldDecl *D); @@ -221,7 +223,7 @@ public: }; } // end anonymous namespace -static void CheckASTMemory(CXXRecordDecl *R, BugReporter &BR) { +static void CheckASTMemory(const CXXRecordDecl *R, BugReporter &BR) { if (!IsPartOfAST(R)) return; @@ -283,29 +285,27 @@ void ASTFieldVisitor::ReportError(QualType T) { } //===----------------------------------------------------------------------===// -// Entry point for all checks. +// LLVMConventionsChecker //===----------------------------------------------------------------------===// -static void ScanCodeDecls(DeclContext *DC, BugReporter &BR) { - for (DeclContext::decl_iterator I=DC->decls_begin(), E=DC->decls_end(); - I!=E ; ++I) { - - Decl *D = *I; - - if (D->hasBody()) - CheckStringRefAssignedTemporary(D, BR); - - if (CXXRecordDecl *R = dyn_cast<CXXRecordDecl>(D)) - if (R->isDefinition()) - CheckASTMemory(R, BR); +namespace { +class LLVMConventionsChecker : public CheckerV2< + check::ASTDecl<CXXRecordDecl>, + check::ASTCodeBody > { +public: + void checkASTDecl(const CXXRecordDecl *R, AnalysisManager& mgr, + BugReporter &BR) const { + if (R->isDefinition()) + CheckASTMemory(R, BR); + } - if (DeclContext *DC_child = dyn_cast<DeclContext>(D)) - ScanCodeDecls(DC_child, BR); + void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, + BugReporter &BR) const { + CheckStringRefAssignedTemporary(D, BR); } +}; } -void ento::CheckLLVMConventions(TranslationUnitDecl &TU, - BugReporter &BR) { - ScanCodeDecls(&TU, BR); +void ento::registerLLVMConventionsChecker(CheckerManager &mgr) { + mgr.registerChecker<LLVMConventionsChecker>(); } - |

