Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 1 | //===-- GRConstants.cpp - Simple, Path-Sens. Constant Prop. ------*- C++ -*-==// |
Ted Kremenek | 6492485 | 2008-01-31 02:35:41 +0000 | [diff] [blame] | 2 | // |
Ted Kremenek | 4af8431 | 2008-01-31 06:49:09 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Constant Propagation via Graph Reachability |
| 11 | // |
| 12 | // This files defines a simple analysis that performs path-sensitive |
| 13 | // constant propagation within a function. An example use of this analysis |
| 14 | // is to perform simple checks for NULL dereferences. |
| 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame^] | 18 | #include "RValues.h" |
| 19 | #include "ValueState.h" |
| 20 | |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 21 | #include "clang/Analysis/PathSensitive/GREngine.h" |
| 22 | #include "clang/AST/Expr.h" |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 23 | #include "clang/AST/ASTContext.h" |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 24 | #include "clang/Analysis/Analyses/LiveVariables.h" |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 25 | |
| 26 | #include "llvm/Support/Casting.h" |
| 27 | #include "llvm/Support/DataTypes.h" |
| 28 | #include "llvm/ADT/APSInt.h" |
| 29 | #include "llvm/ADT/FoldingSet.h" |
| 30 | #include "llvm/ADT/ImmutableMap.h" |
Ted Kremenek | 3c6c672 | 2008-01-16 17:56:25 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/SmallVector.h" |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/SmallPtrSet.h" |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Allocator.h" |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 34 | #include "llvm/Support/Compiler.h" |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 35 | #include "llvm/Support/Streams.h" |
| 36 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 37 | #include <functional> |
| 38 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 39 | #ifndef NDEBUG |
| 40 | #include "llvm/Support/GraphWriter.h" |
| 41 | #include <sstream> |
| 42 | #endif |
| 43 | |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 44 | using namespace clang; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 45 | using llvm::dyn_cast; |
| 46 | using llvm::cast; |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 47 | using llvm::APSInt; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 48 | |
| 49 | //===----------------------------------------------------------------------===// |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 50 | // The Checker. |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 51 | // |
| 52 | // FIXME: This checker logic should be eventually broken into two components. |
| 53 | // The first is the "meta"-level checking logic; the code that |
| 54 | // does the Stmt visitation, fetching values from the map, etc. |
| 55 | // The second part does the actual state manipulation. This way we |
| 56 | // get more of a separate of concerns of these two pieces, with the |
| 57 | // latter potentially being refactored back into the main checking |
| 58 | // logic. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 59 | //===----------------------------------------------------------------------===// |
| 60 | |
| 61 | namespace { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 62 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 63 | class VISIBILITY_HIDDEN GRConstants { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 64 | |
| 65 | public: |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame^] | 66 | typedef ValueState StateTy; |
Ted Kremenek | 7d7fe6d | 2008-01-29 22:56:11 +0000 | [diff] [blame] | 67 | typedef GRStmtNodeBuilder<GRConstants> StmtNodeBuilder; |
| 68 | typedef GRBranchNodeBuilder<GRConstants> BranchNodeBuilder; |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 69 | typedef ExplodedGraph<GRConstants> GraphTy; |
| 70 | typedef GraphTy::NodeTy NodeTy; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 71 | |
| 72 | class NodeSet { |
| 73 | typedef llvm::SmallVector<NodeTy*,3> ImplTy; |
| 74 | ImplTy Impl; |
| 75 | public: |
| 76 | |
| 77 | NodeSet() {} |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 78 | NodeSet(NodeTy* N) { assert (N && !N->isSink()); Impl.push_back(N); } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 79 | |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 80 | void Add(NodeTy* N) { if (N && !N->isSink()) Impl.push_back(N); } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 81 | |
| 82 | typedef ImplTy::iterator iterator; |
| 83 | typedef ImplTy::const_iterator const_iterator; |
| 84 | |
| 85 | unsigned size() const { return Impl.size(); } |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 86 | bool empty() const { return Impl.empty(); } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 87 | |
| 88 | iterator begin() { return Impl.begin(); } |
| 89 | iterator end() { return Impl.end(); } |
| 90 | |
| 91 | const_iterator begin() const { return Impl.begin(); } |
| 92 | const_iterator end() const { return Impl.end(); } |
| 93 | }; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 94 | |
| 95 | protected: |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 96 | /// G - the simulation graph. |
| 97 | GraphTy& G; |
| 98 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 99 | /// Liveness - live-variables information the ValueDecl* and block-level |
| 100 | /// Expr* in the CFG. Used to prune out dead state. |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 101 | LiveVariables Liveness; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 102 | |
Ted Kremenek | f4b7a69 | 2008-01-29 22:11:49 +0000 | [diff] [blame] | 103 | /// Builder - The current GRStmtNodeBuilder which is used when building the nodes |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 104 | /// for a given statement. |
Ted Kremenek | 7d7fe6d | 2008-01-29 22:56:11 +0000 | [diff] [blame] | 105 | StmtNodeBuilder* Builder; |
| 106 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 107 | /// StateMgr - Object that manages the data for all created states. |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame^] | 108 | StateTy::Factory StateMgr; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 109 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 110 | /// ValueMgr - Object that manages the data for all created RValues. |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 111 | ValueManager ValMgr; |
| 112 | |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 113 | /// SymMgr - Object that manages the symbol information. |
| 114 | SymbolManager SymMgr; |
| 115 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 116 | /// StmtEntryNode - The immediate predecessor node. |
| 117 | NodeTy* StmtEntryNode; |
| 118 | |
| 119 | /// CurrentStmt - The current block-level statement. |
| 120 | Stmt* CurrentStmt; |
| 121 | |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 122 | /// UninitBranches - Nodes in the ExplodedGraph that result from |
| 123 | /// taking a branch based on an uninitialized value. |
| 124 | typedef llvm::SmallPtrSet<NodeTy*,5> UninitBranchesTy; |
| 125 | UninitBranchesTy UninitBranches; |
| 126 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 127 | bool StateCleaned; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 128 | |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 129 | ASTContext& getContext() const { return G.getContext(); } |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 130 | |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 131 | public: |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 132 | GRConstants(GraphTy& g) : G(g), Liveness(G.getCFG(), G.getFunctionDecl()), |
| 133 | Builder(NULL), ValMgr(G.getContext()), StmtEntryNode(NULL), |
| 134 | CurrentStmt(NULL) { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 135 | |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 136 | // Compute liveness information. |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 137 | Liveness.runOnCFG(G.getCFG()); |
| 138 | Liveness.runOnAllBlocks(G.getCFG(), NULL, true); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 139 | } |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 140 | |
| 141 | /// getCFG - Returns the CFG associated with this analysis. |
| 142 | CFG& getCFG() { return G.getCFG(); } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 143 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 144 | /// getInitialState - Return the initial state used for the root vertex |
| 145 | /// in the ExplodedGraph. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 146 | StateTy getInitialState() { |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 147 | StateTy St = StateMgr.GetEmptyMap(); |
Ted Kremenek | ff6e3c5 | 2008-01-29 00:43:03 +0000 | [diff] [blame] | 148 | |
| 149 | // Iterate the parameters. |
| 150 | FunctionDecl& F = G.getFunctionDecl(); |
| 151 | |
| 152 | for (FunctionDecl::param_iterator I=F.param_begin(), E=F.param_end(); |
Ted Kremenek | 4150abf | 2008-01-31 00:09:56 +0000 | [diff] [blame] | 153 | I!=E; ++I) |
| 154 | St = SetValue(St, LValueDecl(*I), RValue::GetSymbolValue(SymMgr, *I)); |
Ted Kremenek | ff6e3c5 | 2008-01-29 00:43:03 +0000 | [diff] [blame] | 155 | |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 156 | return St; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 157 | } |
Ted Kremenek | 3b4f670 | 2008-01-30 23:24:39 +0000 | [diff] [blame] | 158 | |
| 159 | bool isUninitControlFlow(const NodeTy* N) const { |
| 160 | return N->isSink() && UninitBranches.count(const_cast<NodeTy*>(N)) != 0; |
| 161 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 162 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 163 | /// ProcessStmt - Called by GREngine. Used to generate new successor |
| 164 | /// nodes by processing the 'effects' of a block-level statement. |
Ted Kremenek | 7d7fe6d | 2008-01-29 22:56:11 +0000 | [diff] [blame] | 165 | void ProcessStmt(Stmt* S, StmtNodeBuilder& builder); |
| 166 | |
| 167 | /// ProcessBranch - Called by GREngine. Used to generate successor |
| 168 | /// nodes by processing the 'effects' of a branch condition. |
Ted Kremenek | 71c29bd | 2008-01-29 23:32:35 +0000 | [diff] [blame] | 169 | void ProcessBranch(Stmt* Condition, Stmt* Term, BranchNodeBuilder& builder); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 170 | |
| 171 | /// RemoveDeadBindings - Return a new state that is the same as 'M' except |
| 172 | /// that all subexpression mappings are removed and that any |
| 173 | /// block-level expressions that are not live at 'S' also have their |
| 174 | /// mappings removed. |
| 175 | StateTy RemoveDeadBindings(Stmt* S, StateTy M); |
| 176 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 177 | StateTy SetValue(StateTy St, Stmt* S, const RValue& V); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 178 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 179 | StateTy SetValue(StateTy St, const Stmt* S, const RValue& V) { |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 180 | return SetValue(St, const_cast<Stmt*>(S), V); |
| 181 | } |
| 182 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 183 | StateTy SetValue(StateTy St, const LValue& LV, const RValue& V); |
Ted Kremenek | 1ccd31c | 2008-01-16 19:42:59 +0000 | [diff] [blame] | 184 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 185 | RValue GetValue(const StateTy& St, Stmt* S); |
| 186 | inline RValue GetValue(const StateTy& St, const Stmt* S) { |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 187 | return GetValue(St, const_cast<Stmt*>(S)); |
| 188 | } |
| 189 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 190 | RValue GetValue(const StateTy& St, const LValue& LV); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 191 | LValue GetLValue(const StateTy& St, Stmt* S); |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 192 | |
| 193 | /// Assume - Create new state by assuming that a given expression |
| 194 | /// is true or false. |
| 195 | inline StateTy Assume(StateTy St, RValue Cond, bool Assumption, |
| 196 | bool& isFeasible) { |
| 197 | if (isa<LValue>(Cond)) |
| 198 | return Assume(St, cast<LValue>(Cond), Assumption, isFeasible); |
| 199 | else |
| 200 | return Assume(St, cast<NonLValue>(Cond), Assumption, isFeasible); |
| 201 | } |
| 202 | |
| 203 | StateTy Assume(StateTy St, LValue Cond, bool Assumption, bool& isFeasible); |
| 204 | StateTy Assume(StateTy St, NonLValue Cond, bool Assumption, bool& isFeasible); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 205 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 206 | void Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, StateTy St); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 207 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 208 | /// Visit - Transfer function logic for all statements. Dispatches to |
| 209 | /// other functions that handle specific kinds of statements. |
| 210 | void Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 211 | |
| 212 | /// VisitCast - Transfer function logic for all casts (implicit and explicit). |
| 213 | void VisitCast(Expr* CastE, Expr* E, NodeTy* Pred, NodeSet& Dst); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 214 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 215 | /// VisitUnaryOperator - Transfer function logic for unary operators. |
| 216 | void VisitUnaryOperator(UnaryOperator* B, NodeTy* Pred, NodeSet& Dst); |
| 217 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 218 | /// VisitBinaryOperator - Transfer function logic for binary operators. |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 219 | void VisitBinaryOperator(BinaryOperator* B, NodeTy* Pred, NodeSet& Dst); |
| 220 | |
| 221 | /// VisitDeclStmt - Transfer function logic for DeclStmts. |
| 222 | void VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 223 | }; |
| 224 | } // end anonymous namespace |
| 225 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 226 | |
Ted Kremenek | 71c29bd | 2008-01-29 23:32:35 +0000 | [diff] [blame] | 227 | void GRConstants::ProcessBranch(Stmt* Condition, Stmt* Term, |
| 228 | BranchNodeBuilder& builder) { |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 229 | |
| 230 | StateTy PrevState = builder.getState(); |
Ted Kremenek | 71c29bd | 2008-01-29 23:32:35 +0000 | [diff] [blame] | 231 | |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 232 | // Remove old bindings for subexpressions. |
| 233 | for (StateTy::iterator I=PrevState.begin(), E=PrevState.end(); I!=E; ++I) |
| 234 | if (I.getKey().isSubExpr()) |
| 235 | PrevState = StateMgr.Remove(PrevState, I.getKey()); |
Ted Kremenek | 71c29bd | 2008-01-29 23:32:35 +0000 | [diff] [blame] | 236 | |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 237 | RValue V = GetValue(PrevState, Condition); |
| 238 | |
| 239 | switch (V.getBaseKind()) { |
| 240 | default: |
| 241 | break; |
| 242 | |
| 243 | case RValue::InvalidKind: |
| 244 | builder.generateNode(PrevState, true); |
| 245 | builder.generateNode(PrevState, false); |
| 246 | return; |
| 247 | |
| 248 | case RValue::UninitializedKind: { |
| 249 | NodeTy* N = builder.generateNode(PrevState, true); |
| 250 | |
| 251 | if (N) { |
| 252 | N->markAsSink(); |
| 253 | UninitBranches.insert(N); |
| 254 | } |
| 255 | |
| 256 | builder.markInfeasible(false); |
| 257 | return; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | // Process the true branch. |
| 262 | bool isFeasible = true; |
| 263 | StateTy St = Assume(PrevState, V, true, isFeasible); |
| 264 | |
| 265 | if (isFeasible) builder.generateNode(St, true); |
| 266 | else { |
| 267 | builder.markInfeasible(true); |
| 268 | isFeasible = true; |
| 269 | } |
| 270 | |
| 271 | // Process the false branch. |
| 272 | St = Assume(PrevState, V, false, isFeasible); |
| 273 | |
| 274 | if (isFeasible) builder.generateNode(St, false); |
| 275 | else builder.markInfeasible(false); |
| 276 | |
Ted Kremenek | 71c29bd | 2008-01-29 23:32:35 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Ted Kremenek | 7d7fe6d | 2008-01-29 22:56:11 +0000 | [diff] [blame] | 279 | void GRConstants::ProcessStmt(Stmt* S, StmtNodeBuilder& builder) { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 280 | Builder = &builder; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 281 | |
| 282 | StmtEntryNode = builder.getLastNode(); |
| 283 | CurrentStmt = S; |
| 284 | NodeSet Dst; |
| 285 | StateCleaned = false; |
| 286 | |
| 287 | Visit(S, StmtEntryNode, Dst); |
| 288 | |
| 289 | // If no nodes were generated, generate a new node that has all the |
| 290 | // dead mappings removed. |
| 291 | if (Dst.size() == 1 && *Dst.begin() == StmtEntryNode) { |
| 292 | StateTy St = RemoveDeadBindings(S, StmtEntryNode->getState()); |
| 293 | builder.generateNode(S, St, StmtEntryNode); |
| 294 | } |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 295 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 296 | CurrentStmt = NULL; |
| 297 | StmtEntryNode = NULL; |
| 298 | Builder = NULL; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 301 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 302 | RValue GRConstants::GetValue(const StateTy& St, const LValue& LV) { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 303 | switch (LV.getSubKind()) { |
| 304 | case LValueDeclKind: { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 305 | StateTy::TreeTy* T = St.SlimFind(cast<LValueDecl>(LV).getDecl()); |
| 306 | return T ? T->getValue().second : InvalidValue(); |
| 307 | } |
| 308 | default: |
| 309 | assert (false && "Invalid LValue."); |
Ted Kremenek | ca3e857 | 2008-01-16 22:28:08 +0000 | [diff] [blame] | 310 | break; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | return InvalidValue(); |
| 314 | } |
| 315 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 316 | RValue GRConstants::GetValue(const StateTy& St, Stmt* S) { |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 317 | for (;;) { |
| 318 | switch (S->getStmtClass()) { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 319 | |
| 320 | // ParenExprs are no-ops. |
| 321 | |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 322 | case Stmt::ParenExprClass: |
| 323 | S = cast<ParenExpr>(S)->getSubExpr(); |
| 324 | continue; |
| 325 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 326 | // DeclRefExprs can either evaluate to an LValue or a Non-LValue |
| 327 | // (assuming an implicit "load") depending on the context. In this |
| 328 | // context we assume that we are retrieving the value contained |
| 329 | // within the referenced variables. |
| 330 | |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 331 | case Stmt::DeclRefExprClass: |
| 332 | return GetValue(St, LValueDecl(cast<DeclRefExpr>(S)->getDecl())); |
Ted Kremenek | ca3e857 | 2008-01-16 22:28:08 +0000 | [diff] [blame] | 333 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 334 | // Integer literals evaluate to an RValue. Simply retrieve the |
| 335 | // RValue for the literal. |
| 336 | |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 337 | case Stmt::IntegerLiteralClass: |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 338 | return NonLValue::GetValue(ValMgr, cast<IntegerLiteral>(S)); |
| 339 | |
| 340 | // Casts where the source and target type are the same |
| 341 | // are no-ops. We blast through these to get the descendant |
| 342 | // subexpression that has a value. |
| 343 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 344 | case Stmt::ImplicitCastExprClass: { |
| 345 | ImplicitCastExpr* C = cast<ImplicitCastExpr>(S); |
| 346 | if (C->getType() == C->getSubExpr()->getType()) { |
| 347 | S = C->getSubExpr(); |
| 348 | continue; |
| 349 | } |
| 350 | break; |
| 351 | } |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 352 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 353 | case Stmt::CastExprClass: { |
| 354 | CastExpr* C = cast<CastExpr>(S); |
| 355 | if (C->getType() == C->getSubExpr()->getType()) { |
| 356 | S = C->getSubExpr(); |
| 357 | continue; |
| 358 | } |
| 359 | break; |
| 360 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 361 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 362 | // Handle all other Stmt* using a lookup. |
| 363 | |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 364 | default: |
| 365 | break; |
| 366 | }; |
| 367 | |
| 368 | break; |
| 369 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 370 | |
Ted Kremenek | 5c1b996 | 2008-01-24 19:43:37 +0000 | [diff] [blame] | 371 | StateTy::TreeTy* T = St.SlimFind(S); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 372 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 373 | return T ? T->getValue().second : InvalidValue(); |
| 374 | } |
| 375 | |
| 376 | LValue GRConstants::GetLValue(const StateTy& St, Stmt* S) { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 377 | while (ParenExpr* P = dyn_cast<ParenExpr>(S)) |
| 378 | S = P->getSubExpr(); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 379 | |
| 380 | if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(S)) |
| 381 | return LValueDecl(DR->getDecl()); |
| 382 | |
| 383 | return cast<LValue>(GetValue(St, S)); |
| 384 | } |
| 385 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 386 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 387 | GRConstants::StateTy GRConstants::SetValue(StateTy St, Stmt* S, |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 388 | const RValue& V) { |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame] | 389 | assert (S); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 390 | |
| 391 | if (!StateCleaned) { |
| 392 | St = RemoveDeadBindings(CurrentStmt, St); |
| 393 | StateCleaned = true; |
| 394 | } |
| 395 | |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 396 | bool isBlkExpr = false; |
| 397 | |
| 398 | if (S == CurrentStmt) { |
| 399 | isBlkExpr = getCFG().isBlkExpr(S); |
| 400 | |
| 401 | if (!isBlkExpr) |
| 402 | return St; |
| 403 | } |
Ted Kremenek | daadf45 | 2008-01-24 19:28:01 +0000 | [diff] [blame] | 404 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 405 | return V.isValid() ? StateMgr.Add(St, ValueKey(S,isBlkExpr), V) |
| 406 | : St; |
| 407 | } |
| 408 | |
| 409 | GRConstants::StateTy GRConstants::SetValue(StateTy St, const LValue& LV, |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 410 | const RValue& V) { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 411 | if (!LV.isValid()) |
| 412 | return St; |
| 413 | |
| 414 | if (!StateCleaned) { |
| 415 | St = RemoveDeadBindings(CurrentStmt, St); |
| 416 | StateCleaned = true; |
Ted Kremenek | ca3e857 | 2008-01-16 22:28:08 +0000 | [diff] [blame] | 417 | } |
Ted Kremenek | 0525a4f | 2008-01-16 19:47:19 +0000 | [diff] [blame] | 418 | |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 419 | switch (LV.getSubKind()) { |
| 420 | case LValueDeclKind: |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 421 | return V.isValid() ? StateMgr.Add(St, cast<LValueDecl>(LV).getDecl(), V) |
| 422 | : StateMgr.Remove(St, cast<LValueDecl>(LV).getDecl()); |
| 423 | |
| 424 | default: |
| 425 | assert ("SetValue for given LValue type not yet implemented."); |
| 426 | return St; |
| 427 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 430 | GRConstants::StateTy GRConstants::RemoveDeadBindings(Stmt* Loc, StateTy M) { |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 431 | // Note: in the code below, we can assign a new map to M since the |
| 432 | // iterators are iterating over the tree of the *original* map. |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 433 | StateTy::iterator I = M.begin(), E = M.end(); |
| 434 | |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 435 | |
Ted Kremenek | 65cac13 | 2008-01-29 05:25:31 +0000 | [diff] [blame] | 436 | for (; I!=E && !I.getKey().isSymbol(); ++I) { |
| 437 | // Remove old bindings for subexpressions and "dead" |
| 438 | // block-level expressions. |
| 439 | if (I.getKey().isSubExpr() || |
| 440 | I.getKey().isBlkExpr() && !Liveness.isLive(Loc,cast<Stmt>(I.getKey()))){ |
| 441 | M = StateMgr.Remove(M, I.getKey()); |
| 442 | } |
| 443 | else if (I.getKey().isDecl()) { // Remove bindings for "dead" decls. |
| 444 | if (VarDecl* V = dyn_cast<VarDecl>(cast<ValueDecl>(I.getKey()))) |
| 445 | if (!Liveness.isLive(Loc, V)) |
| 446 | M = StateMgr.Remove(M, I.getKey()); |
| 447 | } |
| 448 | } |
Ted Kremenek | 565256e | 2008-01-24 22:44:24 +0000 | [diff] [blame] | 449 | |
Ted Kremenek | e00fe3f | 2008-01-17 00:52:48 +0000 | [diff] [blame] | 450 | return M; |
Ted Kremenek | e00fe3f | 2008-01-17 00:52:48 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 453 | void GRConstants::Nodify(NodeSet& Dst, Stmt* S, GRConstants::NodeTy* Pred, |
| 454 | GRConstants::StateTy St) { |
| 455 | |
| 456 | // If the state hasn't changed, don't generate a new node. |
| 457 | if (St == Pred->getState()) |
| 458 | return; |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 459 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 460 | Dst.Add(Builder->generateNode(S, St, Pred)); |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 461 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 462 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 463 | void GRConstants::VisitCast(Expr* CastE, Expr* E, GRConstants::NodeTy* Pred, |
| 464 | GRConstants::NodeSet& Dst) { |
| 465 | |
| 466 | QualType T = CastE->getType(); |
| 467 | |
| 468 | // Check for redundant casts. |
| 469 | if (E->getType() == T) { |
| 470 | Dst.Add(Pred); |
| 471 | return; |
| 472 | } |
| 473 | |
| 474 | NodeSet S1; |
| 475 | Visit(E, Pred, S1); |
| 476 | |
| 477 | for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) { |
| 478 | NodeTy* N = *I1; |
| 479 | StateTy St = N->getState(); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 480 | const RValue& V = GetValue(St, E); |
| 481 | Nodify(Dst, CastE, N, SetValue(St, CastE, V.Cast(ValMgr, CastE))); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 482 | } |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | void GRConstants::VisitDeclStmt(DeclStmt* DS, GRConstants::NodeTy* Pred, |
| 486 | GRConstants::NodeSet& Dst) { |
| 487 | |
| 488 | StateTy St = Pred->getState(); |
| 489 | |
| 490 | for (const ScopedDecl* D = DS->getDecl(); D; D = D->getNextDeclarator()) |
Ted Kremenek | 403c181 | 2008-01-28 22:51:57 +0000 | [diff] [blame] | 491 | if (const VarDecl* VD = dyn_cast<VarDecl>(D)) { |
| 492 | const Expr* E = VD->getInit(); |
| 493 | St = SetValue(St, LValueDecl(VD), |
| 494 | E ? GetValue(St, E) : UninitializedValue()); |
| 495 | } |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 496 | |
| 497 | Nodify(Dst, DS, Pred, St); |
| 498 | |
| 499 | if (Dst.empty()) |
| 500 | Dst.Add(Pred); |
| 501 | } |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 502 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 503 | void GRConstants::VisitUnaryOperator(UnaryOperator* U, |
| 504 | GRConstants::NodeTy* Pred, |
| 505 | GRConstants::NodeSet& Dst) { |
| 506 | NodeSet S1; |
| 507 | Visit(U->getSubExpr(), Pred, S1); |
| 508 | |
| 509 | for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) { |
| 510 | NodeTy* N1 = *I1; |
| 511 | StateTy St = N1->getState(); |
| 512 | |
| 513 | switch (U->getOpcode()) { |
| 514 | case UnaryOperator::PostInc: { |
| 515 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 516 | NonLValue R1 = cast<NonLValue>(GetValue(St, L1)); |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 517 | NonLValue R2 = NonLValue::GetValue(ValMgr, 1U, U->getType(), |
| 518 | U->getLocStart()); |
Ted Kremenek | e0cf9c8 | 2008-01-24 19:00:57 +0000 | [diff] [blame] | 519 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 520 | NonLValue Result = R1.Add(ValMgr, R2); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 521 | Nodify(Dst, U, N1, SetValue(SetValue(St, U, R1), L1, Result)); |
| 522 | break; |
| 523 | } |
| 524 | |
| 525 | case UnaryOperator::PostDec: { |
| 526 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 527 | NonLValue R1 = cast<NonLValue>(GetValue(St, L1)); |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 528 | NonLValue R2 = NonLValue::GetValue(ValMgr, 1U, U->getType(), |
| 529 | U->getLocStart()); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 530 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 531 | NonLValue Result = R1.Sub(ValMgr, R2); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 532 | Nodify(Dst, U, N1, SetValue(SetValue(St, U, R1), L1, Result)); |
| 533 | break; |
| 534 | } |
| 535 | |
| 536 | case UnaryOperator::PreInc: { |
| 537 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 538 | NonLValue R1 = cast<NonLValue>(GetValue(St, L1)); |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 539 | NonLValue R2 = NonLValue::GetValue(ValMgr, 1U, U->getType(), |
| 540 | U->getLocStart()); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 541 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 542 | NonLValue Result = R1.Add(ValMgr, R2); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 543 | Nodify(Dst, U, N1, SetValue(SetValue(St, U, Result), L1, Result)); |
| 544 | break; |
| 545 | } |
| 546 | |
| 547 | case UnaryOperator::PreDec: { |
| 548 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 549 | NonLValue R1 = cast<NonLValue>(GetValue(St, L1)); |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 550 | NonLValue R2 = NonLValue::GetValue(ValMgr, 1U, U->getType(), |
| 551 | U->getLocStart()); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 552 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 553 | NonLValue Result = R1.Sub(ValMgr, R2); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 554 | Nodify(Dst, U, N1, SetValue(SetValue(St, U, Result), L1, Result)); |
| 555 | break; |
| 556 | } |
| 557 | |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 558 | case UnaryOperator::Minus: { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 559 | const NonLValue& R1 = cast<NonLValue>(GetValue(St, U->getSubExpr())); |
| 560 | Nodify(Dst, U, N1, SetValue(St, U, R1.UnaryMinus(ValMgr, U))); |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 561 | break; |
| 562 | } |
| 563 | |
Ted Kremenek | 6492485 | 2008-01-31 02:35:41 +0000 | [diff] [blame] | 564 | case UnaryOperator::AddrOf: { |
| 565 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
| 566 | Nodify(Dst, U, N1, SetValue(St, U, L1)); |
| 567 | break; |
| 568 | } |
| 569 | |
| 570 | case UnaryOperator::Deref: { |
| 571 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
| 572 | Nodify(Dst, U, N1, SetValue(St, U, GetValue(St, L1))); |
| 573 | break; |
| 574 | } |
| 575 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 576 | default: ; |
| 577 | assert (false && "Not implemented."); |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 582 | void GRConstants::VisitBinaryOperator(BinaryOperator* B, |
| 583 | GRConstants::NodeTy* Pred, |
| 584 | GRConstants::NodeSet& Dst) { |
| 585 | NodeSet S1; |
| 586 | Visit(B->getLHS(), Pred, S1); |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 587 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 588 | for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) { |
| 589 | NodeTy* N1 = *I1; |
Ted Kremenek | e00fe3f | 2008-01-17 00:52:48 +0000 | [diff] [blame] | 590 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 591 | // When getting the value for the LHS, check if we are in an assignment. |
| 592 | // In such cases, we want to (initially) treat the LHS as an LValue, |
| 593 | // so we use GetLValue instead of GetValue so that DeclRefExpr's are |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 594 | // evaluated to LValueDecl's instead of to an NonLValue. |
| 595 | const RValue& V1 = |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 596 | B->isAssignmentOp() ? GetLValue(N1->getState(), B->getLHS()) |
| 597 | : GetValue(N1->getState(), B->getLHS()); |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 598 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 599 | NodeSet S2; |
| 600 | Visit(B->getRHS(), N1, S2); |
| 601 | |
| 602 | for (NodeSet::iterator I2=S2.begin(), E2=S2.end(); I2 != E2; ++I2) { |
| 603 | NodeTy* N2 = *I2; |
| 604 | StateTy St = N2->getState(); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 605 | const RValue& V2 = GetValue(St, B->getRHS()); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 606 | |
| 607 | switch (B->getOpcode()) { |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 608 | default: |
| 609 | Dst.Add(N2); |
| 610 | break; |
| 611 | |
| 612 | // Arithmetic opreators. |
| 613 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 614 | case BinaryOperator::Add: { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 615 | const NonLValue& R1 = cast<NonLValue>(V1); |
| 616 | const NonLValue& R2 = cast<NonLValue>(V2); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 617 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 618 | Nodify(Dst, B, N2, SetValue(St, B, R1.Add(ValMgr, R2))); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 619 | break; |
| 620 | } |
| 621 | |
| 622 | case BinaryOperator::Sub: { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 623 | const NonLValue& R1 = cast<NonLValue>(V1); |
| 624 | const NonLValue& R2 = cast<NonLValue>(V2); |
| 625 | Nodify(Dst, B, N2, SetValue(St, B, R1.Sub(ValMgr, R2))); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 626 | break; |
| 627 | } |
| 628 | |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 629 | case BinaryOperator::Mul: { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 630 | const NonLValue& R1 = cast<NonLValue>(V1); |
| 631 | const NonLValue& R2 = cast<NonLValue>(V2); |
| 632 | Nodify(Dst, B, N2, SetValue(St, B, R1.Mul(ValMgr, R2))); |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 633 | break; |
| 634 | } |
| 635 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 636 | case BinaryOperator::Div: { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 637 | const NonLValue& R1 = cast<NonLValue>(V1); |
| 638 | const NonLValue& R2 = cast<NonLValue>(V2); |
| 639 | Nodify(Dst, B, N2, SetValue(St, B, R1.Div(ValMgr, R2))); |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 640 | break; |
| 641 | } |
| 642 | |
Ted Kremenek | cce207d | 2008-01-28 22:26:15 +0000 | [diff] [blame] | 643 | case BinaryOperator::Rem: { |
| 644 | const NonLValue& R1 = cast<NonLValue>(V1); |
| 645 | const NonLValue& R2 = cast<NonLValue>(V2); |
| 646 | Nodify(Dst, B, N2, SetValue(St, B, R1.Rem(ValMgr, R2))); |
| 647 | break; |
| 648 | } |
| 649 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 650 | // Assignment operators. |
| 651 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 652 | case BinaryOperator::Assign: { |
| 653 | const LValue& L1 = cast<LValue>(V1); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 654 | const NonLValue& R2 = cast<NonLValue>(V2); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 655 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, R2), L1, R2)); |
| 656 | break; |
| 657 | } |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 658 | |
| 659 | case BinaryOperator::AddAssign: { |
| 660 | const LValue& L1 = cast<LValue>(V1); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 661 | NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1)); |
| 662 | NonLValue Result = R1.Add(ValMgr, cast<NonLValue>(V2)); |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 663 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 664 | break; |
| 665 | } |
| 666 | |
| 667 | case BinaryOperator::SubAssign: { |
| 668 | const LValue& L1 = cast<LValue>(V1); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 669 | NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1)); |
| 670 | NonLValue Result = R1.Sub(ValMgr, cast<NonLValue>(V2)); |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 671 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 672 | break; |
| 673 | } |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 674 | |
| 675 | case BinaryOperator::MulAssign: { |
| 676 | const LValue& L1 = cast<LValue>(V1); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 677 | NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1)); |
| 678 | NonLValue Result = R1.Mul(ValMgr, cast<NonLValue>(V2)); |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 679 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 680 | break; |
| 681 | } |
Ted Kremenek | 5c1e262 | 2008-01-25 23:45:34 +0000 | [diff] [blame] | 682 | |
| 683 | case BinaryOperator::DivAssign: { |
| 684 | const LValue& L1 = cast<LValue>(V1); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 685 | NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1)); |
| 686 | NonLValue Result = R1.Div(ValMgr, cast<NonLValue>(V2)); |
Ted Kremenek | 5c1e262 | 2008-01-25 23:45:34 +0000 | [diff] [blame] | 687 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 688 | break; |
| 689 | } |
Ted Kremenek | 10099a6 | 2008-01-28 22:28:54 +0000 | [diff] [blame] | 690 | |
| 691 | case BinaryOperator::RemAssign: { |
| 692 | const LValue& L1 = cast<LValue>(V1); |
| 693 | NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1)); |
| 694 | NonLValue Result = R1.Rem(ValMgr, cast<NonLValue>(V2)); |
| 695 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 696 | break; |
| 697 | } |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 698 | |
| 699 | // Equality operators. |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 700 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 701 | case BinaryOperator::EQ: |
| 702 | // FIXME: should we allow XX.EQ() to return a set of values, |
| 703 | // allowing state bifurcation? In such cases, they will also |
| 704 | // modify the state (meaning that a new state will be returned |
| 705 | // as well). |
| 706 | assert (B->getType() == getContext().IntTy); |
| 707 | |
| 708 | if (isa<LValue>(V1)) { |
| 709 | const LValue& L1 = cast<LValue>(V1); |
| 710 | const LValue& L2 = cast<LValue>(V2); |
| 711 | St = SetValue(St, B, L1.EQ(ValMgr, L2)); |
| 712 | } |
| 713 | else { |
| 714 | const NonLValue& R1 = cast<NonLValue>(V1); |
| 715 | const NonLValue& R2 = cast<NonLValue>(V2); |
| 716 | St = SetValue(St, B, R1.EQ(ValMgr, R2)); |
| 717 | } |
| 718 | |
| 719 | Nodify(Dst, B, N2, St); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 720 | break; |
| 721 | } |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 722 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 723 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 724 | } |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 725 | |
Ted Kremenek | 1ccd31c | 2008-01-16 19:42:59 +0000 | [diff] [blame] | 726 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 727 | void GRConstants::Visit(Stmt* S, GRConstants::NodeTy* Pred, |
| 728 | GRConstants::NodeSet& Dst) { |
| 729 | |
| 730 | // FIXME: add metadata to the CFG so that we can disable |
| 731 | // this check when we KNOW that there is no block-level subexpression. |
| 732 | // The motivation is that this check requires a hashtable lookup. |
| 733 | |
| 734 | if (S != CurrentStmt && getCFG().isBlkExpr(S)) { |
| 735 | Dst.Add(Pred); |
| 736 | return; |
| 737 | } |
| 738 | |
| 739 | switch (S->getStmtClass()) { |
| 740 | case Stmt::BinaryOperatorClass: |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 741 | case Stmt::CompoundAssignOperatorClass: |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 742 | VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst); |
| 743 | break; |
| 744 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 745 | case Stmt::UnaryOperatorClass: |
| 746 | VisitUnaryOperator(cast<UnaryOperator>(S), Pred, Dst); |
| 747 | break; |
| 748 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 749 | case Stmt::ParenExprClass: |
| 750 | Visit(cast<ParenExpr>(S)->getSubExpr(), Pred, Dst); |
| 751 | break; |
| 752 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 753 | case Stmt::ImplicitCastExprClass: { |
| 754 | ImplicitCastExpr* C = cast<ImplicitCastExpr>(S); |
| 755 | VisitCast(C, C->getSubExpr(), Pred, Dst); |
| 756 | break; |
| 757 | } |
| 758 | |
| 759 | case Stmt::CastExprClass: { |
| 760 | CastExpr* C = cast<CastExpr>(S); |
| 761 | VisitCast(C, C->getSubExpr(), Pred, Dst); |
| 762 | break; |
| 763 | } |
| 764 | |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 765 | case Stmt::DeclStmtClass: |
| 766 | VisitDeclStmt(cast<DeclStmt>(S), Pred, Dst); |
| 767 | break; |
| 768 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 769 | default: |
| 770 | Dst.Add(Pred); // No-op. Simply propagate the current state unchanged. |
| 771 | break; |
Ted Kremenek | 79649df | 2008-01-17 18:25:22 +0000 | [diff] [blame] | 772 | } |
Ted Kremenek | 1ccd31c | 2008-01-16 19:42:59 +0000 | [diff] [blame] | 773 | } |
| 774 | |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 775 | //===----------------------------------------------------------------------===// |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 776 | // "Assume" logic. |
| 777 | //===----------------------------------------------------------------------===// |
| 778 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame^] | 779 | GRConstants::StateTy GRConstants::Assume(StateTy St, LValue Cond, bool Assumption, |
| 780 | bool& isFeasible) { |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 781 | return St; |
| 782 | } |
| 783 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame^] | 784 | GRConstants::StateTy GRConstants::Assume(StateTy St, NonLValue Cond, bool Assumption, |
| 785 | bool& isFeasible) { |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 786 | |
| 787 | switch (Cond.getSubKind()) { |
| 788 | default: |
| 789 | assert (false && "'Assume' not implemented for this NonLValue."); |
| 790 | return St; |
| 791 | |
| 792 | case ConcreteIntKind: { |
| 793 | bool b = cast<ConcreteInt>(Cond).getValue() != 0; |
| 794 | isFeasible = b ? Assumption : !Assumption; |
| 795 | return St; |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | |
| 801 | //===----------------------------------------------------------------------===// |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 802 | // Driver. |
| 803 | //===----------------------------------------------------------------------===// |
| 804 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 805 | #ifndef NDEBUG |
Ted Kremenek | 3b4f670 | 2008-01-30 23:24:39 +0000 | [diff] [blame] | 806 | static GRConstants* GraphPrintCheckerState; |
| 807 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 808 | namespace llvm { |
| 809 | template<> |
| 810 | struct VISIBILITY_HIDDEN DOTGraphTraits<GRConstants::NodeTy*> : |
| 811 | public DefaultDOTGraphTraits { |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 812 | |
| 813 | static void PrintKindLabel(std::ostream& Out, ValueKey::Kind kind) { |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 814 | switch (kind) { |
Ted Kremenek | 565256e | 2008-01-24 22:44:24 +0000 | [diff] [blame] | 815 | case ValueKey::IsSubExpr: Out << "Sub-Expressions:\\l"; break; |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 816 | case ValueKey::IsDecl: Out << "Variables:\\l"; break; |
| 817 | case ValueKey::IsBlkExpr: Out << "Block-level Expressions:\\l"; break; |
| 818 | default: assert (false && "Unknown ValueKey type."); |
| 819 | } |
| 820 | } |
| 821 | |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 822 | static void PrintKind(std::ostream& Out, GRConstants::StateTy M, |
| 823 | ValueKey::Kind kind, bool isFirstGroup = false) { |
| 824 | bool isFirst = true; |
| 825 | |
| 826 | for (GRConstants::StateTy::iterator I=M.begin(), E=M.end();I!=E;++I) { |
| 827 | if (I.getKey().getKind() != kind) |
| 828 | continue; |
| 829 | |
| 830 | if (isFirst) { |
| 831 | if (!isFirstGroup) Out << "\\l\\l"; |
| 832 | PrintKindLabel(Out, kind); |
| 833 | isFirst = false; |
| 834 | } |
| 835 | else |
| 836 | Out << "\\l"; |
| 837 | |
| 838 | Out << ' '; |
| 839 | |
| 840 | if (ValueDecl* V = dyn_cast<ValueDecl>(I.getKey())) |
| 841 | Out << V->getName(); |
| 842 | else { |
| 843 | Stmt* E = cast<Stmt>(I.getKey()); |
| 844 | Out << " (" << (void*) E << ") "; |
| 845 | E->printPretty(Out); |
| 846 | } |
| 847 | |
| 848 | Out << " : "; |
| 849 | I.getData().print(Out); |
| 850 | } |
| 851 | } |
| 852 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 853 | static std::string getNodeLabel(const GRConstants::NodeTy* N, void*) { |
| 854 | std::ostringstream Out; |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 855 | |
| 856 | // Program Location. |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 857 | ProgramPoint Loc = N->getLocation(); |
| 858 | |
| 859 | switch (Loc.getKind()) { |
| 860 | case ProgramPoint::BlockEntranceKind: |
| 861 | Out << "Block Entrance: B" |
| 862 | << cast<BlockEntrance>(Loc).getBlock()->getBlockID(); |
| 863 | break; |
| 864 | |
| 865 | case ProgramPoint::BlockExitKind: |
| 866 | assert (false); |
| 867 | break; |
| 868 | |
| 869 | case ProgramPoint::PostStmtKind: { |
| 870 | const PostStmt& L = cast<PostStmt>(Loc); |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 871 | Out << L.getStmt()->getStmtClassName() << ':' |
| 872 | << (void*) L.getStmt() << ' '; |
| 873 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 874 | L.getStmt()->printPretty(Out); |
| 875 | break; |
| 876 | } |
| 877 | |
| 878 | default: { |
| 879 | const BlockEdge& E = cast<BlockEdge>(Loc); |
| 880 | Out << "Edge: (B" << E.getSrc()->getBlockID() << ", B" |
| 881 | << E.getDst()->getBlockID() << ')'; |
Ted Kremenek | b38911f | 2008-01-30 23:03:39 +0000 | [diff] [blame] | 882 | |
| 883 | if (Stmt* T = E.getSrc()->getTerminator()) { |
| 884 | Out << "\\|Terminator: "; |
| 885 | E.getSrc()->printTerminator(Out); |
| 886 | |
| 887 | if (isa<SwitchStmt>(T)) { |
| 888 | // FIXME |
| 889 | } |
| 890 | else { |
| 891 | Out << "\\lCondition: "; |
| 892 | if (*E.getSrc()->succ_begin() == E.getDst()) |
| 893 | Out << "true"; |
| 894 | else |
| 895 | Out << "false"; |
| 896 | } |
| 897 | |
| 898 | Out << "\\l"; |
| 899 | } |
Ted Kremenek | 3b4f670 | 2008-01-30 23:24:39 +0000 | [diff] [blame] | 900 | |
| 901 | if (GraphPrintCheckerState->isUninitControlFlow(N)) { |
| 902 | Out << "\\|Control-flow based on\\lUninitialized value.\\l"; |
| 903 | } |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 904 | } |
| 905 | } |
| 906 | |
Ted Kremenek | 6492485 | 2008-01-31 02:35:41 +0000 | [diff] [blame] | 907 | Out << "\\|StateID: " << (void*) N->getState().getRoot() << "\\|"; |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 908 | |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 909 | PrintKind(Out, N->getState(), ValueKey::IsDecl, true); |
| 910 | PrintKind(Out, N->getState(), ValueKey::IsBlkExpr); |
Ted Kremenek | 565256e | 2008-01-24 22:44:24 +0000 | [diff] [blame] | 911 | PrintKind(Out, N->getState(), ValueKey::IsSubExpr); |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 912 | |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 913 | Out << "\\l"; |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 914 | return Out.str(); |
| 915 | } |
| 916 | }; |
| 917 | } // end llvm namespace |
| 918 | #endif |
| 919 | |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 920 | namespace clang { |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 921 | void RunGRConstants(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx) { |
| 922 | GREngine<GRConstants> Engine(cfg, FD, Ctx); |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 923 | Engine.ExecuteWorkList(); |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 924 | #ifndef NDEBUG |
Ted Kremenek | 3b4f670 | 2008-01-30 23:24:39 +0000 | [diff] [blame] | 925 | GraphPrintCheckerState = &Engine.getCheckerState(); |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 926 | llvm::ViewGraph(*Engine.getGraph().roots_begin(),"GRConstants"); |
Ted Kremenek | 3b4f670 | 2008-01-30 23:24:39 +0000 | [diff] [blame] | 927 | GraphPrintCheckerState = NULL; |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 928 | #endif |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 929 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 930 | } // end clang namespace |