Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:07

0001 //== AnalysisManager.h - Path sensitive analysis data manager ------*- C++ -*-//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the AnalysisManager class that manages the data and policy
0010 // for path sensitive analysis.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
0015 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
0016 
0017 #include "clang/Analysis/AnalysisDeclContext.h"
0018 #include "clang/Analysis/PathDiagnostic.h"
0019 #include "clang/Lex/Preprocessor.h"
0020 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
0021 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
0022 #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
0023 
0024 namespace clang {
0025 
0026 class CodeInjector;
0027 
0028 namespace ento {
0029   class CheckerManager;
0030 
0031 class AnalysisManager : public BugReporterData {
0032   virtual void anchor();
0033   AnalysisDeclContextManager AnaCtxMgr;
0034 
0035   ASTContext &Ctx;
0036   Preprocessor &PP;
0037   const LangOptions &LangOpts;
0038   PathDiagnosticConsumers PathConsumers;
0039 
0040   // Configurable components creators.
0041   StoreManagerCreator CreateStoreMgr;
0042   ConstraintManagerCreator CreateConstraintMgr;
0043 
0044   CheckerManager *CheckerMgr;
0045 
0046 public:
0047   AnalyzerOptions &options;
0048 
0049   AnalysisManager(ASTContext &ctx, Preprocessor &PP,
0050                   const PathDiagnosticConsumers &Consumers,
0051                   StoreManagerCreator storemgr,
0052                   ConstraintManagerCreator constraintmgr,
0053                   CheckerManager *checkerMgr, AnalyzerOptions &Options,
0054                   CodeInjector *injector = nullptr);
0055 
0056   ~AnalysisManager() override;
0057 
0058   void ClearContexts() {
0059     AnaCtxMgr.clear();
0060   }
0061 
0062   AnalysisDeclContextManager& getAnalysisDeclContextManager() {
0063     return AnaCtxMgr;
0064   }
0065 
0066   Preprocessor &getPreprocessor() override { return PP; }
0067 
0068   StoreManagerCreator getStoreManagerCreator() {
0069     return CreateStoreMgr;
0070   }
0071 
0072   AnalyzerOptions& getAnalyzerOptions() override {
0073     return options;
0074   }
0075 
0076   ConstraintManagerCreator getConstraintManagerCreator() {
0077     return CreateConstraintMgr;
0078   }
0079 
0080   CheckerManager *getCheckerManager() const { return CheckerMgr; }
0081 
0082   ASTContext &getASTContext() override {
0083     return Ctx;
0084   }
0085 
0086   SourceManager &getSourceManager() override {
0087     return getASTContext().getSourceManager();
0088   }
0089 
0090   const LangOptions &getLangOpts() const {
0091     return LangOpts;
0092   }
0093 
0094   ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() override {
0095     return PathConsumers;
0096   }
0097 
0098   void FlushDiagnostics();
0099 
0100   bool shouldVisualize() const {
0101     return options.visualizeExplodedGraphWithGraphViz;
0102   }
0103 
0104   bool shouldInlineCall() const {
0105     return options.getIPAMode() != IPAK_None;
0106   }
0107 
0108   CFG *getCFG(Decl const *D) {
0109     return AnaCtxMgr.getContext(D)->getCFG();
0110   }
0111 
0112   template <typename T>
0113   T *getAnalysis(Decl const *D) {
0114     return AnaCtxMgr.getContext(D)->getAnalysis<T>();
0115   }
0116 
0117   ParentMap &getParentMap(Decl const *D) {
0118     return AnaCtxMgr.getContext(D)->getParentMap();
0119   }
0120 
0121   AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
0122     return AnaCtxMgr.getContext(D);
0123   }
0124 
0125   static bool isInCodeFile(SourceLocation SL, const SourceManager &SM) {
0126     if (SM.isInMainFile(SL))
0127       return true;
0128 
0129     // Support the "unified sources" compilation method (eg. WebKit) that
0130     // involves producing non-header files that include other non-header files.
0131     // We should be included directly from a UnifiedSource* file
0132     // and we shouldn't be a header - which is a very safe defensive check.
0133     SourceLocation IL = SM.getIncludeLoc(SM.getFileID(SL));
0134     if (!IL.isValid() || !SM.isInMainFile(IL))
0135       return false;
0136     // Should rather be "file name starts with", but the current .getFilename
0137     // includes the full path.
0138     if (SM.getFilename(IL).contains("UnifiedSource")) {
0139       // It might be great to reuse FrontendOptions::getInputKindForExtension()
0140       // but for now it doesn't discriminate between code and header files.
0141       return llvm::StringSwitch<bool>(SM.getFilename(SL).rsplit('.').second)
0142           .Cases("c", "m", "mm", "C", "cc", "cp", true)
0143           .Cases("cpp", "CPP", "c++", "cxx", "cppm", true)
0144           .Default(false);
0145     }
0146 
0147     return false;
0148   }
0149 
0150   bool isInCodeFile(SourceLocation SL) {
0151     const SourceManager &SM = getASTContext().getSourceManager();
0152     return isInCodeFile(SL, SM);
0153   }
0154 };
0155 
0156 } // enAnaCtxMgrspace
0157 
0158 } // end clang namespace
0159 
0160 #endif