Coverage Report

Created: 2018-07-21 08:31

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
Line
Count
Source (jump to first uncovered line)
1
//== AnalysisManager.h - Path sensitive analysis data manager ------*- C++ -*-//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file defines the AnalysisManager class that manages the data and policy
11
// for path sensitive analysis.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
16
#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
17
18
#include "clang/Analysis/AnalysisDeclContext.h"
19
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
20
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
21
#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
22
#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
23
24
namespace clang {
25
26
class CodeInjector;
27
28
namespace ento {
29
  class CheckerManager;
30
31
class AnalysisManager : public BugReporterData {
32
  virtual void anchor();
33
  AnalysisDeclContextManager AnaCtxMgr;
34
35
  ASTContext &Ctx;
36
  DiagnosticsEngine &Diags;
37
  const LangOptions &LangOpts;
38
  PathDiagnosticConsumers PathConsumers;
39
40
  // Configurable components creators.
41
  StoreManagerCreator CreateStoreMgr;
42
  ConstraintManagerCreator CreateConstraintMgr;
43
44
  CheckerManager *CheckerMgr;
45
46
public:
47
  AnalyzerOptions &options;
48
  
49
  AnalysisManager(ASTContext &ctx,DiagnosticsEngine &diags,
50
                  const LangOptions &lang,
51
                  const PathDiagnosticConsumers &Consumers,
52
                  StoreManagerCreator storemgr,
53
                  ConstraintManagerCreator constraintmgr, 
54
                  CheckerManager *checkerMgr,
55
                  AnalyzerOptions &Options,
56
                  CodeInjector* injector = nullptr);
57
58
  ~AnalysisManager() override;
59
60
23.1k
  void ClearContexts() {
61
23.1k
    AnaCtxMgr.clear();
62
23.1k
  }
63
  
64
37.9k
  AnalysisDeclContextManager& getAnalysisDeclContextManager() {
65
37.9k
    return AnaCtxMgr;
66
37.9k
  }
67
68
9.37k
  StoreManagerCreator getStoreManagerCreator() {
69
9.37k
    return CreateStoreMgr;
70
9.37k
  }
71
72
115k
  AnalyzerOptions& getAnalyzerOptions() override {
73
115k
    return options;
74
115k
  }
75
76
9.37k
  ConstraintManagerCreator getConstraintManagerCreator() {
77
9.37k
    return CreateConstraintMgr;
78
9.37k
  }
79
80
2.66M
  CheckerManager *getCheckerManager() const { return CheckerMgr; }
81
82
2.14M
  ASTContext &getASTContext() override {
83
2.14M
    return Ctx;
84
2.14M
  }
85
86
149k
  SourceManager &getSourceManager() override {
87
149k
    return getASTContext().getSourceManager();
88
149k
  }
89
90
0
  DiagnosticsEngine &getDiagnostic() override {
91
0
    return Diags;
92
0
  }
93
94
10.6k
  const LangOptions &getLangOpts() const {
95
10.6k
    return LangOpts;
96
10.6k
  }
97
98
9.77k
  ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() override {
99
9.77k
    return PathConsumers;
100
9.77k
  }
101
102
  void FlushDiagnostics();
103
104
0
  bool shouldVisualize() const {
105
0
    return options.visualizeExplodedGraphWithGraphViz ||
106
0
           options.visualizeExplodedGraphWithUbiGraph;
107
0
  }
108
109
74.3k
  bool shouldInlineCall() const {
110
74.3k
    return options.getIPAMode() != IPAK_None;
111
74.3k
  }
112
113
33.5k
  CFG *getCFG(Decl const *D) {
114
33.5k
    return AnaCtxMgr.getContext(D)->getCFG();
115
33.5k
  }
116
117
  template <typename T>
118
435
  T *getAnalysis(Decl const *D) {
119
435
    return AnaCtxMgr.getContext(D)->getAnalysis<T>();
120
435
  }
121
122
435
  ParentMap &getParentMap(Decl const *D) {
123
435
    return AnaCtxMgr.getContext(D)->getParentMap();
124
435
  }
125
126
90.3k
  AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
127
90.3k
    return AnaCtxMgr.getContext(D);
128
90.3k
  }
129
130
133k
  static bool isInCodeFile(SourceLocation SL, const SourceManager &SM) {
131
133k
    if (SM.isInMainFile(SL))
132
81.4k
      return true;
133
51.8k
134
51.8k
    // Support the "unified sources" compilation method (eg. WebKit) that
135
51.8k
    // involves producing non-header files that include other non-header files.
136
51.8k
    // We should be included directly from a UnifiedSource* file
137
51.8k
    // and we shouldn't be a header - which is a very safe defensive check.
138
51.8k
    SourceLocation IL = SM.getIncludeLoc(SM.getFileID(SL));
139
51.8k
    if (!IL.isValid() || 
!SM.isInMainFile(IL)51.6k
)
140
2.73k
      return false;
141
49.1k
    // Should rather be "file name starts with", but the current .getFilename
142
49.1k
    // includes the full path.
143
49.1k
    if (SM.getFilename(IL).contains("UnifiedSource")) {
144
24
      // It might be great to reuse FrontendOptions::getInputKindForExtension()
145
24
      // but for now it doesn't discriminate between code and header files.
146
24
      return llvm::StringSwitch<bool>(SM.getFilename(SL).rsplit('.').second)
147
24
          .Cases("c", "m", "mm", "C", "cc", "cp", true)
148
24
          .Cases("cpp", "CPP", "c++", "cxx", "cppm", true)
149
24
          .Default(false);
150
24
    }
151
49.1k
152
49.1k
    return false;
153
49.1k
  }
154
155
133k
  bool isInCodeFile(SourceLocation SL) {
156
133k
    const SourceManager &SM = getASTContext().getSourceManager();
157
133k
    return isInCodeFile(SL, SM);
158
133k
  }
159
};
160
161
} // enAnaCtxMgrspace
162
163
} // end clang namespace
164
165
#endif