diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-02-14 19:09:05 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-02-14 19:09:05 +0000 |
commit | 676ca153e04b1c6be477bc8a10f1e06256850cee (patch) | |
tree | 1ebaf2e379955b7be5d68af8c34010e85ff5c43a /lib/Checker/LLVMConventionsChecker.cpp | |
parent | f6eafcca7734274d277afa121f2c4fb025a54218 (diff) |
Change LLVMConventionsChecker to accept an entire translation unit instead
of operating on each code decl. This exposes two flaws in AnalysisConsumer
that should eventually be fixed:
(1) It is not possible to associate multiple "actions" with a single
command line argument. This will require the notion of an
"analysis" group, and possibly tablegen support. (although eventually
we want to support dynamically loading analyses as well)
(2) AnalysisConsumer may not actually be scanning the declarations in namespaces.
We'll experiment first in LLVMConventionsChecker before changing the
behavior in AnalysisConsumer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96183 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Checker/LLVMConventionsChecker.cpp')
-rw-r--r-- | lib/Checker/LLVMConventionsChecker.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/Checker/LLVMConventionsChecker.cpp b/lib/Checker/LLVMConventionsChecker.cpp index 7cd98b0319..17a17a8bbf 100644 --- a/lib/Checker/LLVMConventionsChecker.cpp +++ b/lib/Checker/LLVMConventionsChecker.cpp @@ -42,7 +42,7 @@ static bool IsStdString(QualType T) { if (!TT) return false; - const TypedefDecl *TD = TT->getDecl(); + const TypedefDecl *TD = TT->getDecl(); const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(TD->getDeclContext()); if (!ND) return false; @@ -94,7 +94,7 @@ void StringRefCheckerVisitor::VisitDeclStmt(DeclStmt *S) { void StringRefCheckerVisitor::VisitVarDecl(VarDecl *VD) { Expr *Init = VD->getInit(); if (!Init) - return; + return; // Pattern match for: // llvm::StringRef x = call() (where call returns std::string) @@ -129,6 +129,22 @@ void StringRefCheckerVisitor::VisitVarDecl(VarDecl *VD) { // Entry point for all checks. //===----------------------------------------------------------------------===// -void clang::CheckLLVMConventions(const Decl *D, BugReporter &BR) { - CheckStringRefAssignedTemporary(D, BR); +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->getBody()) { + CheckStringRefAssignedTemporary(D, BR); + } + + if (DeclContext *DC_child = dyn_cast<DeclContext>(D)) + ScanCodeDecls(DC_child, BR); + } } + +void clang::CheckLLVMConventions(TranslationUnitDecl &TU, + BugReporter &BR) { + ScanCodeDecls(&TU, BR); +} + |