clang  8.0.0svn
Environment.h
Go to the documentation of this file.
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 
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  const Stmt *getStmt() const { return first; }
42  const LocationContext *getLocationContext() const { return second; }
43 
44  /// Profile an EnvironmentEntry for inclusion in a FoldingSet.
45  static void Profile(llvm::FoldingSetNodeID &ID,
46  const EnvironmentEntry &E) {
47  ID.AddPointer(E.getStmt());
48  ID.AddPointer(E.getLocationContext());
49  }
50 
51  void Profile(llvm::FoldingSetNodeID &ID) const {
52  Profile(ID, *this);
53  }
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  Environment(BindingsTy eb) : ExprBindings(eb) {}
66 
67  SVal lookupExpr(const EnvironmentEntry &E) const;
68 
69 public:
70  using iterator = BindingsTy::iterator;
71 
72  iterator begin() const { return ExprBindings.begin(); }
73  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  static void Profile(llvm::FoldingSetNodeID& ID, const Environment* env) {
82  env->ExprBindings.Profile(ID);
83  }
84 
85  /// Profile - Used to profile the contents of this object for inclusion
86  /// in a FoldingSet.
87  void Profile(llvm::FoldingSetNodeID& ID) const {
88  Profile(ID, this);
89  }
90 
91  bool operator==(const Environment& RHS) const {
92  return ExprBindings == RHS.ExprBindings;
93  }
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 
101 private:
102  using FactoryTy = Environment::BindingsTy::Factory;
103 
104  FactoryTy F;
105 
106 public:
107  EnvironmentManager(llvm::BumpPtrAllocator &Allocator) : F(Allocator) {}
108 
110  return Environment(F.getEmptyMap());
111  }
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,
120 };
121 
122 } // namespace ento
123 
124 } // namespace clang
125 
126 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ENVIRONMENT_H
EnvironmentEntry(const Stmt *s, const LocationContext *L)
Definition: Environment.cpp:70
Stmt - This represents one statement.
Definition: Stmt.h:66
void Profile(llvm::FoldingSetNodeID &ID) const
Profile - Used to profile the contents of this object for inclusion in a FoldingSet.
Definition: Environment.h:87
const Stmt * getStmt() const
Definition: Environment.h:41
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Environment.h:51
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
iterator end() const
Definition: Environment.h:73
iterator begin() const
Definition: Environment.h:72
BindingsTy::iterator iterator
Definition: Environment.h:70
static void Profile(llvm::FoldingSetNodeID &ID, const EnvironmentEntry &E)
Profile an EnvironmentEntry for inclusion in a FoldingSet.
Definition: Environment.h:45
static void Profile(llvm::FoldingSetNodeID &ID, const Environment *env)
Profile - Profile the contents of an Environment object for use in a FoldingSet.
Definition: Environment.h:81
An entry in the environment consists of a Stmt and an LocationContext.
Definition: Environment.h:36
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Definition: SVals.h:76
A class responsible for cleaning up unused symbols.
An immutable map from EnvironemntEntries to SVals.
Definition: Environment.h:57
Dataflow Directional Tag Classes.
EnvironmentManager(llvm::BumpPtrAllocator &Allocator)
Definition: Environment.h:107
bool operator==(const Environment &RHS) const
Definition: Environment.h:91
const LocationContext * getLocationContext() const
Definition: Environment.h:42