Coverage Report

Created: 2018-12-11 17:59

/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.8k
  void ClearContexts() {
59
24.8k
    AnaCtxMgr.clear();
60
24.8k
  }
61
62
44.3k
  AnalysisDeclContextManager& getAnalysisDeclContextManager() {
63
44.3k
    return AnaCtxMgr;
64
44.3k
  }
65
66
10.0k
  StoreManagerCreator getStoreManagerCreator() {
67
10.0k
    return CreateStoreMgr;
68
10.0k
  }
69
70
75.9k
  AnalyzerOptions& getAnalyzerOptions() override {
71
75.9k
    return options;
72
75.9k
  }
73
74
10.0k
  ConstraintManagerCreator getConstraintManagerCreator() {
75
10.0k
    return CreateConstraintMgr;
76
10.0k
  }
77
78
3.06M
  CheckerManager *getCheckerManager() const { return CheckerMgr; }
79
80
2.34M
  ASTContext &getASTContext() override {
81
2.34M
    return Ctx;
82
2.34M
  }
83
84
210k
  SourceManager &getSourceManager() override {
85
210k
    return getASTContext().getSourceManager();
86
210k
  }
87
88
0
  DiagnosticsEngine &getDiagnostic() override {
89
0
    return Diags;
90
0
  }
91
92
1.31k
  const LangOptions &getLangOpts() const {
93
1.31k
    return LangOpts;
94
1.31k
  }
95
96
10.3k
  ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() override {
97
10.3k
    return PathConsumers;
98
10.3k
  }
99
100
  void FlushDiagnostics();
101
102
0
  bool shouldVisualize() const {
103
0
    return options.visualizeExplodedGraphWithGraphViz;
104
0
  }
105
106
82.0k
  bool shouldInlineCall() const {
107
82.0k
    return options.getIPAMode() != IPAK_None;
108
82.0k
  }
109
110
36.0k
  CFG *getCFG(Decl const *D) {
111
36.0k
    return AnaCtxMgr.getContext(D)->getCFG();
112
36.0k
  }
113
114
  template <typename T>
115
440
  T *getAnalysis(Decl const *D) {
116
440
    return AnaCtxMgr.getContext(D)->getAnalysis<T>();
117
440
  }
118
119
440
  ParentMap &getParentMap(Decl const *D) {
120
440
    return AnaCtxMgr.getContext(D)->getParentMap();
121
440
  }
122
123
107k
  AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
124
107k
    return AnaCtxMgr.getContext(D);
125
107k
  }
126
127
173k
  static bool isInCodeFile(SourceLocation SL, const SourceManager &SM) {
128
173k
    if (SM.isInMainFile(SL))
129
87.5k
      return true;
130
86.3k
131
86.3k
    // Support the "unified sources" compilation method (eg. WebKit) that
132
86.3k
    // involves producing non-header files that include other non-header files.
133
86.3k
    // We should be included directly from a UnifiedSource* file
134
86.3k
    // and we shouldn't be a header - which is a very safe defensive check.
135
86.3k
    SourceLocation IL = SM.getIncludeLoc(SM.getFileID(SL));
136
86.3k
    if (!IL.isValid() || 
!SM.isInMainFile(IL)86.1k
)
137
3.79k
      return false;
138
82.5k
    // Should rather be "file name starts with", but the current .getFilename
139
82.5k
    // includes the full path.
140
82.5k
    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
82.5k
149
82.5k
    return false;
150
82.5k
  }
151
152
173k
  bool isInCodeFile(SourceLocation SL) {
153
173k
    const SourceManager &SM = getASTContext().getSourceManager();
154
173k
    return isInCodeFile(SL, SM);
155
173k
  }
156
};
157
158
} // enAnaCtxMgrspace
159
160
} // end clang namespace
161
162
#endif