From 34090db51632aa24c46eeba5713539d8cc6f039d Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Fri, 2 Feb 2018 02:01:55 +0000 Subject: [analyzer] Expose exploration strategy through analyzer options. Differential Revision: https://reviews.llvm.org/D42774 llvm-svn: 324049 --- clang/lib/StaticAnalyzer/Core/CoreEngine.cpp | 33 ++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'clang/lib/StaticAnalyzer/Core/CoreEngine.cpp') diff --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp index 2fdd310fa31..a06c311590a 100644 --- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -82,8 +82,13 @@ public: // functions, and we the code for the dstor generated in one compilation unit. WorkList::~WorkList() {} -WorkList *WorkList::makeDFS() { return new DFS(); } -WorkList *WorkList::makeBFS() { return new BFS(); } +std::unique_ptr WorkList::makeDFS() { + return llvm::make_unique(); +} + +std::unique_ptr WorkList::makeBFS() { + return llvm::make_unique(); +} namespace { class BFSBlockDFSContents : public WorkList { @@ -119,14 +124,34 @@ namespace { }; } // end anonymous namespace -WorkList* WorkList::makeBFSBlockDFSContents() { - return new BFSBlockDFSContents(); +std::unique_ptr WorkList::makeBFSBlockDFSContents() { + return llvm::make_unique(); } //===----------------------------------------------------------------------===// // Core analysis engine. //===----------------------------------------------------------------------===// +static std::unique_ptr generateWorkList(AnalyzerOptions &Opts) { + switch (Opts.getExplorationStrategy()) { + case AnalyzerOptions::ExplorationStrategyKind::DFS: + return WorkList::makeDFS(); + case AnalyzerOptions::ExplorationStrategyKind::BFS: + return WorkList::makeBFS(); + case AnalyzerOptions::ExplorationStrategyKind::BFSBlockDFSContents: + return WorkList::makeBFSBlockDFSContents(); + default: + llvm_unreachable("Unexpected case"); + } +} + +CoreEngine::CoreEngine(SubEngine &subengine, + FunctionSummariesTy *FS, + AnalyzerOptions &Opts) : SubEng(subengine), + WList(generateWorkList(Opts)), + BCounterFactory(G.getAllocator()), + FunctionSummaries(FS) {} + /// ExecuteWorkList - Run the worklist algorithm for a maximum number of steps. bool CoreEngine::ExecuteWorkList(const LocationContext *L, unsigned Steps, ProgramStateRef InitState) { -- cgit v1.2.3