1 //===-- AnalysisManager.cpp -------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
10 
11 using namespace clang;
12 using namespace ento;
13 
14 void AnalysisManager::anchor() { }
15 
16 AnalysisManager::AnalysisManager(ASTContext &ASTCtx, DiagnosticsEngine &diags,
17                                  const PathDiagnosticConsumers &PDC,
18                                  StoreManagerCreator storemgr,
19                                  ConstraintManagerCreator constraintmgr,
20                                  CheckerManager *checkerMgr,
21                                  AnalyzerOptions &Options,
22                                  CodeInjector *injector)
23     : AnaCtxMgr(
24           ASTCtx, Options.UnoptimizedCFG,
25           Options.ShouldIncludeImplicitDtorsInCFG,
26           /*AddInitializers=*/true,
27           Options.ShouldIncludeTemporaryDtorsInCFG,
28           Options.ShouldIncludeLifetimeInCFG,
29           // Adding LoopExit elements to the CFG is a requirement for loop
30           // unrolling.
31           Options.ShouldIncludeLoopExitInCFG ||
32             Options.ShouldUnrollLoops,
33           Options.ShouldIncludeScopesInCFG,
34           Options.ShouldSynthesizeBodies,
35           Options.ShouldConditionalizeStaticInitializers,
36           /*addCXXNewAllocator=*/true,
37           Options.ShouldIncludeRichConstructorsInCFG,
38           Options.ShouldElideConstructors, injector),
39       Ctx(ASTCtx), Diags(diags), LangOpts(ASTCtx.getLangOpts()),
40       PathConsumers(PDC), CreateStoreMgr(storemgr),
41       CreateConstraintMgr(constraintmgr), CheckerMgr(checkerMgr),
42       options(Options) {
43   AnaCtxMgr.getCFGBuildOptions().setAllAlwaysAdd();
44 }
45 
46 AnalysisManager::~AnalysisManager() {
47   FlushDiagnostics();
48   for (PathDiagnosticConsumers::iterator I = PathConsumers.begin(),
49        E = PathConsumers.end(); I != E; ++I) {
50     delete *I;
51   }
52 }
53 
54 void AnalysisManager::FlushDiagnostics() {
55   PathDiagnosticConsumer::FilesMade filesMade;
56   for (PathDiagnosticConsumers::iterator I = PathConsumers.begin(),
57        E = PathConsumers.end();
58        I != E; ++I) {
59     (*I)->FlushDiagnostics(&filesMade);
60   }
61 }
62