Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/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/Analysis/PathDiagnostic.h"
19
#include "clang/Lex/Preprocessor.h"
20
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
21
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.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
  Preprocessor &PP;
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, Preprocessor &PP,
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
30.2k
  void ClearContexts() {
59
30.2k
    AnaCtxMgr.clear();
60
30.2k
  }
61
62
91.8k
  AnalysisDeclContextManager& getAnalysisDeclContextManager() {
63
91.8k
    return AnaCtxMgr;
64
91.8k
  }
65
66
19
  Preprocessor &getPreprocessor() override { return PP; }
67
68
12.6k
  StoreManagerCreator getStoreManagerCreator() {
69
12.6k
    return CreateStoreMgr;
70
12.6k
  }
71
72
126k
  AnalyzerOptions& getAnalyzerOptions() override {
73
126k
    return options;
74
126k
  }
75
76
12.6k
  ConstraintManagerCreator getConstraintManagerCreator() {
77
12.6k
    return CreateConstraintMgr;
78
12.6k
  }
79
80
4.76M
  CheckerManager *getCheckerManager() const { return CheckerMgr; }
81
82
3.36M
  ASTContext &getASTContext() override {
83
3.36M
    return Ctx;
84
3.36M
  }
85
86
300k
  SourceManager &getSourceManager() override {
87
300k
    return getASTContext().getSourceManager();
88
300k
  }
89
90
1.75k
  const LangOptions &getLangOpts() const {
91
1.75k
    return LangOpts;
92
1.75k
  }
93
94
13.2k
  ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() override {
95
13.2k
    return PathConsumers;
96
13.2k
  }
97
98
  void FlushDiagnostics();
99
100
0
  bool shouldVisualize() const {
101
0
    return options.visualizeExplodedGraphWithGraphViz;
102
0
  }
103
104
196k
  bool shouldInlineCall() const {
105
196k
    return options.getIPAMode() != IPAK_None;
106
196k
  }
107
108
44.1k
  CFG *getCFG(Decl const *D) {
109
44.1k
    return AnaCtxMgr.getContext(D)->getCFG();
110
44.1k
  }
111
112
  template <typename T>
113
488
  T *getAnalysis(Decl const *D) {
114
488
    return AnaCtxMgr.getContext(D)->getAnalysis<T>();
115
488
  }
clang::LiveVariables* clang::ento::AnalysisManager::getAnalysis<clang::LiveVariables>(clang::Decl const*)
Line
Count
Source
113
483
  T *getAnalysis(Decl const *D) {
114
483
    return AnaCtxMgr.getContext(D)->getAnalysis<T>();
115
483
  }
clang::RelaxedLiveVariables* clang::ento::AnalysisManager::getAnalysis<clang::RelaxedLiveVariables>(clang::Decl const*)
Line
Count
Source
113
5
  T *getAnalysis(Decl const *D) {
114
5
    return AnaCtxMgr.getContext(D)->getAnalysis<T>();
115
5
  }
116
117
483
  ParentMap &getParentMap(Decl const *D) {
118
483
    return AnaCtxMgr.getContext(D)->getParentMap();
119
483
  }
120
121
264k
  AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
122
264k
    return AnaCtxMgr.getContext(D);
123
264k
  }
124
125
268k
  static bool isInCodeFile(SourceLocation SL, const SourceManager &SM) {
126
268k
    if (SM.isInMainFile(SL))
127
106k
      return true;
128
161k
129
161k
    // Support the "unified sources" compilation method (eg. WebKit) that
130
161k
    // involves producing non-header files that include other non-header files.
131
161k
    // We should be included directly from a UnifiedSource* file
132
161k
    // and we shouldn't be a header - which is a very safe defensive check.
133
161k
    SourceLocation IL = SM.getIncludeLoc(SM.getFileID(SL));
134
161k
    if (!IL.isValid() || 
!SM.isInMainFile(IL)160k
)
135
9.22k
      return false;
136
151k
    // Should rather be "file name starts with", but the current .getFilename
137
151k
    // includes the full path.
138
151k
    if (SM.getFilename(IL).contains("UnifiedSource")) {
139
24
      // It might be great to reuse FrontendOptions::getInputKindForExtension()
140
24
      // but for now it doesn't discriminate between code and header files.
141
24
      return llvm::StringSwitch<bool>(SM.getFilename(SL).rsplit('.').second)
142
24
          .Cases("c", "m", "mm", "C", "cc", "cp", true)
143
24
          .Cases("cpp", "CPP", "c++", "cxx", "cppm", true)
144
24
          .Default(false);
145
24
    }
146
151k
147
151k
    return false;
148
151k
  }
149
150
268k
  bool isInCodeFile(SourceLocation SL) {
151
268k
    const SourceManager &SM = getASTContext().getSourceManager();
152
268k
    return isInCodeFile(SL, SM);
153
268k
  }
154
};
155
156
} // enAnaCtxMgrspace
157
158
} // end clang namespace
159
160
#endif