diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-02-16 09:31:36 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-02-16 09:31:36 +0000 |
commit | fd035e6496665b1f1197868e21cb0a4594e8db6e (patch) | |
tree | 53010172e19c77ea447bcd89e117cda052ab52e0 /lib/Frontend/AnalysisConsumer.cpp | |
parent | 2fce988e86bc01829142e4362d4eff1af0925147 (diff) | |
download | FreeBSD-src-fd035e6496665b1f1197868e21cb0a4594e8db6e.zip FreeBSD-src-fd035e6496665b1f1197868e21cb0a4594e8db6e.tar.gz |
Update clang to r96341.
Diffstat (limited to 'lib/Frontend/AnalysisConsumer.cpp')
-rw-r--r-- | lib/Frontend/AnalysisConsumer.cpp | 161 |
1 files changed, 82 insertions, 79 deletions
diff --git a/lib/Frontend/AnalysisConsumer.cpp b/lib/Frontend/AnalysisConsumer.cpp index 45a3b15..d764fd0 100644 --- a/lib/Frontend/AnalysisConsumer.cpp +++ b/lib/Frontend/AnalysisConsumer.cpp @@ -18,14 +18,15 @@ #include "clang/AST/DeclObjC.h" #include "clang/AST/ParentMap.h" #include "clang/Analysis/Analyses/LiveVariables.h" +#include "clang/Analysis/Analyses/UninitializedValues.h" #include "clang/Analysis/CFG.h" -#include "clang/Analysis/LocalCheckers.h" -#include "clang/Analysis/ManagerRegistry.h" -#include "clang/Analysis/PathDiagnostic.h" -#include "clang/Analysis/PathSensitive/AnalysisManager.h" -#include "clang/Analysis/PathSensitive/BugReporter.h" -#include "clang/Analysis/PathSensitive/GRExprEngine.h" -#include "clang/Analysis/PathSensitive/GRTransferFuncs.h" +#include "clang/Checker/Checkers/LocalCheckers.h" +#include "clang/Checker/ManagerRegistry.h" +#include "clang/Checker/BugReporter/PathDiagnostic.h" +#include "clang/Checker/PathSensitive/AnalysisManager.h" +#include "clang/Checker/BugReporter/BugReporter.h" +#include "clang/Checker/PathSensitive/GRExprEngine.h" +#include "clang/Checker/PathSensitive/GRTransferFuncs.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/PathDiagnosticClients.h" @@ -64,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<CodeAction> Actions; + typedef std::vector<TUAction> TUActions; + Actions FunctionActions; Actions ObjCMethodActions; Actions ObjCImplementationActions; - Actions TranslationUnitActions; + TUActions TranslationUnitActions; public: ASTContext* Ctx; @@ -133,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()); @@ -162,7 +167,7 @@ public: ObjCImplementationActions.push_back(action); } - void addTranslationUnitAction(CodeAction action) { + void addTranslationUnitAction(TUAction action) { TranslationUnitActions.push_back(action); } @@ -191,7 +196,7 @@ public: namespace llvm { template <> struct FoldingSetTrait<AnalysisConsumer::CodeAction> { - static inline void Profile(AnalysisConsumer::CodeAction X, + static inline void Profile(AnalysisConsumer::CodeAction X, FoldingSetNodeID& ID) { ID.AddPointer(reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(X))); } @@ -204,42 +209,30 @@ namespace llvm { void AnalysisConsumer::HandleTopLevelSingleDecl(Decl *D) { switch (D->getKind()) { + case Decl::CXXConstructor: + case Decl::CXXDestructor: + case Decl::CXXConversion: + case Decl::CXXMethod: case Decl::Function: { FunctionDecl* FD = cast<FunctionDecl>(D); - if (!Opts.AnalyzeSpecificFunction.empty() && - Opts.AnalyzeSpecificFunction != FD->getIdentifier()->getName()) - break; + FD->getDeclName().getAsString() != Opts.AnalyzeSpecificFunction) + break; - Stmt* Body = FD->getBody(); - if (Body) HandleCode(FD, Body, FunctionActions); + if (Stmt *Body = FD->getBody()) + HandleCode(FD, Body, FunctionActions); break; } case Decl::ObjCMethod: { ObjCMethodDecl* MD = cast<ObjCMethodDecl>(D); - if (Opts.AnalyzeSpecificFunction.size() > 0 && + if (!Opts.AnalyzeSpecificFunction.empty() && Opts.AnalyzeSpecificFunction != MD->getSelector().getAsString()) return; - Stmt* Body = MD->getBody(); - if (Body) HandleCode(MD, Body, ObjCMethodActions); - break; - } - - case Decl::CXXConstructor: - case Decl::CXXDestructor: - case Decl::CXXConversion: - case Decl::CXXMethod: { - CXXMethodDecl *CXXMD = cast<CXXMethodDecl>(D); - - if (Opts.AnalyzeSpecificFunction.size() > 0 && - Opts.AnalyzeSpecificFunction != CXXMD->getName()) - return; - - Stmt *Body = CXXMD->getBody(); - if (Body) HandleCode(CXXMD, Body, FunctionActions); + if (Stmt* Body = MD->getBody()) + HandleCode(MD, Body, ObjCMethodActions); break; } @@ -249,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<FunctionDecl>(*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); - } + for (TUActions::iterator I = TranslationUnitActions.begin(), + E = TranslationUnitActions.end(); I != E; ++I) { + (*I)(*this, *Mgr, *TU); } if (!ObjCImplementationActions.empty()) { @@ -293,7 +268,7 @@ void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) { 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)) @@ -314,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<Decl*, 10> WL; WL.push_back(D); - + if (Body && Opts.AnalyzeNestedBlocks) FindBlocks(cast<DeclContext>(D), WL); - + for (Actions::iterator I = actions.begin(), E = actions.end(); I != E; ++I) for (llvm::SmallVectorImpl<Decl*>::iterator WI=WL.begin(), WE=WL.end(); WI != WE; ++WI) @@ -351,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<GRTransferFuncs> TF(tf); @@ -363,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<ExplodedNode::Auditor> Auditor; if (mgr.shouldVisualizeUbigraph()) { @@ -397,7 +372,7 @@ static void ActionGRExprEngine(AnalysisConsumer &C, AnalysisManager& mgr, Eng.getBugReporter().FlushReports(); } -static void ActionCheckerCFRefAux(AnalysisConsumer &C, AnalysisManager& mgr, +static void ActionObjCMemCheckerAux(AnalysisConsumer &C, AnalysisManager& mgr, Decl *D, bool GCEnabled) { GRTransferFuncs* TF = MakeCFRefCountTF(mgr.getASTContext(), @@ -407,23 +382,23 @@ static void ActionCheckerCFRefAux(AnalysisConsumer &C, AnalysisManager& mgr, ActionGRExprEngine(C, mgr, D, TF); } -static void ActionCheckerCFRef(AnalysisConsumer &C, AnalysisManager& mgr, +static void ActionObjCMemChecker(AnalysisConsumer &C, AnalysisManager& mgr, Decl *D) { switch (mgr.getLangOptions().getGCMode()) { default: assert (false && "Invalid GC mode."); case LangOptions::NonGC: - ActionCheckerCFRefAux(C, mgr, D, false); + ActionObjCMemCheckerAux(C, mgr, D, false); break; case LangOptions::GCOnly: - ActionCheckerCFRefAux(C, mgr, D, true); + ActionObjCMemCheckerAux(C, mgr, D, true); break; case LangOptions::HybridGC: - ActionCheckerCFRefAux(C, mgr, D, false); - ActionCheckerCFRefAux(C, mgr, D, true); + ActionObjCMemCheckerAux(C, mgr, D, false); + ActionObjCMemCheckerAux(C, mgr, D, true); break; } } @@ -457,6 +432,13 @@ static void ActionSecuritySyntacticChecks(AnalysisConsumer &C, CheckSecuritySyntaxOnly(D, BR); } +static void ActionLLVMConventionChecker(AnalysisConsumer &C, + AnalysisManager &mgr, + TranslationUnitDecl &TU) { + BugReporter BR(mgr); + CheckLLVMConventions(TU, BR); +} + static void ActionWarnObjCDealloc(AnalysisConsumer &C, AnalysisManager& mgr, Decl *D) { if (mgr.getLangOptions().getGCMode() == LangOptions::GCOnly) @@ -489,8 +471,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<FunctionDecl>(*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); @@ -500,9 +503,9 @@ static void ActionInlineCall(AnalysisConsumer &C, AnalysisManager &mgr, if (C.Opts.EnableExperimentalInternalChecks) RegisterExperimentalInternalChecks(Eng); - + RegisterAppleChecks(Eng, *D); - + if (C.Opts.EnableExperimentalChecks) RegisterExperimentalChecks(Eng); |