Coverage Report

Created: 2018-09-25 23:22

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h
Line
Count
Source
1
//===- Environment.h - Map from Stmt* to Locations/Values -------*- 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 defined the Environment and EnvironmentManager classes.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ENVIRONMENT_H
15
#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ENVIRONMENT_H
16
17
#include "clang/Analysis/AnalysisDeclContext.h"
18
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
19
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
20
#include "llvm/ADT/ImmutableMap.h"
21
#include <utility>
22
23
namespace clang {
24
25
class Stmt;
26
27
namespace ento {
28
29
class SValBuilder;
30
class SymbolReaper;
31
32
/// An entry in the environment consists of a Stmt and an LocationContext.
33
/// This allows the environment to manage context-sensitive bindings,
34
/// which is essentially for modeling recursive function analysis, among
35
/// other things.
36
class EnvironmentEntry : public std::pair<const Stmt *,
37
                                          const StackFrameContext *> {
38
public:
39
  EnvironmentEntry(const Stmt *s, const LocationContext *L);
40
41
6.24M
  const Stmt *getStmt() const { return first; }
42
6.24M
  const LocationContext *getLocationContext() const { return second; }
43
44
  /// Profile an EnvironmentEntry for inclusion in a FoldingSet.
45
  static void Profile(llvm::FoldingSetNodeID &ID,
46
3.43M
                      const EnvironmentEntry &E) {
47
3.43M
    ID.AddPointer(E.getStmt());
48
3.43M
    ID.AddPointer(E.getLocationContext());
49
3.43M
  }
50
51
3.43M
  void Profile(llvm::FoldingSetNodeID &ID) const {
52
3.43M
    Profile(ID, *this);
53
3.43M
  }
54
};
55
56
/// An immutable map from EnvironemntEntries to SVals.
57
class Environment {
58
private:
59
  friend class EnvironmentManager;
60
61
  using BindingsTy = llvm::ImmutableMap<EnvironmentEntry, SVal>;
62
63
  BindingsTy ExprBindings;
64
65
945k
  Environment(BindingsTy eb) : ExprBindings(eb) {}
66
67
  SVal lookupExpr(const EnvironmentEntry &E) const;
68
69
public:
70
  using iterator = BindingsTy::iterator;
71
72
261k
  iterator begin() const { return ExprBindings.begin(); }
73
261k
  iterator end() const { return ExprBindings.end(); }
74
75
  /// Fetches the current binding of the expression in the
76
  /// Environment.
77
  SVal getSVal(const EnvironmentEntry &E, SValBuilder &svalBuilder) const;
78
79
  /// Profile - Profile the contents of an Environment object for use
80
  ///  in a FoldingSet.
81
3.67M
  static void Profile(llvm::FoldingSetNodeID& ID, const Environment* env) {
82
3.67M
    env->ExprBindings.Profile(ID);
83
3.67M
  }
84
85
  /// Profile - Used to profile the contents of this object for inclusion
86
  ///  in a FoldingSet.
87
3.67M
  void Profile(llvm::FoldingSetNodeID& ID) const {
88
3.67M
    Profile(ID, this);
89
3.67M
  }
90
91
675k
  bool operator==(const Environment& RHS) const {
92
675k
    return ExprBindings == RHS.ExprBindings;
93
675k
  }
94
95
  void print(raw_ostream &Out, const char *NL, const char *Sep,
96
             const ASTContext &Context,
97
             const LocationContext *WithLC = nullptr) const;
98
};
99
100
class EnvironmentManager {
101
private:
102
  using FactoryTy = Environment::BindingsTy::Factory;
103
104
  FactoryTy F;
105
106
public:
107
9.75k
  EnvironmentManager(llvm::BumpPtrAllocator &Allocator) : F(Allocator) {}
108
109
269k
  Environment getInitialEnvironment() {
110
269k
    return Environment(F.getEmptyMap());
111
269k
  }
112
113
  /// Bind a symbolic value to the given environment entry.
114
  Environment bindExpr(Environment Env, const EnvironmentEntry &E, SVal V,
115
                       bool Invalidate);
116
117
  Environment removeDeadBindings(Environment Env,
118
                                 SymbolReaper &SymReaper,
119
                                 ProgramStateRef state);
120
};
121
122
} // namespace ento
123
124
} // namespace clang
125
126
#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ENVIRONMENT_H