From 39df94b00d86c720da50271b6aadb495a3f434ee Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sun, 14 Feb 2010 19:08:51 +0000 Subject: [PATCH] Rework translation unit actions to actually take an entire translation unit as imput. llvm-svn: 96182 --- clang/lib/Frontend/AnalysisConsumer.cpp | 95 +++++++++++++------------ 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/clang/lib/Frontend/AnalysisConsumer.cpp b/clang/lib/Frontend/AnalysisConsumer.cpp index 64fa1d24f73e..b03d65afcdf1 100644 --- a/clang/lib/Frontend/AnalysisConsumer.cpp +++ b/clang/lib/Frontend/AnalysisConsumer.cpp @@ -65,13 +65,17 @@ namespace { class AnalysisConsumer : public ASTConsumer { public: typedef void (*CodeAction)(AnalysisConsumer &C, AnalysisManager &M, Decl *D); - + typedef void (*TUAction)(AnalysisConsumer &C, AnalysisManager &M, + TranslationUnitDecl &TU); + private: typedef std::vector Actions; + typedef std::vector TUActions; + Actions FunctionActions; Actions ObjCMethodActions; Actions ObjCImplementationActions; - Actions TranslationUnitActions; + TUActions TranslationUnitActions; public: ASTContext* Ctx; @@ -134,11 +138,11 @@ public: } } } - + void DisplayFunction(const Decl *D) { if (!Opts.AnalyzerDisplayProgress || declDisplayed) return; - + declDisplayed = true; SourceManager &SM = Mgr->getASTContext().getSourceManager(); PresumedLoc Loc = SM.getPresumedLoc(D->getLocation()); @@ -163,7 +167,7 @@ public: ObjCImplementationActions.push_back(action); } - void addTranslationUnitAction(CodeAction action) { + void addTranslationUnitAction(TUAction action) { TranslationUnitActions.push_back(action); } @@ -192,7 +196,7 @@ public: namespace llvm { template <> struct FoldingSetTrait { - static inline void Profile(AnalysisConsumer::CodeAction X, + static inline void Profile(AnalysisConsumer::CodeAction X, FoldingSetNodeID& ID) { ID.AddPointer(reinterpret_cast(reinterpret_cast(X))); } @@ -238,30 +242,12 @@ void AnalysisConsumer::HandleTopLevelSingleDecl(Decl *D) { } void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) { - - TranslationUnitDecl *TU = C.getTranslationUnitDecl(); - - if (!TranslationUnitActions.empty()) { - // Find the entry function definition (if any). - FunctionDecl *FD = 0; - // Must specify an entry function. - if (!Opts.AnalyzeSpecificFunction.empty()) { - for (DeclContext::decl_iterator I=TU->decls_begin(), E=TU->decls_end(); - I != E; ++I) { - if (FunctionDecl *fd = dyn_cast(*I)) - if (fd->isThisDeclarationADefinition() && - fd->getNameAsString() == Opts.AnalyzeSpecificFunction) { - FD = fd; - break; - } - } - } - if (FD) { - for (Actions::iterator I = TranslationUnitActions.begin(), - E = TranslationUnitActions.end(); I != E; ++I) - (*I)(*this, *Mgr, FD); - } + TranslationUnitDecl *TU = C.getTranslationUnitDecl(); + + for (TUActions::iterator I = TranslationUnitActions.begin(), + E = TranslationUnitActions.end(); I != E; ++I) { + (*I)(*this, *Mgr, *TU); } if (!ObjCImplementationActions.empty()) { @@ -282,7 +268,7 @@ void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) { static void FindBlocks(DeclContext *D, llvm::SmallVectorImpl &WL) { if (BlockDecl *BD = dyn_cast(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(*I)) @@ -303,14 +289,14 @@ void AnalysisConsumer::HandleCode(Decl *D, Stmt* Body, Actions& actions) { // Clear the AnalysisManager of old AnalysisContexts. Mgr->ClearContexts(); - + // Dispatch on the actions. llvm::SmallVector WL; WL.push_back(D); - + if (Body && Opts.AnalyzeNestedBlocks) FindBlocks(cast(D), WL); - + for (Actions::iterator I = actions.begin(), E = actions.end(); I != E; ++I) for (llvm::SmallVectorImpl::iterator WI=WL.begin(), WE=WL.end(); WI != WE; ++WI) @@ -340,7 +326,7 @@ static void ActionWarnUninitVals(AnalysisConsumer &C, AnalysisManager& mgr, static void ActionGRExprEngine(AnalysisConsumer &C, AnalysisManager& mgr, - Decl *D, + Decl *D, GRTransferFuncs* tf) { llvm::OwningPtr TF(tf); @@ -352,18 +338,18 @@ static void ActionGRExprEngine(AnalysisConsumer &C, AnalysisManager& mgr, // information to see if the CFG is valid. // FIXME: Inter-procedural analysis will need to handle invalid CFGs. if (!mgr.getLiveVariables(D)) - return; - + return; + GRExprEngine Eng(mgr, TF.take()); - + if (C.Opts.EnableExperimentalInternalChecks) RegisterExperimentalInternalChecks(Eng); - + RegisterAppleChecks(Eng, *D); - + if (C.Opts.EnableExperimentalChecks) RegisterExperimentalChecks(Eng); - + // Set the graph auditor. llvm::OwningPtr Auditor; if (mgr.shouldVisualizeUbigraph()) { @@ -486,8 +472,29 @@ static void ActionWarnSizeofPointer(AnalysisConsumer &C, AnalysisManager &mgr, } static void ActionInlineCall(AnalysisConsumer &C, AnalysisManager &mgr, - Decl *D) { - // FIXME: This is largely copy of ActionGRExprEngine. Needs cleanup. + TranslationUnitDecl &TU) { + + // Find the entry function definition (if any). + FunctionDecl *D = 0; + + // Must specify an entry function. + if (!C.Opts.AnalyzeSpecificFunction.empty()) { + for (DeclContext::decl_iterator I=TU.decls_begin(), E=TU.decls_end(); + I != E; ++I) { + if (FunctionDecl *fd = dyn_cast(*I)) + if (fd->isThisDeclarationADefinition() && + fd->getNameAsString() == C.Opts.AnalyzeSpecificFunction) { + D = fd; + break; + } + } + } + + if (!D) + return; + + + // FIXME: This is largely copy of ActionGRExprEngine. Needs cleanup. // Display progress. C.DisplayFunction(D); @@ -497,9 +504,9 @@ static void ActionInlineCall(AnalysisConsumer &C, AnalysisManager &mgr, if (C.Opts.EnableExperimentalInternalChecks) RegisterExperimentalInternalChecks(Eng); - + RegisterAppleChecks(Eng, *D); - + if (C.Opts.EnableExperimentalChecks) RegisterExperimentalChecks(Eng);