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