aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/AnalysisConsumer.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-12-07 22:06:12 +0000
committerTed Kremenek <kremenek@apple.com>2009-12-07 22:06:12 +0000
commitfc576514d06c46a7cac49500169411d82f38d04b (patch)
tree495a811390c9348fb49d4d2c8d9cd58b3d4f3976 /lib/Frontend/AnalysisConsumer.cpp
parent67d1287035767f4f6c8ca0c2bb755990012a44ca (diff)
Add clang-cc option '-analyzer-opt-analyze-nested-blocks' to treat block literals as an entry point for analyzer checks.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90810 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/AnalysisConsumer.cpp')
-rw-r--r--lib/Frontend/AnalysisConsumer.cpp41
1 files changed, 33 insertions, 8 deletions
diff --git a/lib/Frontend/AnalysisConsumer.cpp b/lib/Frontend/AnalysisConsumer.cpp
index 5df1eceb88..92f34b21fe 100644
--- a/lib/Frontend/AnalysisConsumer.cpp
+++ b/lib/Frontend/AnalysisConsumer.cpp
@@ -139,14 +139,21 @@ public:
return;
declDisplayed = true;
- // FIXME: Is getCodeDecl() always a named decl?
- if (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)) {
- const NamedDecl *ND = cast<NamedDecl>(D);
- SourceManager &SM = Mgr->getASTContext().getSourceManager();
- llvm::errs() << "ANALYZE: "
- << SM.getPresumedLoc(ND->getLocation()).getFilename()
- << ' ' << ND->getNameAsString() << '\n';
+ SourceManager &SM = Mgr->getASTContext().getSourceManager();
+ PresumedLoc Loc = SM.getPresumedLoc(D->getLocation());
+ llvm::errs() << "ANALYZE: " << Loc.getFilename();
+
+ if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
+ assert(isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D));
+ llvm::errs() << ' ' << ND->getNameAsString();
+ }
+ else {
+ assert(isa<BlockDecl>(D));
+ llvm::errs() << ' ' << "block(line:" << Loc.getLine() << ",col:"
+ << Loc.getColumn();
}
+
+ llvm::errs() << '\n';
}
void addCodeAction(CodeAction action) {
@@ -269,6 +276,16 @@ void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
Mgr.reset(NULL);
}
+static void FindBlocks(DeclContext *D, llvm::SmallVectorImpl<Decl*> &WL) {
+ if (BlockDecl *BD = dyn_cast<BlockDecl>(D))
+ WL.push_back(BD);
+
+ for (DeclContext::decl_iterator I = D->decls_begin(), E = D->decls_end();
+ I!=E; ++I)
+ if (DeclContext *DC = dyn_cast<DeclContext>(*I))
+ FindBlocks(DC, WL);
+}
+
void AnalysisConsumer::HandleCode(Decl *D, Stmt* Body, Actions& actions) {
// Don't run the actions if an error has occured with parsing the file.
@@ -285,8 +302,16 @@ void AnalysisConsumer::HandleCode(Decl *D, Stmt* Body, Actions& actions) {
Mgr->ClearContexts();
// Dispatch on the actions.
+ llvm::SmallVector<Decl*, 10> WL;
+ WL.push_back(D);
+
+ if (Opts.AnalyzeNestedBlocks)
+ FindBlocks(cast<DeclContext>(D), WL);
+
for (Actions::iterator I = actions.begin(), E = actions.end(); I != E; ++I)
- (*I)(*this, *Mgr, D);
+ for (llvm::SmallVectorImpl<Decl*>::iterator WI=WL.begin(), WE=WL.end();
+ WI != WE; ++WI)
+ (*I)(*this, *Mgr, *WI);
}
//===----------------------------------------------------------------------===//