Coverage Report

Created: 2019-03-22 08:08

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