aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Checker/Checkers/LocalCheckers.h3
-rw-r--r--include/clang/Frontend/Analyses.def2
-rw-r--r--lib/Checker/LLVMConventionsChecker.cpp24
-rw-r--r--lib/Frontend/AnalysisConsumer.cpp5
4 files changed, 25 insertions, 9 deletions
diff --git a/include/clang/Checker/Checkers/LocalCheckers.h b/include/clang/Checker/Checkers/LocalCheckers.h
index a262aaa1fb..4a9e381a7c 100644
--- a/include/clang/Checker/Checkers/LocalCheckers.h
+++ b/include/clang/Checker/Checkers/LocalCheckers.h
@@ -31,6 +31,7 @@ class BugReporter;
class ObjCImplementationDecl;
class LangOptions;
class GRExprEngine;
+class TranslationUnitDecl;
void CheckDeadStores(CFG &cfg, LiveVariables &L, ParentMap &map,
BugReporter& BR);
@@ -50,7 +51,7 @@ void RegisterAppleChecks(GRExprEngine& Eng, const Decl &D);
void RegisterExperimentalChecks(GRExprEngine &Eng);
void RegisterExperimentalInternalChecks(GRExprEngine &Eng);
-void CheckLLVMConventions(const Decl *D, BugReporter &BR);
+void CheckLLVMConventions(TranslationUnitDecl &TU, BugReporter &BR);
void CheckSecuritySyntaxOnly(const Decl *D, BugReporter &BR);
void CheckSizeofPointer(const Decl *D, BugReporter &BR);
diff --git a/include/clang/Frontend/Analyses.def b/include/clang/Frontend/Analyses.def
index 6ea43f7341..287c67ebb7 100644
--- a/include/clang/Frontend/Analyses.def
+++ b/include/clang/Frontend/Analyses.def
@@ -30,7 +30,7 @@ ANALYSIS(SecuritySyntacticChecks, "analyzer-check-security-syntactic",
ANALYSIS(LLVMConventionChecker, "analyzer-check-llvm-conventions",
"Check code for LLVM codebase conventions (domain-specific)",
- Code)
+ TranslationUnit)
ANALYSIS(WarnDeadStores, "analyzer-check-dead-stores",
"Warn about stores to dead variables", Code)
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);
+}
+
diff --git a/lib/Frontend/AnalysisConsumer.cpp b/lib/Frontend/AnalysisConsumer.cpp
index b03d65afcd..d764fd0789 100644
--- a/lib/Frontend/AnalysisConsumer.cpp
+++ b/lib/Frontend/AnalysisConsumer.cpp
@@ -434,10 +434,9 @@ static void ActionSecuritySyntacticChecks(AnalysisConsumer &C,
static void ActionLLVMConventionChecker(AnalysisConsumer &C,
AnalysisManager &mgr,
- Decl *D) {
- C.DisplayFunction(D);
+ TranslationUnitDecl &TU) {
BugReporter BR(mgr);
- CheckLLVMConventions(D, BR);
+ CheckLLVMConventions(TU, BR);
}
static void ActionWarnObjCDealloc(AnalysisConsumer &C, AnalysisManager& mgr,