[cfe-commits] r96183 - in /cfe/trunk: include/clang/Checker/Checkers/LocalCheckers.h include/clang/Frontend/Analyses.def lib/Checker/LLVMConventionsChecker.cpp lib/Frontend/AnalysisConsumer.cpp
Ted Kremenek
kremenek at apple.com
Sun Feb 14 11:09:05 PST 2010
Author: kremenek
Date: Sun Feb 14 13:09:05 2010
New Revision: 96183
URL: http://llvm.org/viewvc/llvm-project?rev=96183&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Checker/Checkers/LocalCheckers.h
cfe/trunk/include/clang/Frontend/Analyses.def
cfe/trunk/lib/Checker/LLVMConventionsChecker.cpp
cfe/trunk/lib/Frontend/AnalysisConsumer.cpp
Modified: cfe/trunk/include/clang/Checker/Checkers/LocalCheckers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Checker/Checkers/LocalCheckers.h?rev=96183&r1=96182&r2=96183&view=diff
==============================================================================
--- cfe/trunk/include/clang/Checker/Checkers/LocalCheckers.h (original)
+++ cfe/trunk/include/clang/Checker/Checkers/LocalCheckers.h Sun Feb 14 13:09:05 2010
@@ -31,6 +31,7 @@
class ObjCImplementationDecl;
class LangOptions;
class GRExprEngine;
+class TranslationUnitDecl;
void CheckDeadStores(CFG &cfg, LiveVariables &L, ParentMap &map,
BugReporter& BR);
@@ -50,7 +51,7 @@
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);
Modified: cfe/trunk/include/clang/Frontend/Analyses.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/Analyses.def?rev=96183&r1=96182&r2=96183&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/Analyses.def (original)
+++ cfe/trunk/include/clang/Frontend/Analyses.def Sun Feb 14 13:09:05 2010
@@ -30,7 +30,7 @@
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)
Modified: cfe/trunk/lib/Checker/LLVMConventionsChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/LLVMConventionsChecker.cpp?rev=96183&r1=96182&r2=96183&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/LLVMConventionsChecker.cpp (original)
+++ cfe/trunk/lib/Checker/LLVMConventionsChecker.cpp Sun Feb 14 13:09:05 2010
@@ -42,7 +42,7 @@
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::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 @@
// 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);
}
+
Modified: cfe/trunk/lib/Frontend/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/AnalysisConsumer.cpp?rev=96183&r1=96182&r2=96183&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/AnalysisConsumer.cpp Sun Feb 14 13:09:05 2010
@@ -434,10 +434,9 @@
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,
More information about the cfe-commits
mailing list