Coverage Report

Created: 2019-07-24 05:18

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