| 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 | #include "clang/Basic/DiagnosticDriver.h" |
| 11 | |
| 12 | using namespace clang; |
| 13 | using namespace ento; |
| 14 | |
| 15 | void AnalysisManager::anchor() { } |
| 16 | |
| 17 | AnalysisManager::AnalysisManager(ASTContext &ASTCtx, Preprocessor &PP, |
| 18 | PathDiagnosticConsumers PDC, |
| 19 | StoreManagerCreator storemgr, |
| 20 | ConstraintManagerCreator constraintmgr, |
| 21 | CheckerManager *checkerMgr, |
| 22 | AnalyzerOptions &Options, |
| 23 | std::unique_ptr<CodeInjector> injector) |
| 24 | : AnaCtxMgr( |
| 25 | ASTCtx, Options.UnoptimizedCFG, |
| 26 | Options.ShouldIncludeImplicitDtorsInCFG, |
| 27 | /*addInitializers=*/true, Options.ShouldIncludeTemporaryDtorsInCFG, |
| 28 | Options.ShouldIncludeLifetimeInCFG, |
| 29 | // Adding LoopExit elements to the CFG is a requirement for loop |
| 30 | // unrolling. |
| 31 | Options.ShouldIncludeLoopExitInCFG || Options.ShouldUnrollLoops, |
| 32 | Options.ShouldIncludeScopesInCFG, Options.ShouldSynthesizeBodies, |
| 33 | Options.ShouldConditionalizeStaticInitializers, |
| 34 | /*addCXXNewAllocator=*/true, |
| 35 | Options.ShouldIncludeRichConstructorsInCFG, |
| 36 | Options.ShouldElideConstructors, |
| 37 | /*addVirtualBaseBranches=*/true, std::move(injector)), |
| 38 | Ctx(ASTCtx), PP(PP), LangOpts(ASTCtx.getLangOpts()), |
| 39 | PathConsumers(std::move(PDC)), CreateStoreMgr(storemgr), |
| 40 | CreateConstraintMgr(constraintmgr), CheckerMgr(checkerMgr), |
| 41 | options(Options) { |
| 42 | SmallVector<StringRef> Extensions; |
| 43 | if (!Options.UnityBuildFileExtensions.empty()) |
| 44 | Options.UnityBuildFileExtensions.split(A&: Extensions, Separator: ';'); |
| 45 | for (StringRef Extension : Extensions) { |
| 46 | Extension = Extension.trim(); |
| 47 | if (Extension.empty()) { |
| 48 | ASTCtx.getDiagnostics().Report(DiagID: diag::err_analyzer_config_invalid_input) |
| 49 | << "unitybuild-file-extensions" << "a non-empty file extension" ; |
| 50 | continue; |
| 51 | } |
| 52 | UnityBuildFileExtensions.push_back(Elt: Extension); |
| 53 | } |
| 54 | |
| 55 | AnaCtxMgr.getCFGBuildOptions().setAllAlwaysAdd(); |
| 56 | AnaCtxMgr.getCFGBuildOptions().OmitImplicitValueInitializers = true; |
| 57 | AnaCtxMgr.getCFGBuildOptions().AddCXXDefaultInitExprInAggregates = |
| 58 | Options.ShouldIncludeDefaultInitForAggregates; |
| 59 | } |
| 60 | |
| 61 | AnalysisManager::~AnalysisManager() { |
| 62 | FlushDiagnostics(); |
| 63 | } |
| 64 | |
| 65 | void AnalysisManager::FlushDiagnostics() { |
| 66 | PathDiagnosticConsumer::FilesMade filesMade; |
| 67 | for (const auto &Consumer : PathConsumers) { |
| 68 | Consumer->FlushDiagnostics(FilesMade: &filesMade); |
| 69 | } |
| 70 | } |
| 71 | |