AnalysisManager.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
  9. using namespace clang;
  10. using namespace ento;
  11. void AnalysisManager::anchor() { }
  12. AnalysisManager::AnalysisManager(ASTContext &ASTCtx, Preprocessor &PP,
  13. const PathDiagnosticConsumers &PDC,
  14. StoreManagerCreator storemgr,
  15. ConstraintManagerCreator constraintmgr,
  16. CheckerManager *checkerMgr,
  17. AnalyzerOptions &Options,
  18. CodeInjector *injector)
  19. : AnaCtxMgr(
  20. ASTCtx, Options.UnoptimizedCFG,
  21. Options.ShouldIncludeImplicitDtorsInCFG,
  22. /*addInitializers=*/true,
  23. Options.ShouldIncludeTemporaryDtorsInCFG,
  24. Options.ShouldIncludeLifetimeInCFG,
  25. // Adding LoopExit elements to the CFG is a requirement for loop
  26. // unrolling.
  27. Options.ShouldIncludeLoopExitInCFG ||
  28. Options.ShouldUnrollLoops,
  29. Options.ShouldIncludeScopesInCFG,
  30. Options.ShouldSynthesizeBodies,
  31. Options.ShouldConditionalizeStaticInitializers,
  32. /*addCXXNewAllocator=*/true,
  33. Options.ShouldIncludeRichConstructorsInCFG,
  34. Options.ShouldElideConstructors,
  35. /*addVirtualBaseBranches=*/true,
  36. injector),
  37. Ctx(ASTCtx), PP(PP), LangOpts(ASTCtx.getLangOpts()),
  38. PathConsumers(PDC), CreateStoreMgr(storemgr),
  39. CreateConstraintMgr(constraintmgr), CheckerMgr(checkerMgr),
  40. options(Options) {
  41. AnaCtxMgr.getCFGBuildOptions().setAllAlwaysAdd();
  42. AnaCtxMgr.getCFGBuildOptions().OmitImplicitValueInitializers = true;
  43. AnaCtxMgr.getCFGBuildOptions().AddCXXDefaultInitExprInAggregates =
  44. Options.ShouldIncludeDefaultInitForAggregates;
  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. void AnalysisManager::FlushDiagnostics() {
  54. PathDiagnosticConsumer::FilesMade filesMade;
  55. for (PathDiagnosticConsumers::iterator I = PathConsumers.begin(),
  56. E = PathConsumers.end();
  57. I != E; ++I) {
  58. (*I)->FlushDiagnostics(&filesMade);
  59. }
  60. }