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
class ObjCImplementationDecl;
class LangOptions;
class GRExprEngine;
+class TranslationUnitDecl;
void CheckDeadStores(CFG &cfg, LiveVariables &L, ParentMap &map,
BugReporter& BR);
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);
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)
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;
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)
// 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);
+}
+
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,