Coverage Report

Created: 2018-09-25 23:22

/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 PathDiagnosticConsumers &Consumers,
51
                  StoreManagerCreator storemgr,
52
                  ConstraintManagerCreator constraintmgr,
53
                  CheckerManager *checkerMgr, AnalyzerOptions &Options,
54
                  CodeInjector *injector = nullptr);
55
56
  ~AnalysisManager() override;
57
58
24.1k
  void ClearContexts() {
59
24.1k
    AnaCtxMgr.clear();
60
24.1k
  }
61
62
40.2k
  AnalysisDeclContextManager& getAnalysisDeclContextManager() {
63
40.2k
    return AnaCtxMgr;
64
40.2k
  }
65
66
9.75k
  StoreManagerCreator getStoreManagerCreator() {
67
9.75k
    return CreateStoreMgr;
68
9.75k
  }
69
70
73.8k
  AnalyzerOptions& getAnalyzerOptions() override {
71
73.8k
    return options;
72
73.8k
  }
73
74
9.75k
  ConstraintManagerCreator getConstraintManagerCreator() {
75
9.75k
    return CreateConstraintMgr;
76
9.75k
  }
77
78
2.74M
  CheckerManager *getCheckerManager() const { return CheckerMgr; }
79
80
2.22M
  ASTContext &getASTContext() override {
81
2.22M
    return Ctx;
82
2.22M
  }
83
84
156k
  SourceManager &getSourceManager() override {
85
156k
    return getASTContext().getSourceManager();
86
156k
  }
87
88
0
  DiagnosticsEngine &getDiagnostic() override {
89
0
    return Diags;
90
0
  }
91
92
11.0k
  const LangOptions &getLangOpts() const {
93
11.0k
    return LangOpts;
94
11.0k
  }
95
96
10.0k
  ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() override {
97
10.0k
    return PathConsumers;
98
10.0k
  }
99
100
  void FlushDiagnostics();
101
102
0
  bool shouldVisualize() const {
103
0
    return options.visualizeExplodedGraphWithGraphViz;
104
0
  }
105
106
77.9k
  bool shouldInlineCall() const {
107
77.9k
    return options.getIPAMode() != IPAK_None;
108
77.9k
  }
109
110
34.9k
  CFG *getCFG(Decl const *D) {
111
34.9k
    return AnaCtxMgr.getContext(D)->getCFG();
112
34.9k
  }
113
114
  template <typename T>
115
439
  T *getAnalysis(Decl const *D) {
116
439
    return AnaCtxMgr.getContext(D)->getAnalysis<T>();
117
439
  }
118
119
439
  ParentMap &getParentMap(Decl const *D) {
120
439
    return AnaCtxMgr.getContext(D)->getParentMap();
121
439
  }
122
123
94.5k
  AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
124
94.5k
    return AnaCtxMgr.getContext(D);
125
94.5k
  }
126
127
156k
  static bool isInCodeFile(SourceLocation SL, const SourceManager &SM) {
128
156k
    if (SM.isInMainFile(SL))
129
84.5k
      return true;
130
71.6k
131
71.6k
    // Support the "unified sources" compilation method (eg. WebKit) that
132
71.6k
    // involves producing non-header files that include other non-header files.
133
71.6k
    // We should be included directly from a UnifiedSource* file
134
71.6k
    // and we shouldn't be a header - which is a very safe defensive check.
135
71.6k
    SourceLocation IL = SM.getIncludeLoc(SM.getFileID(SL));
136
71.6k
    if (!IL.isValid() || 
!SM.isInMainFile(IL)71.4k
)
137
3.59k
      return false;
138
68.0k
    // Should rather be "file name starts with", but the current .getFilename
139
68.0k
    // includes the full path.
140
68.0k
    if (SM.getFilename(IL).contains("UnifiedSource")) {
141
24
      // It might be great to reuse FrontendOptions::getInputKindForExtension()
142
24
      // but for now it doesn't discriminate between code and header files.
143
24
      return llvm::StringSwitch<bool>(SM.getFilename(SL).rsplit('.').second)
144
24
          .Cases("c", "m", "mm", "C", "cc", "cp", true)
145
24
          .Cases("cpp", "CPP", "c++", "cxx", "cppm", true)
146
24
          .Default(false);
147
24
    }
148
68.0k
149
68.0k
    return false;
150
68.0k
  }
151
152
156k
  bool isInCodeFile(SourceLocation SL) {
153
156k
    const SourceManager &SM = getASTContext().getSourceManager();
154
156k
    return isInCodeFile(SL, SM);
155
156k
  }
156
};
157
158
} // enAnaCtxMgrspace
159
160
} // end clang namespace
161
162
#endif